grafana / grizzly

A utility for managing Jsonnet dashboards against the Grafana API
https://grafana.github.io/grizzly/
Apache License 2.0
525 stars 68 forks source link

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

Closed BlaCkinkGJ closed 1 week ago

BlaCkinkGJ commented 3 months ago

Grizzly Version

v0.4.0

Expected Behavior

Actual Behavior

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:

malcolmholmes commented 3 months ago

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.

BlaCkinkGJ commented 3 months ago

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.

malcolmholmes commented 3 months ago

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

BlaCkinkGJ commented 3 months ago

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
minhthong582000 commented 3 months ago

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: https://github.com/grafana/grizzly/pull/466, and it seems to work.

malcolmholmes commented 3 months ago

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.

minhthong582000 commented 2 months ago

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