-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use grafana configuration in the Alertmanager #8066
Merged
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
520bc9a
Add promoted bool field to Grafana state and configuration
santihernandezc af5c9f9
fix tests
santihernandezc 8112ab8
add function to compute final configuration from Mimir and Grafana co…
santihernandezc 24bd0f3
parse grafana configuration into an AlertConfigDesc
santihernandezc 8ecff41
apply grafana configuration to the alertmanager ignoring grafana rece…
santihernandezc 38a3fb3
include grafana receivers
santihernandezc f60ee36
implement webhook sender, send notifications
santihernandezc 7079756
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 0359ebe
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 79fcbdd
add version and orgID to BuildReceiverIntegrations(), fix whSenderFn()
santihernandezc effcdc4
make tests compile
santihernandezc b3aa755
add logger implementation and logger factory
santihernandezc 8187b69
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 46a5f94
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 9aadec6
use NoopDecrypt from alerting package, delete getActiveReceiversMap
santihernandezc 6555447
make sender work with the go-kit logger, use the sender, use logger f…
santihernandezc 06e1253
go back to using pointers for integrations, update alerting package a…
santihernandezc 55c2817
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 2b83927
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 3697724
update AM fork
santihernandezc fd33a39
Merge branch 'main' of https://github.com/grafana/mimir into santiher…
santihernandezc 24501d1
pass 1 as orgID when creating integrations
santihernandezc 1492f98
comments, tests
santihernandezc 25202d3
address code review comments, refactor
santihernandezc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/alertmanager/distributor.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Cortex Authors. | ||
|
||
package alertmanager | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/grafana/mimir/pkg/alertmanager/alertspb" | ||
) | ||
|
||
// parseGrafanaConfig creates an AlertConfigDesc from a GrafanaAlertConfigDesc. | ||
func parseGrafanaConfig(cfg alertspb.GrafanaAlertConfigDesc) (alertspb.AlertConfigDesc, error) { | ||
var amCfg GrafanaAlertmanagerConfig | ||
if err := json.Unmarshal([]byte(cfg.RawConfig), &amCfg); err != nil { | ||
return alertspb.AlertConfigDesc{}, fmt.Errorf("failed to unmarshal Grafana Alertmanager configuration %w", err) | ||
} | ||
|
||
rawCfg, err := json.Marshal(amCfg.AlertmanagerConfig) | ||
if err != nil { | ||
return alertspb.AlertConfigDesc{}, fmt.Errorf("failed to marshal Grafana Alertmanager configuration %w", err) | ||
} | ||
|
||
return alertspb.ToProto(string(rawCfg), amCfg.Templates, cfg.User), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -324,7 +324,7 @@ func NewMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, store alerts | |||||
return createMultitenantAlertmanager(cfg, fallbackConfig, store, ringStore, limits, features, logger, registerer) | ||||||
} | ||||||
|
||||||
// ComputeFallbackConfig will load, vaildate and return the provided fallbackConfigFile | ||||||
// ComputeFallbackConfig will load, validate and return the provided fallbackConfigFile | ||||||
// or return an valid empty default configuration if none is provided. | ||||||
func ComputeFallbackConfig(fallbackConfigFile string) ([]byte, error) { | ||||||
if fallbackConfigFile != "" { | ||||||
|
@@ -638,11 +638,17 @@ func (am *MultitenantAlertmanager) isUserOwned(userID string) bool { | |||||
return alertmanagers.Includes(am.ringLifecycler.GetInstanceAddr()) | ||||||
} | ||||||
|
||||||
func (am *MultitenantAlertmanager) syncConfigs(cfgs map[string]alertspb.AlertConfigDescs) { | ||||||
level.Debug(am.logger).Log("msg", "adding configurations", "num_configs", len(cfgs)) | ||||||
for user, cfg := range cfgs { | ||||||
err := am.setConfig(cfg.Mimir) | ||||||
func (am *MultitenantAlertmanager) syncConfigs(cfgMap map[string]alertspb.AlertConfigDescs) { | ||||||
level.Debug(am.logger).Log("msg", "adding configurations", "num_configs", len(cfgMap)) | ||||||
for user, cfgs := range cfgMap { | ||||||
cfg, err := am.computeConfig(cfgs) | ||||||
if err != nil { | ||||||
am.multitenantMetrics.lastReloadSuccessful.WithLabelValues(user).Set(float64(0)) | ||||||
level.Warn(am.logger).Log("msg", "error computing config", "err", err) | ||||||
continue | ||||||
} | ||||||
|
||||||
if err := am.setConfig(cfg); err != nil { | ||||||
am.multitenantMetrics.lastReloadSuccessful.WithLabelValues(user).Set(float64(0)) | ||||||
level.Warn(am.logger).Log("msg", "error applying config", "err", err) | ||||||
continue | ||||||
|
@@ -656,7 +662,7 @@ func (am *MultitenantAlertmanager) syncConfigs(cfgs map[string]alertspb.AlertCon | |||||
|
||||||
am.alertmanagersMtx.Lock() | ||||||
for userID, userAM := range am.alertmanagers { | ||||||
if _, exists := cfgs[userID]; !exists { | ||||||
if _, exists := cfgMap[userID]; !exists { | ||||||
userAlertmanagersToStop[userID] = userAM | ||||||
delete(am.alertmanagers, userID) | ||||||
delete(am.cfgs, userID) | ||||||
|
@@ -675,6 +681,40 @@ func (am *MultitenantAlertmanager) syncConfigs(cfgs map[string]alertspb.AlertCon | |||||
} | ||||||
} | ||||||
|
||||||
// computeConfig takes an AlertConfigDescs struct containing Mimir and Grafana configurations. | ||||||
// It returns the final configuration the Alertmanager will use. | ||||||
func (am *MultitenantAlertmanager) computeConfig(cfgs alertspb.AlertConfigDescs) (alertspb.AlertConfigDesc, error) { | ||||||
var cfg alertspb.AlertConfigDesc | ||||||
switch { | ||||||
// Mimir configuration. | ||||||
case !cfgs.Grafana.Promoted: | ||||||
level.Debug(am.logger).Log("msg", "grafana configuration not promoted, using mimir config", "user", cfgs.Mimir.User) | ||||||
cfg = cfgs.Mimir | ||||||
case cfgs.Grafana.Default: | ||||||
level.Debug(am.logger).Log("msg", "grafana configuration is default, using mimir config", "user", cfgs.Mimir.User) | ||||||
cfg = cfgs.Mimir | ||||||
case cfgs.Grafana.RawConfig == "": | ||||||
level.Debug(am.logger).Log("msg", "grafana configuration is empty, using mimir config", "user", cfgs.Mimir.User) | ||||||
cfg = cfgs.Mimir | ||||||
|
||||||
// Grafana configuration. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
case cfgs.Mimir.RawConfig == am.fallbackConfig: | ||||||
level.Debug(am.logger).Log("msg", "mimir configuration is default, using grafana config", "user", cfgs.Mimir.User) | ||||||
return parseGrafanaConfig(cfgs.Grafana) | ||||||
case cfgs.Mimir.RawConfig == "": | ||||||
level.Debug(am.logger).Log("msg", "mimir configuration is empty, using grafana config", "user", cfgs.Grafana.User) | ||||||
return parseGrafanaConfig(cfgs.Grafana) | ||||||
|
||||||
// Both configurations. | ||||||
// TODO: merge configurations. | ||||||
default: | ||||||
level.Debug(am.logger).Log("msg", "merging configurations not implemented, using mimir config", "user", cfgs.Mimir.User) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be at least warning, if not error.
Suggested change
|
||||||
return cfgs.Mimir, nil | ||||||
} | ||||||
|
||||||
return cfg, nil | ||||||
} | ||||||
|
||||||
// setConfig applies the given configuration to the alertmanager for `userID`, | ||||||
// creating an alertmanager if it doesn't already exist. | ||||||
func (am *MultitenantAlertmanager) setConfig(cfg alertspb.AlertConfigDesc) error { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be nice pulled out into a function, e.g.
buildGrafanaReceiverIntegrations