What does HackerNews think of grafonnet-lib?

Jsonnet library for generating Grafana dashboard files.

Language: Jsonnet

I honestly... don't know. I have been using Jsonnet to programatically generate Grafana dashboards, because AFAIK the only official library to generate them is written in Jsonnet [1].

In my experience, it works, but it doesn't really give me any distinct advantage and instead it gives me some headaches. Maybe for things that look almost like JSON it'd be helpful, but the moment you start dealing with more complex generations you start finding lack of typing, lack of IDE support, lack of easy debugging, etc, fairly problematic. For example, something I really dislike is that due to how the expressions are evaluated, the only way to add debug/trace statements is to use them to "transform" a value you're going to use, if you don't use the result of the trace in the final output, the trace does not appear.

Also, I really dislike the error messages. Again, due to the lazy evaluation design, when you mess up something the error message might appear deep in some unrelated call stack and with a jarring lack of context. Debugging it is a real pain.

1: https://github.com/grafana/grafonnet-lib

You could use Tanka and Jsonnet to improve this for Grafana dashboards: https://github.com/grafana/grafonnet-lib.

Would that work for you?

Yeah. It’s a pretty sweet tool. What’s also pretty awesome about it is that its interpreters (one C++ and one Go implementation) can also easily be embedded into custom applications.

For an Open Source project of mine (https://github.com/buildbarn, a remote build cluster implementation for the Bazel build system), we are using go-jsonnet as the config file parser library. This means that people can use JSON, but if they need something that’s more flexible, they can add Jsonnet statements immediately. It’s also possible to have that as a preprocessing stage (init scripts), but in a containerized world it’s easier to have it embedded.

One of the nice things about doing that is that I also don’t need to write code to load TLS certificate data from disk. People can either embed their secrets directly into the config file, or they can use Jsonnet’s ‘importstr’ keyword to load separate PEM files from disk.

Somewhat related to that: Jsonnet also allows people to write libraries for constructing more complex JSON files. For example, the Grafana folks have released a library (https://github.com/grafana/grafonnet-lib) that allows you to easily build Grafana dashboards from code.