grafana / grafonnet

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

Custom variable not working properly #195

Closed DanickBG closed 5 months ago

DanickBG commented 5 months ago

I am testing the simples version of the custom variable:

local g = import 'g.libsonnet';
local var = g.dashboard.variable;
local customVar =
  var.custom.new(
    'myOptions',['a', 'b', 'c', 'd'],
  );
g.dashboard.new('my dashboard')
+ g.dashboard.withVariables([customVar])

However, it results in this error: RUNTIME ERROR: field does not exist: get vendor/github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/clean/../custom/./dashboard/variable.libsonnet:335:17-24 thunk <multi> vendor/github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/clean/../custom/./dashboard/../util/./dashboard.libsonnet:27:14-19 object <anonymous> vendor/github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/clean/../custom/./dashboard/variable.libsonnet:(333:15)-(336:16) object <anonymous> test.jsonnet:11:30-39 thunk <array_element> vendor/github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/clean/dashboard.libsonnet:(210:48)-(212:60) object <anonymous> vendor/github.com/grafana/grafonnet/gen/grafonnet-v10.4.0/clean/dashboard.libsonnet:(210:24)-(212:65) object <anonymous> During manifestation

   However, I can create query variables and manage all the panels which are available, so this error makes no sense to me. Please, help!

image

Duologic commented 5 months ago

Please update your jsonnet.

DanickBG commented 5 months ago

@Duologic I followed your advice and updated everything and installed again jsonnet via pip as well. Here is what I did:

dani@dani-Latitude-E5430:~$ go version

go version go1.22.2 linux/amd64

dani@dani-Latitude-E5430:~$ go install github.com/google/go-jsonnet/cmd/jsonnet@latest

go: downloading github.com/google/go-jsonnet v0.20.0

...

dani@dani-Latitude-E5430:~$ go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest

go: downloading github.com/jsonnet-bundler/jsonnet-bundler v0.5.1

...

dani@dani-Latitude-E5430:~$ mkdir mynewjsonnetproject

dani@dani-Latitude-E5430:~$ cd mynewjsonnetproject/

dani@dani-Latitude-E5430:~/mynewjsonnetproject$ jb init

dani@dani-Latitude-E5430:~/mynewjsonnetproject$ jb install github.com/grafana/grafonnet/gen/grafonnet-latest@main

GET https://github.com/grafana/grafonnet/archive/1c56af39815c4903e47c27194444456f005f65df.tar.gz 200

GET https://github.com/grafana/grafonnet/archive/1c56af39815c4903e47c27194444456f005f65df.tar.gz 200

GET https://github.com/jsonnet-libs/docsonnet/archive/6ac6c69685b8c29c54515448eaca583da2d88150.tar.gz 200

GET https://github.com/jsonnet-libs/xtd/archive/63d430b69a95741061c2f7fc9d84b1a778511d9c.tar.gz 200

dani@dani-Latitude-E5430:~/mynewjsonnetproject$ go install github.com/google/go-jsonnet/cmd/jsonnet@latest

dani@dani-Latitude-E5430:~/mynewjsonnetproject$ pip install jsonnet

...

Successfully installed jsonnet-0.20.0

I created a new folder and tried again there - I got the same error

image image

Please, help me resolve this problem :)

DanickBG commented 5 months ago

@Duologic I updated and still get the same results, any other advice? I would really appreciate if you can help me so we can others who face the same problem in the future.

malcolmholmes commented 5 months ago

Not sure what is in the python bindings for Jsonnet. Does it also pull in Jsonnet itself? You will want to run go-jsonnet not default C jsonnet.

DanickBG commented 5 months ago

Unfortunately I can't understand what you mean @malcolmholmes :( I have no go-jsonnet command which I can run, only jsonnet, despite having downloaded everything as stated in Readme. If you tell me explicitly how to run go-jsonnet then I can try to do it :)

malcolmholmes commented 5 months ago

Run this command:

jsonnet -v

It should mention "Go implementation", as mine does:

Jsonnet commandline interpreter (Go implementation) v0.19.1
DanickBG commented 5 months ago

image @malcolmholmes Mine says: Jsonnet commandline interpreter (Go implementation) v0.20.0

DanickBG commented 5 months ago

Oh my God... Finally resolved the error: The extention of the file used to be .jsonnet instead of .libsonnet Once I renamed the extention everything is working. Thank you guys @Duologic @malcolmholmes for the help you provided me!