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

(feat): display unifiedAlerting state #65

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

Conversation

ivangonzalezacuna
Copy link

@ivangonzalezacuna ivangonzalezacuna commented Apr 26, 2023

This is an extension for this PR: #54
And fixes #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.

ivgo added 3 commits April 26, 2023 14:41
Small modification in the API to allow a single or multiple selectors.
The final alert state is aggregated at the end in case there are more than 1 alerts for a label
If not set, the .flat() methods where not found properly.
And now the pluginApiRef and the types are also exported, in case they are needed by someone else
@banup-kubeforce
Copy link

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

@ivangonzalezacuna
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

RobertSimonDB commented Mar 13, 2024

This was already partially implemented in #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
Copy link

TEST-ACCOUNT-APURV commented Jun 10, 2024

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

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.

Alert state is not surfaced when using Grafana Unified Alerting
4 participants