backstage-plugin-grafana icon indicating copy to clipboard operation
backstage-plugin-grafana copied to clipboard

(feat): display unifiedAlerting state

Open ivangonzalezacuna opened this issue 1 year ago • 6 comments

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.

ivangonzalezacuna avatar Apr 26 '23 12:04 ivangonzalezacuna

Where do I set the " set the showState in the EntityGrafanaAlertsCard component to true" . is it is app config.yaml

banup-kubeforce avatar Dec 05 '23 16:12 banup-kubeforce

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

ivangonzalezacuna avatar Dec 06 '23 08:12 ivangonzalezacuna

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 image

banup-kubeforce avatar Dec 06 '23 18:12 banup-kubeforce

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.

ivangonzalezacuna avatar Dec 07 '23 15:12 ivangonzalezacuna

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,
        );

RobertSimonDB avatar Mar 13 '24 21:03 RobertSimonDB

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

TEST-ACCOUNT-APURV avatar Jun 10 '24 15:06 TEST-ACCOUNT-APURV