weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.88k stars 315 forks source link

Grafana Cloud unable to upload a grafanalib generated dashboard #549

Open agilbert314 opened 1 year ago

agilbert314 commented 1 year ago

What you expected to happen?

I would expect Grafana Cloud to be able to upload a grafanalib generated dashboard from the button Upload a Dashboard.

What happened?

Grafana Cloud reports the error: Old dashboard JSON format and direct the user to Grafana documentation Read about Importing & Sharing with Grafana 2.x or 3.0.

How to reproduce it?

With this Ptyhon script:

from grafanalib.core import (
  Dashboard, Stat, Target, GridPos, Template, Templating, Time, Repeat
)

application = 'backend'
statusTemplate = Template(default='',
                          dataSource='Prometheus',
                          name='statusCode',
                          multi=True,
                          query=(
                            f'http_server_requests_seconds_count{{'
                            f'application="{application.upper()}",'
                            f'uri=~"/public/api/v1/.*"'
                            f'}}'
                          ),
                          regex='.*status="(\\d+)".*',
                          )

templateList = [statusTemplate]

dashboard = Dashboard(
  title='Some Dashboard',
  timezone='',
  time=Time('now-24h', 'now'),
  panels=[
    Stat(
      title='STATUS $statusCode',
      dataSource=None,
      reduceCalc='lastNotNull',
      repeat=Repeat(direction='h', variable='statusCode'),
      targets=[
        Target(
          expr=(f'round(sum(increase(http_server_requests_seconds_count{{'
                f'status="$statusCode", '
                f'application="{application.upper()}", '
                f'uri=~"/public/api/v1/.*"'
                f'}}[$__range:])))')
        ),
      ],
      gridPos=GridPos(h=6, w=12, x=0, y=0),
    )
  ],
  templating=Templating(list=templateList)
).auto_panel_ids()

With this command line:

generate-dashboard -o grafana_dashboard.json backend.dashboard.py
The JSON dashboard was generated with these versions: - version
python 3.10
attrs 22.1.0
grafanalib 0.7.0
pip 22.3.1
setuptools 49.2.1
agilbert314 commented 1 year ago

Note that the genarated JSON is supported by grafana version 7.3.4.