grafana/grizzly

[Bug]: UID Configuration in Jsonnet File Not Working and Causes Error

BlaCkinkGJ opened this issue · 7 comments

Grizzly Version

v0.4.0

Expected Behavior

  • If the UID is not specified, the system should automatically add the UID to the Jsonnet file, similar to how it was handled in version 0.3.1.
  • If the UID is specified, it should be explicitly set.

Actual Behavior

  • Regardless of whether the UID was specified in the Jsonnet file, it did not function correctly and displayed the following error message:
  • Even when the UID was specified, the error message indicated that the UID wasn't configured.

I generated the following error message using the source code provided in the "Steps to Reproduce" section.

image

Steps to Reproduce

  1. Prepare the Jsonnet File:

    • Create a Jsonnet file to generate a dashboard using Grizzly. We will use grafonnet-7.0 to configure the Jsonnet file. Name the test file test.jsonnet.
    local grafana = import 'grafonnet-7.0/grafana.libsonnet';
    local dashboard = grafana.dashboard;
    
    {
      grafanaDashboardFolder:: 'Test Dashboard Folder',
      grafanaDashboards:: {
        ['test_dashboard']: dashboard.new(title="hello", uid="hello"),
      },
    }
  2. Set Configuration Values:

    • Configure the GRAFANA_URL and GRAFANA_TOKEN values.
  3. Apply the Jsonnet File:

    • Run the command grr apply test.jsonnet.

Note: In my local environment, I was able to resolve this issue by either:

This really isn't straightforward, and there isn't a right answer. Say someone wants a dashboard delivering to Grafana without a UID - if Grizzly added the metadata/name as UID, it would then be shipping a different dashboard to the one the user expected, resulting in unexpected behaviour.

Using validation to confirm that metadata/name and UID both match, and erroring out otherwise is the simplest and cleanest of a bad set of options.

Thank you for looking into this issue.

I would like to point out that setting the UID value does not seem to work as expected, regardless of the validation routine.

For instance, even when I configure metadata/name to "hello" and set the UID to "hello," I still receive the same error message. It appears that the UID is always empty, causing the validation routine to consistently fail.

Dashboard.hello failed: uid "" and name "hello", don't match.

In summary, the UID value setting does not appear to be functioning correctly.

can you give me a simple snippet that demonstrates this case?

You can reproduce this issue by using the following dashboard.jsonnet file.

local grafana = import 'grafonnet/grafana.libsonnet';

{
  grafanaDashboards:: {
    empty_dashboard: grafana.dashboard.new(title="hello", uid="world"),
  },
}

Its result:
image

The commands are as follows:

mkdir simple-dashboard
cd simple-dashboard
jb init
jb install https://github.com/grafana/grafonnet-lib/grafonnet
vi dashboard.jsonnet # put the content above
grr apply dashbaord.jsonnet

Just in case, I updated my grizzly version from v0.4.0 to v0.4.3, but I still got the same error message.

2024/07/17 10:27:36 grr version v0.4.3

I am also facing the same issue.

As pointed out above, the grizzly.jsonnet seems to set the dashboard uid to an empty string (https://github.com/grafana/grizzly/blob/main/pkg/grizzly/grizzly.jsonnet#L41-L42) when parsing the jsonnet input file, making the validation logic redundant. The resource.Name() function then serves as a valid uid.

If the intention is to always keep the uid as an empty string, I've created an example PR to remove the validation: #466, and it seems to work.

Ahh, thanks, I haven't been looking at grizzly.jsonnet. I'm AFK until next week. I can take a look then, unless someone beats me to it.

Hi @malcolmholmes, just a friendly reminder, please check this when you get a chance. Thank you! 😄