grafana / grafonnet

Jsonnet library for generating Grafana dashboards.
https://grafana.github.io/grafonnet/
Apache License 2.0
352 stars 19 forks source link

fieldOverride byQuery renders not valid json #162

Closed v-zhuravlev closed 8 months ago

v-zhuravlev commented 8 months ago

https://grafana.github.io/grafonnet/API/panel/timeSeries/standardOptions/override.html#obj-byquery Snippet:

        + g.panel.timeSeries.standardOptions.withOverridesMixin(
          [
            // byQuery doesn't work
            g.panel.timeSeries.fieldOverride.byQuery.new('A')
            + g.panel.timeSeries.fieldOverride.byQuery.withPropertiesFromOptions(
              g.panel.timeSeries.standardOptions.withUnit(signal.units.simple),
            ),
          ],
        ),

Gives json:

    "overrides": [
      {
        "matcher": {
          "id": "byQuery",
          "options": "A"
        },
        "properties": [
          {
            "id": "unit",
            "value": "seconds"
          }
        ]
      }
    ]

That returns an error in Grafana:

An unexpected error happened
Error: "byQuery" not found in: byName,byRegexp,byType,byFrameRefID,byNames,byValue

ir@http://grafana.k3d.localhost:9999/public/build/DashboardPageProxy.c428143cac890308b384.js:83:5333
div
div
Or@http://grafana.k3d.localhost:9999/public/build/DashboardPageProxy.c428143cac890308b384.js:204:144
div
i@http://grafana.k3d.localhost:9999/public/build/8474.aca7493112eb29aea9e3.js:1:2302
div
i@http://grafana.k3d.localhost:9999/public/build/8474.aca7493112eb29aea9e3.js:1:4290
_@http://grafana.k3d.localhost:9999/public/build/8474.aca7493112eb29aea9e3.js:1:9613
div
div
div
W@http://grafana.k3d.localhost:9999/public/build/8291.6eb51b53410a9cd7be10.js:404:21371
Xs@http://grafana.k3d.localhost:9999/public/build/DashboardPageProxy.c428143cac890308b384.js:332:531
Connect(Xs)@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:183:66208
WithTheme(Connect(Xs))
vn@http://grafana.k3d.localhost:9999/public/build/DashboardPageProxy.c428143cac890308b384.js:407:479
DashboardPage
Connect(DashboardPage)@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:183:66208
To@http://grafana.k3d.localhost:9999/public/build/DashboardPageProxy.c428143cac890308b384.js:407:6445
Suspense
o@http://grafana.k3d.localhost:9999/public/build/8291.6eb51b53410a9cd7be10.js:192:118871
bo@http://grafana.k3d.localhost:9999/public/build/8291.6eb51b53410a9cd7be10.js:349:10002
be@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:228:23527
uo@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:209:4760
Jn@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:209:10242
el@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:228:11797
be@http://grafana.k3d.localhost:9999/public/build/1663.190becda783f60342f79.js:228:25722
div
div

This workaround works:

        + g.panel.timeSeries.standardOptions.withOverridesMixin(
          [
            // byQuery doesn't work
            {
              matcher: {
                id: 'byFrameRefID',
                options: 'A',
              },
            }
            + g.panel.timeSeries.fieldOverride.byQuery.withPropertiesFromOptions(
              g.panel.timeSeries.standardOptions.withUnit(signal.units.simple),
            ),
          ],
        ),

grafana version 10.3.1

Duologic commented 8 months ago

Thanks for reporting, looks like a bug.

I can vaguely recall I based this on the Scenes, now that I look back at it I see that assumptions were made:

https://github.com/grafana/scenes/blob/01d599ad96d703bf43e3e8657879a1a9dc81f2b9/packages/scenes/src/core/PanelBuilders/FieldConfigOverridesBuilder.ts#L48C1-L57C4