K-Phoen / backstage-plugin-grafana

Grafana plugin for Backstage
Apache License 2.0
53 stars 28 forks source link

(feat): display unifiedAlerting state #65

Open ivangonzalezacuna opened 1 year ago

ivangonzalezacuna commented 1 year ago

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.

banup-kubeforce commented 7 months ago

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

ivangonzalezacuna commented 7 months ago

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
banup-kubeforce commented 7 months ago

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
ivangonzalezacuna commented 7 months ago

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.

RobertSimonDB commented 4 months ago

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,
        );
TEST-ACCOUNT-APURV commented 1 month ago

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