K-Phoen / grabana

User-friendly Go library for building Grafana dashboards
MIT License
680 stars 69 forks source link

panel ids in different dashboards have common numbering #235

Open rifler opened 11 months ago

rifler commented 11 months ago

Hello!

Current behaviour

builder1 := dashboard.New(
    "dashboard 1",
    dashboard.Row(
        "Prometheus",
        row.WithGraph(
            // some data
        ),
    ),
)
builder2 := dashboard.New(
    "dashboard 2",
    dashboard.Row(
        "Prometheus",
        row.WithGraph(
            // some data
        ),
    ),
)

fmt.Printf("%d\n", builder1.Internal().Rows[0].Panels[0].ID)
// 1
fmt.Printf("%d\n", builder2.Internal().Rows[0].Panels[0].ID)
// 2

Expected behaviour Numbering is independent:

builder1 := dashboard.New(
    "dashboard 1",
    dashboard.Row(
        "Prometheus",
        row.WithGraph(
            // some data
        ),
    ),
)
builder2 := dashboard.New(
    "dashboard 2",
    dashboard.Row(
        "Prometheus",
        row.WithGraph(
            // some data
        ),
    ),
)

fmt.Printf("%d\n", builder1.Internal().Rows[0].Panels[0].ID)
// 1
fmt.Printf("%d\n", builder2.Internal().Rows[0].Panels[0].ID)
// 1

As far as I understand problem is here - https://github.com/K-Phoen/sdk/blob/master/row.go#L33 Possible solution is to extend MarshalJSON/MarshalIndentJSON and mutate ids there, starting them from 1

K-Phoen commented 8 months ago

Does that cause any issue when publishing the dashboards to Grafana?