Skip to content
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

#3513: Show muted alerts in the Alert Groups API #3797

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

grobinson-grafana
Copy link
Contributor

This commit updates the Alert Groups API (/api/v2/alerts/groups) to show if an alert is suppressed from one or more active or mute time intervals. It does not update the Alerts API (/api/v2/alerts) because that API does not take aggregation or routing into consideration.

Based on #3793.

@grobinson-grafana grobinson-grafana marked this pull request as draft April 3, 2024 12:38
@grobinson-grafana grobinson-grafana changed the title Show muted alerts in the Alert Groups API #3513: Show muted alerts in the Alert Groups API Apr 3, 2024
@grobinson-grafana
Copy link
Contributor Author

I added a checkbox for filtering Muted alerts and a label to show if the alert is muted, like we have for silenced and inhibited alerts.

Screenshot 2024-04-05 at 5 20 14 PM

@grobinson-grafana grobinson-grafana marked this pull request as ready for review April 8, 2024 09:54
fetchAlerts apiUrl filter =
let
url =
String.join "/" [ apiUrl, "alerts" ++ generateAPIQueryString filter ]
in
Utils.Api.send (Utils.Api.get url (Json.Decode.list Data.GettableAlert.decoder))
Utils.Api.send (Utils.Api.get url (Json.Decode.list Data.ExtendedGettableAlert.decoder))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most important change to the Elm code. I'm decoding the response for /api/v2/alerts as ExtendedGettableAlert when in the OpenAPI schema it is GettableAlert. The difference between the two is that ExtendedGettableAlert has a mutedBy column in status.

This commit updates /api/v2/alerts/groups to show if an alert is
suppressed from one or more active or mute time intervals. It does
not update the /api/v2/alerts API because that API does not
take aggregation or routing into consideration.

It also updates the UI to support filtering Muted alerts via the
Muted checkbox.

Signed-off-by: George Robinson <george.robinson@grafana.com>
@@ -86,16 +88,18 @@ type (
func NewAPI(
alerts provider.Alerts,
gf groupsFn,
sf getAlertStatusFn,
asf getAlertStatusFn,
Copy link
Contributor Author

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! 😄

@@ -407,17 +411,22 @@ 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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skips muted groups if muted is false.

extendedGettableAlert:
allOf:
- type: object
properties:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to duplicate all of these properties due to a bug in swagger generation for Elm that occurs when using inheritance.

@@ -505,6 +542,29 @@ definitions:
- state
- silencedBy
- inhibitedBy
extendedAlertStatus:
type: object
properties:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also had to duplicate this otherwise the state enum does not get inherited and the Elm code fails.

@@ -206,6 +206,8 @@ type AlertGroup struct {
Alerts types.AlertSlice
Labels model.LabelSet
Receiver string
GroupKey string
RouteID string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to add RouteID here because we added it to the marker. Without it, we cannot see if a group is muted or not.

Signed-off-by: George Robinson <george.robinson@grafana.com>
@grobinson-grafana grobinson-grafana marked this pull request as ready for review May 13, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant