Closed jacksongoode closed 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(...)
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.
Yep, more tedious for sure, but there is good reason.
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 theg.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.