backstage-plugin-grafana
backstage-plugin-grafana copied to clipboard
(feat): display unifiedAlerting state
This is an extension for this PR: https://github.com/K-Phoen/backstage-plugin-grafana/pull/54 And fixes https://github.com/K-Phoen/backstage-plugin-grafana/issues/53
In this PR I'm extending a bit the API call, so that it can fetch not only one labelSelector, but multiple. So now it accepts a string or an array as input. Then, I created an aggregation function to analyze what is the state for each alert and return a final value.
As an example, if there are 3 alerts; 2 of them are ok
but one is firing
, then the final state will be firing
.
The API extension is meant for some use cases where the API is called from another place in the UI (we are currently doing so, and doing a call per selector is really time consuming, especially when the request is always the same), therefore I also exported a couple types to allow other people to use this API internally.
To try it out, just enable the unifiedAlerting
in your backstage instance, set the annotation and set the showState
in the EntityGrafanaAlertsCard
component to true.
Where do I set the " set the showState in the EntityGrafanaAlertsCard component to true" . is it is app config.yaml
Where do I set the " set the showState in the EntityGrafanaAlertsCard component to true" . is it is app config.yaml
Exactly, you should have a block like the following:
grafana:
domain: ${GRAFANA_BASE_URL}
unifiedAlerting: true
Where do I set the " set the showState in the EntityGrafanaAlertsCard component to true" . is it is app config.yaml
Exactly, you should have a block like the following:
grafana: domain: ${GRAFANA_BASE_URL} unifiedAlerting: true
It is still not showing the "state" column
If you're using this plugin's last version you won't have that supported unfortunately. In our case, we ended up creating a fork and merging this change and a few others, and in our case, we can see the state properly.
This was already partially implemented in https://github.com/K-Phoen/backstage-plugin-grafana/pull/54 Maybe this will make @ThomasAwesome happy :-D
Problem there was how to exact match rule and alert, which can be solved by using includeInternalLabels=trueas part of fetching alerts.
'/api/prometheus/grafana/api/v1/alerts?includeInternalLabels=true'`
than you can exact match rules and alerts
const matchingAlertInstances = alertInstances.filter(
alertInstance =>
alertInstance.labels.__alert_rule_uid__ === rule.grafana_alert.uid,
);
can you please provide screenshots about how you are using the alert-label selector in catalog-info and how alert label looks like in your grafana portal @banup-kubeforce @RobertSimonDB @ivangonzalezacuna