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

AlertList compatibility with grafana 9.x #585

Open
tporeba opened this issue May 11, 2023 · 1 comment
Open

AlertList compatibility with grafana 9.x #585

tporeba opened this issue May 11, 2023 · 1 comment

Comments

@tporeba
Copy link

tporeba commented May 11, 2023

I am trying to use grafanalib with grafana 9.4 and I noticed that grafanalib.core.AlertList component produces definition of alertlist panel in old json format. The panel gets created, but some properties end up with wrong values and are ignored, for example : stateFilter or onlyAlertsOnDashboard.

If I understand this note correctly, grafanalib assumes that grafana will migrate from those old json formats to newest formats when dashboard is being imported, but this does not happen for me. I'm not sure if this is some configuration issue or if the new grafana no longer does the migration.

What you expected to happen?

grafanalib.core.AlertList.to_json_data should produce a json compatible with recent grafana versions.

What happened?

For

AlertList(title="Panel Title",
             onlyAlertsOnDashboard=True,
             stateFilter=[grafanalib.core.ALERTLIST_STATE_PENDING],
             gridPos=GridPos(h=8, w=24, x=0, y=0),
             )

Grafanalib generates following AlertList a json with AlertList panel, it generates a json like this one:

{
      "dashboardTags": [],
      "description": "",
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "limit": 10,
      "links": [],
      "nameFilter": "",
      "onlyAlertsOnDashboard": true,
      "options": {
        "alertName": ""
      },
      "show": "current",
      "sortOrder": 1,
      "span": 6,
      "stateFilter": [
        "pending"
      ],
      "title": "Panel Title",
      "type": "alertlist"
    }

but after importing this in grafana, panel has default settings in 'Alerts from this dashboard' and 'Alert state filter'.
image
image

If following json was generated, the import would work ok:

    {
      "gridPos": {
        "h": 8,
        "w": 24
        "x": 0,
        "y": 0
      },
      "id": 2,
      "options": {
        "alertInstanceLabelFilter": "",
        "alertName": "",
        "dashboardAlerts": true,
        "groupBy": [],
        "groupMode": "default",
        "maxItems": 20,
        "sortOrder": 1,
        "stateFilter": {
          "error": false,
          "firing": false,
          "noData": false,
          "normal": false,
          "pending": true
        },
        "viewMode": "list"
      },
      "title": "Panel Title",
      "type": "alertlist"
    }

image
image

How to reproduce it?

Generate a dashboard with AlertList panel from grafanalib and install it in grafana

AlertList(title="Panel Title",
             onlyAlertsOnDashboard=True,
             stateFilter=[grafanalib.core.ALERTLIST_STATE_PENDING],
             gridPos=GridPos(h=8, w=24, x=0, y=0),
             )

or use one of the following example dashboard jsons for manual test:

steps:

  1. In grafana 9.4 import them manually: Dashboards -> Import -> upload json -> Import
  2. Go to imported dashboard and click on panel title -> edit -> scroll down to 'Alerts from this dashboard' and 'Alert state filter' options
    • 'Alerts from this dashboard' is set to False, but should be True
    • 'Alert state filter' is set to defaults: pending, alerting/firing, error, but should be only pending
@tporeba
Copy link
Author

tporeba commented May 11, 2023

It is quite easy to reproduce using grafana docker image + those two json files provided above in the description:

docker run --rm -p 3000:3000 --name grafana grafana/grafana-oss:<version>
grafana image version old Format new format
6.0.0
7.0.0
8.0.0
9.0.0
9.4.0

@tporeba tporeba changed the title AlertList compatibility with grafana 9.4 AlertList compatibility with grafana 9.x May 11, 2023
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

No branches or pull requests

1 participant