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

Support exclude_alerts parameter in Prometheus list rules endpoint #9300

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

Conversation

alexander-akhmetov
Copy link

@alexander-akhmetov alexander-akhmetov commented Sep 13, 2024

What this PR does

Adds exclude_alerts GET parameter to the Prometheus rules API endpoint, same as in Prometheus (documentation).

It also passes the parameter further to other replicas in the gRPC call.

Example

Without exclude_alerts

curl -s 'http://127.0.0.1:8001/prometheus/api/v1/rules?rule_group=group_2&rule_name=alert_0' | jq
{
  "status": "success",
  "data": {
    "groups": [
      {
        "name": "group_2",
        "file": "mimirtool",
        "rules": [
          {
            "state": "firing",
            "name": "alert_0",
            "query": "vector(1) > 0",
            "duration": 60,
            "keepFiringFor": 0,
            "labels": {
              "severity": "no"
            },
            "annotations": {
              "summary": "Always firing"
            },
            "alerts": [
              {
                "labels": {
                  "alertname": "alert_0",
                  "severity": "no"
                },
                "annotations": {
                  "summary": "Always firing"
                },
                "state": "firing",
                "activeAt": "2024-09-17T12:14:31.71939972Z",
                "value": "1e+00"
              }
            ],
            "health": "ok",
            "lastError": "",
            "type": "alerting",
            "lastEvaluation": "2024-09-17T12:17:31.722263334Z",
            "evaluationTime": 0.005084959
          }
        ],
        "interval": 30,
        "lastEvaluation": "2024-09-17T12:17:31.722165334Z",
        "evaluationTime": 0.017278292,
        "sourceTenants": null
      }
    ]
  },
  "errorType": "",
  "error": ""
}

exclude_alerts=true

curl -s 'http://127.0.0.1:8001/prometheus/api/v1/rules?rule_group=group_2&rule_name=alert_0&exclude_alerts=true' | jq
{
"status": "success",
"data": {
  "groups": [
    {
      "name": "group_2",
      "file": "mimirtool",
      "rules": [
        {
          "state": "firing",
          "name": "alert_0",
          "query": "vector(1) > 0",
          "duration": 60,
          "keepFiringFor": 0,
          "labels": {
            "severity": "no"
          },
          "annotations": {
            "summary": "Always firing"
          },
          "alerts": null,
          "health": "ok",
          "lastError": "",
          "type": "alerting",
          "lastEvaluation": "2024-09-17T12:17:31.722263334Z",
          "evaluationTime": 0.005084959
        }
      ],
      "interval": 30,
      "lastEvaluation": "2024-09-17T12:17:31.722165334Z",
      "evaluationTime": 0.017278292,
      "sourceTenants": null
    }
  ]
},
"errorType": "",
"error": ""
}

Which issue(s) this PR fixes or relates to

Fixes https://github.com/grafana/alerting-squad/issues/912
Part of https://github.com/grafana/alerting-squad/issues/871

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@CLAassistant
Copy link

CLAassistant commented Sep 13, 2024

CLA assistant check
All committers have signed the CLA.

@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/prometheus-api-exclude-alerts branch 4 times, most recently from f3d47ca to 9dbcdf4 Compare September 15, 2024 09:03
@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/prometheus-api-exclude-alerts branch from c2ec600 to a1b5059 Compare September 17, 2024 07:50
@alexander-akhmetov alexander-akhmetov marked this pull request as ready for review September 17, 2024 12:24
Copy link
Contributor

@fayzal-g fayzal-g left a comment

Choose a reason for hiding this comment

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

Few nits, looks good otherwise!

pkg/ruler/api.go Outdated Show resolved Hide resolved
pkg/ruler/api_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tacole02 tacole02 left a comment

Choose a reason for hiding this comment

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

LGTM 😄

docs/sources/mimir/references/http-api/index.md Outdated Show resolved Hide resolved
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.

4 participants