-
Notifications
You must be signed in to change notification settings - Fork 2.2k
#3513: Show muted alerts in the Alert Groups API #3797
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -60,6 +60,7 @@ type API struct { | |||||||||
alerts provider.Alerts | ||||||||||
alertGroups groupsFn | ||||||||||
getAlertStatus getAlertStatusFn | ||||||||||
groupMutedFunc groupMutedFunc | ||||||||||
uptime time.Time | ||||||||||
|
||||||||||
// mtx protects alertmanagerConfig, setAlertStatus and route. | ||||||||||
|
@@ -78,6 +79,7 @@ type API struct { | |||||||||
|
||||||||||
type ( | ||||||||||
groupsFn func(func(*dispatch.Route) bool, func(*types.Alert, time.Time) bool) (dispatch.AlertGroups, map[prometheus_model.Fingerprint][]string) | ||||||||||
groupMutedFunc func(routeID, groupKey string) ([]string, bool) | ||||||||||
getAlertStatusFn func(prometheus_model.Fingerprint) types.AlertStatus | ||||||||||
setAlertStatusFn func(prometheus_model.LabelSet) | ||||||||||
) | ||||||||||
|
@@ -86,16 +88,18 @@ type ( | |||||||||
func NewAPI( | ||||||||||
alerts provider.Alerts, | ||||||||||
gf groupsFn, | ||||||||||
sf getAlertStatusFn, | ||||||||||
asf getAlertStatusFn, | ||||||||||
gmf groupMutedFunc, | ||||||||||
Comment on lines
+91
to
+92
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. How about this for consistent naming:
Suggested change
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 don't mind the types as these two are consistent: getAlertStatusFn func(prometheus_model.Fingerprint) types.AlertStatus
setAlertStatusFn func(prometheus_model.LabelSet) It was more the variable names |
||||||||||
silences *silence.Silences, | ||||||||||
peer cluster.ClusterPeer, | ||||||||||
l log.Logger, | ||||||||||
r prometheus.Registerer, | ||||||||||
) (*API, error) { | ||||||||||
api := API{ | ||||||||||
alerts: alerts, | ||||||||||
getAlertStatus: sf, | ||||||||||
getAlertStatus: asf, | ||||||||||
alertGroups: gf, | ||||||||||
groupMutedFunc: gmf, | ||||||||||
peer: peer, | ||||||||||
silences: silences, | ||||||||||
logger: l, | ||||||||||
|
@@ -290,7 +294,7 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re | |||||||||
continue | ||||||||||
} | ||||||||||
|
||||||||||
alert := AlertToOpenAPIAlert(a, api.getAlertStatus(a.Fingerprint()), receivers) | ||||||||||
alert := AlertToOpenAPIAlert(a, api.getAlertStatus(a.Fingerprint()), receivers, nil) | ||||||||||
|
||||||||||
res = append(res, alert) | ||||||||||
} | ||||||||||
|
@@ -407,6 +411,11 @@ func (api *API) getAlertGroupsHandler(params alertgroup_ops.GetAlertGroupsParams | |||||||||
res := make(open_api_models.AlertGroups, 0, len(alertGroups)) | ||||||||||
|
||||||||||
for _, alertGroup := range alertGroups { | ||||||||||
mutedBy, isMuted := api.groupMutedFunc(alertGroup.RouteID, alertGroup.GroupKey) | ||||||||||
if !*params.Muted && isMuted { | ||||||||||
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. This skips muted groups if |
||||||||||
continue | ||||||||||
} | ||||||||||
|
||||||||||
ag := &open_api_models.AlertGroup{ | ||||||||||
Receiver: &open_api_models.Receiver{Name: &alertGroup.Receiver}, | ||||||||||
Labels: ModelLabelSetToAPILabelSet(alertGroup.Labels), | ||||||||||
|
@@ -417,7 +426,7 @@ func (api *API) getAlertGroupsHandler(params alertgroup_ops.GetAlertGroupsParams | |||||||||
fp := alert.Fingerprint() | ||||||||||
receivers := allReceivers[fp] | ||||||||||
status := api.getAlertStatus(fp) | ||||||||||
apiAlert := AlertToOpenAPIAlert(alert, status, receivers) | ||||||||||
apiAlert := AlertToOpenAPIAlert(alert, status, receivers, mutedBy) | ||||||||||
ag.Alerts = append(ag.Alerts, apiAlert) | ||||||||||
} | ||||||||||
res = append(res, ag) | ||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ func PostableSilenceToProto(s *open_api_models.PostableSilence) (*silencepb.Sile | |
} | ||
|
||
// AlertToOpenAPIAlert converts internal alerts, alert types, and receivers to *open_api_models.GettableAlert. | ||
func AlertToOpenAPIAlert(alert *types.Alert, status types.AlertStatus, receivers []string) *open_api_models.GettableAlert { | ||
func AlertToOpenAPIAlert(alert *types.Alert, status types.AlertStatus, receivers, mutedBy []string) *open_api_models.GettableAlert { | ||
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.
|
||
startsAt := strfmt.DateTime(alert.StartsAt) | ||
updatedAt := strfmt.DateTime(alert.UpdatedAt) | ||
endsAt := strfmt.DateTime(alert.EndsAt) | ||
|
@@ -128,7 +128,13 @@ func AlertToOpenAPIAlert(alert *types.Alert, status types.AlertStatus, receivers | |
} | ||
|
||
fp := alert.Fingerprint().String() | ||
|
||
state := string(status.State) | ||
if len(mutedBy) > 0 { | ||
// If the alert is muted, change the state to suppressed. | ||
state = open_api_models.AlertStatusStateSuppressed | ||
} | ||
|
||
aa := &open_api_models.GettableAlert{ | ||
Alert: open_api_models.Alert{ | ||
GeneratorURL: strfmt.URI(alert.GeneratorURL), | ||
|
@@ -144,6 +150,7 @@ func AlertToOpenAPIAlert(alert *types.Alert, status types.AlertStatus, receivers | |
State: &state, | ||
SilencedBy: status.SilencedBy, | ||
InhibitedBy: status.InhibitedBy, | ||
MutedBy: mutedBy, | ||
}, | ||
} | ||
|
||
|
@@ -155,6 +162,10 @@ func AlertToOpenAPIAlert(alert *types.Alert, status types.AlertStatus, receivers | |
aa.Status.InhibitedBy = []string{} | ||
} | ||
|
||
if aa.Status.MutedBy == nil { | ||
aa.Status.MutedBy = []string{} | ||
} | ||
|
||
return aa | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Not the best variable name, option to suggestions! 😄