Skip to content

Commit 2d6bfa7

Browse files
committed
Migrate from deprecated grafonnet-lib to grafonnet
The library used to generate Grafana dashboards, `grafonnet-lib`, has been deprecate for quite some time. This commit re-implements `simpledash` with the replacement library `grafonnet`. The tool "Jsonnet Bundler" is now used to manage `grafonnet` versions and dependencies.
1 parent 2f0e80b commit 2d6bfa7

30 files changed

Lines changed: 1127 additions & 4925 deletions

MODULE.bazel

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,6 @@ bazel_dep(name = "buildifier_prebuilt", version = "8.5.1.2", dev_dependency = Tr
3232

3333
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3434

35-
http_archive(
36-
name = "grafonnet_lib",
37-
build_file_content = """
38-
load("@rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_library")
39-
40-
jsonnet_library(
41-
name = "grafonnet",
42-
srcs = glob(["grafonnet/*.libsonnet"]),
43-
imports = ["."],
44-
visibility = ["//visibility:public"],
45-
)
46-
""",
47-
sha256 = "ef8d75ab8633024f0a214f61e28ca8a5fe384467ce1151587eb812ddf7181e76",
48-
strip_prefix = "grafonnet-lib-04f3e87e2d524c7aba936aae525f388290d94291",
49-
urls = ["https://github.com/grafana/grafonnet-lib/archive/04f3e87e2d524c7aba936aae525f388290d94291.tar.gz"],
50-
)
51-
5235
http_archive(
5336
name = "abseil-hello",
5437
patch_cmds = [
@@ -141,7 +124,7 @@ go_sdk.download(version = "1.26.4")
141124

142125
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
143126
go_deps.from_file(go_mod = "//:go.mod")
144-
use_repo(go_deps, "org_golang_x_lint")
127+
use_repo(go_deps, "com_github_jsonnet_bundler_jsonnet_bundler", "org_golang_x_lint")
145128

146129
go_deps_dev = use_extension("@gazelle//:extensions.bzl", "go_deps", dev_dependency = True)
147130

MODULE.bazel.lock

Lines changed: 0 additions & 3959 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dummy_for_dependencies.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
package dummyforgomod
1010

1111
import (
12-
_ "golang.org/x/lint" // GitHub Workflow
12+
_ "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb" // Jsonnet Bundler
13+
_ "golang.org/x/lint" // GitHub Workflow
1314
)

go.mod

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ replace github.com/hanwen/go-fuse/v2 => github.com/hanwen/go-fuse/v2 v2.5.1
1717

1818
require (
1919
github.com/bazelbuild/rules_go v0.61.1
20+
github.com/jsonnet-bundler/jsonnet-bundler v0.6.0
2021
golang.org/x/lint v0.0.0-20241112194109-818c5a804067
2122
)
2223

2324
require github.com/google/go-cmp v0.7.0 // indirect
2425

25-
require golang.org/x/tools v0.34.0 // indirect
26+
require (
27+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
28+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
29+
github.com/elliotchance/orderedmap/v2 v2.2.0 // indirect
30+
github.com/fatih/color v1.13.0 // indirect
31+
github.com/mattn/go-colorable v0.1.12 // indirect
32+
github.com/mattn/go-isatty v0.0.14 // indirect
33+
github.com/pkg/errors v0.9.1 // indirect
34+
golang.org/x/sys v0.33.0 // indirect
35+
golang.org/x/tools v0.34.0 // indirect
36+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
37+
)

go.sum

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
2+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
4+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
15
github.com/bazelbuild/rules_go v0.61.1 h1:F7jqdw0Zp/RtWFDbLFuVa2DaPjUQkqZOLCns8vCxSWg=
26
github.com/bazelbuild/rules_go v0.61.1/go.mod h1:6YghDRf6l3FSiAwncK+Ww9jE1naoQzNq28gaKJeB67I=
7+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/elliotchance/orderedmap/v2 v2.2.0 h1:7/2iwO98kYT4XkOjA9mBEIwvi4KpGB4cyHeOFOnj4Vk=
11+
github.com/elliotchance/orderedmap/v2 v2.2.0/go.mod h1:85lZyVbpGaGvHvnKa7Qhx7zncAdBIBq6u56Hb1PRU5Q=
12+
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
13+
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
314
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
415
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
16+
github.com/jsonnet-bundler/jsonnet-bundler v0.6.0 h1:DBnynmjyWBVQ9gUBmTh49x3Dw5/u4CvGO3k2k1CsYNo=
17+
github.com/jsonnet-bundler/jsonnet-bundler v0.6.0/go.mod h1:5esRxD59TyScj6qxT3o7GH0sryBKvVmx2zaEYDXtQkg=
18+
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
19+
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
20+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
21+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
22+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
23+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
24+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
25+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
26+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
27+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
28+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
29+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
30+
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
31+
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
532
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
633
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
734
golang.org/x/lint v0.0.0-20241112194109-818c5a804067 h1:adDmSQyFTCiv19j015EGKJBoaa7ElV0Q1Wovb/4G7NA=
@@ -16,8 +43,20 @@ golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
1643
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
1744
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1845
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
46+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
47+
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
48+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
49+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
50+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
51+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
1952
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2053
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
2154
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
2255
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
2356
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
57+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
58+
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
59+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
61+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
62+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

monitoring/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ order to render them efficiently, they rely on Prometheus recording
55
rules that are also provided.
66

77
All of the source files in this directory are written in Jsonnet.
8-
Grafana dashboards make use of [Grafonnet](https://github.com/grafana/grafonnet-lib).
8+
Grafana dashboards make use of [Grafonnet](https://github.com/grafana/grafonnet).
99
Bazel build rules are provided that convert them to JSON. Building all
1010
of the Grafana dashboards is as simple as running:
1111

1212
```
13-
bazel test //monitoring/...
13+
bazel build //monitoring/grafana:dashboards
1414
```
1515

1616
An eventual goal would be to integrate these dashboards into the
1717
Kubernetes manifests that are also stored in this repository. Maybe it
1818
makes sense to inject the recording rules into Prometheus using the
1919
[Prometheus operator](https://github.com/coreos/prometheus-operator)?
2020
Contributions in this area are more than welcome!
21+
22+
## Dashboard default values
23+
24+
The file `grafana/config.libsonnet` includes some configurable default
25+
values for all dashboards. To override a default value for a single
26+
dashboards, for example `timerange`:
27+
28+
```jsonnet
29+
'example-dashboard.jsonnet': simpledash.dashboard(
30+
...
31+
config=$._config {
32+
timerange: 'now-6h',
33+
},
34+
),
35+
```

monitoring/grafana/BUILD.bazel

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,24 @@
1-
load("@rules_jsonnet//jsonnet:jsonnet.bzl", "jsonnet_library", "jsonnet_to_json")
1+
load("simpledash.bzl", "simpledash", "jb_library")
22

3-
jsonnet_library(
4-
name = "grpc",
5-
srcs = ["grpc.libsonnet"],
3+
jb_library(
4+
name = "vendor",
5+
jsonnetfile = "jsonnetfile.json",
6+
jsonnetfile_lock = "jsonnetfile.lock.json",
67
)
78

8-
jsonnet_library(
9-
name = "simpledash",
10-
srcs = ["simpledash.libsonnet"],
11-
deps = ["@grafonnet_lib//:grafonnet"],
12-
)
13-
14-
[
15-
jsonnet_to_json(
16-
name = dashboard,
17-
src = dashboard + ".jsonnet",
18-
outs = [dashboard + ".json"],
19-
deps = [":simpledash"],
20-
)
21-
for dashboard in [
22-
"bb-scheduler",
23-
"blobaccess",
24-
"buildexecutor",
25-
"centralized-storage",
26-
"eviction-sets",
27-
"fuse",
28-
]
9+
DASHBOARDS = [
10+
"dashboards/bb-scheduler.jsonnet",
11+
"dashboards/blobaccess.jsonnet",
12+
"dashboards/buildexecutor.jsonnet",
13+
"dashboards/centralized-storage.jsonnet",
14+
"dashboards/eviction-sets.jsonnet",
15+
"dashboards/fuse.jsonnet",
16+
"dashboards/grpc-clients.jsonnet",
17+
"dashboards/grpc-servers.jsonnet",
2918
]
3019

31-
[
32-
jsonnet_to_json(
33-
name = dashboard,
34-
src = dashboard + ".jsonnet",
35-
outs = [dashboard + ".json"],
36-
deps = [
37-
":grpc",
38-
":simpledash",
39-
],
40-
)
41-
for dashboard in [
42-
"grpc-clients",
43-
"grpc-servers",
44-
]
45-
]
20+
simpledash(
21+
name = "dashboards",
22+
srcs = DASHBOARDS,
23+
imports = [":vendor"]
24+
)

monitoring/grafana/bb-scheduler.jsonnet

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)