grafana / grafonnet

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

Verbose dashboard construction syntax #58

Closed jacksongoode closed 1 year ago

jacksongoode commented 1 year ago

https://github.com/grafana/grafonnet/blob/84df6caded9f78b0773b67aa6d5202d7a0d24ba3/examples/terraform/jsonnet/main.libsonnet#L3-L6

I've been following progress here and a major point of difference between this and the old grafonnet-lib is the syntax to build out dashboards. In the above example, would it be possible to drop the g.dashboard when calling .withDescription() .withPanels() etc? This way they would seem more like chained methods of a class instance rather than independent functions being called.

malcolmholmes commented 1 year ago

You are talking about the builder pattern that the previous grafonnet used.

Unfortunately, the builder pattern has performance issues in Jsonnet, and we were advised against it my one of the Jsonnet authors (it requires continuously adding self which requires excessive re-evaluation).

You can make your code more brief with locals, e.g.

local d = g.dashboard,
d.withDescription(...)
jacksongoode commented 1 year ago

Ah darn. Well good to hear that there's some performance benefit against doing it. It will make migrating dashboards over a little bit more tedious.

malcolmholmes commented 1 year ago

Yep, more tedious for sure, but there is good reason.