Skip to content

Commit 085ec03

Browse files
committed
Revert grafana SDK switch; update release metadata
1 parent bfb32d4 commit 085ec03

File tree

9 files changed

+75
-91
lines changed

9 files changed

+75
-91
lines changed

.bcr/presubmit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ bcr_test_module_linux:
1212
- "//..."
1313
test_targets:
1414
- "//..."
15+
# Linux runners have Docker available, so run docker/oci tests here.
1516

1617
bcr_test_module_macos:
1718
module_path: ""

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
run: |
1919
TAG=${GITHUB_REF#refs/tags/v}
2020
git archive --format=tar.gz --prefix=rules_grafana-${TAG}/ HEAD > rules_grafana-${TAG}.tar.gz
21-
shasum -a 256 rules_grafana-${TAG}.tar.gz > rules_grafana-${TAG}.tar.gz.sha256
21+
sha256sum rules_grafana-${TAG}.tar.gz > rules_grafana-${TAG}.tar.gz.sha256
2222
2323
- uses: softprops/action-gh-release@v2
2424
with:

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module(
22
name = "rules_grafana",
33
version = "2.0.0",
44
bazel_compatibility = [">=8.0.0"],
5-
compatibility_level = 1,
5+
compatibility_level = 2,
66
)
77

88
bazel_dep(name = "aspect_bazel_lib", version = "2.21.2")

README.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bazel_dep(name = "rules_grafana", version = "2.0.0")
4747
git_override(
4848
module_name = "rules_grafana",
4949
remote = "https://github.com/etsy/rules_grafana.git",
50-
branch = "grafana-foundation-sdk",
50+
branch = "main",
5151
)
5252

5353
# For plugins and container setup
@@ -92,36 +92,23 @@ to ensure it has a [consistent URL in Grafana](http://docs.grafana.org/administr
9292

9393
### Python dashboards
9494

95-
Dashboards can also be generated with Python using the
96-
[`grafana-foundation-sdk`](https://github.com/grafana/grafana-foundation-sdk) library.
97-
The SDK provides type-safe builders for creating Grafana dashboards programmatically.
95+
Dashboards can also be generated with Python,
96+
using the [`grafanalib`](https://github.com/weaveworks/grafanalib) library.
97+
`grafanalib` is automatically imported,
98+
and you can also add other `deps` to help build your dashboard.
9899

99100
Each Python dashboard file should print the complete JSON of a Grafana dashboard.
100-
Here's a template to get started:
101+
An easy way to do that is to follow a template like this:
101102

102103
```python
103-
import json
104-
from grafana_foundation_sdk.builders import dashboard as dashboard_builder
105-
from grafana_foundation_sdk.builders import text, timeseries
106-
from grafana_foundation_sdk.cog.encoder import JSONEncoder
107-
from grafana_foundation_sdk.models.dashboard import GridPos
108-
109-
dashboard = (
110-
dashboard_builder.Dashboard("My Dashboard")
111-
.with_panel(
112-
text.Panel()
113-
.title("Welcome")
114-
.grid_pos(GridPos(h=4, w=24, x=0, y=0))
115-
)
116-
.with_panel(
117-
timeseries.Panel()
118-
.title("Metrics")
119-
.grid_pos(GridPos(h=8, w=12, x=0, y=4))
120-
)
121-
.build()
104+
from grafanalib.core import *
105+
from grafanalib._gen import print_dashboard
106+
107+
dashboard = Dashboard(
108+
# Fill in your dashboard!
122109
)
123110

124-
print(json.dumps(dashboard, cls=JSONEncoder, indent=2))
111+
print_dashboard(dashboard.auto_panel_ids()) # `auto_panel_ids()` call is required!
125112
```
126113

127114
Use `py_dashboards` to add Python files that generate dashboards to your build.
@@ -199,7 +186,7 @@ Then pass the plugin to the image rule's `plugins` list as `@grafana_plotly_plug
199186

200187
### Custom Grafana image
201188

202-
The default version of Grafana (12.0) may not suit your needs.
189+
The default version of Grafana (11.6.9) may not suit your needs.
203190
You can override the container by modifying the grafana extension in your MODULE.bazel.
204191

205192
## API Reference

example/sample.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import json
2-
from grafana_foundation_sdk.builders import dashboard as dashboard_builder
3-
from grafana_foundation_sdk.builders import text, timeseries
4-
from grafana_foundation_sdk.cog.encoder import JSONEncoder
5-
from grafana_foundation_sdk.models.dashboard import GridPos
1+
from grafanalib.core import *
2+
from grafanalib._gen import print_dashboard
63

7-
dashboard = (
8-
dashboard_builder.Dashboard("Python sample")
9-
# UID is set by uid_injector based on filename
10-
.with_panel(
11-
text.Panel()
12-
.title("Hello world!")
13-
.grid_pos(GridPos(h=8, w=12, x=0, y=0))
14-
)
15-
.with_panel(
16-
timeseries.Panel()
17-
.title("Sample data")
18-
.grid_pos(GridPos(h=8, w=12, x=12, y=0))
19-
)
20-
.build()
4+
dashboard = Dashboard(
5+
title="Python sample",
6+
rows=[
7+
Row(panels=[
8+
Text(content="Hello world!"),
9+
Graph(
10+
title="Sample data",
11+
targets=[
12+
Target(),
13+
],
14+
),
15+
TimeSeries(
16+
title="Sample data",
17+
targets=[
18+
Target(),
19+
],
20+
),
21+
]),
22+
],
2123
)
2224

23-
print(json.dumps(dashboard, cls=JSONEncoder, indent=2))
25+
print_dashboard(dashboard.auto_panel_ids())

grafana/grafana.bzl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
"""Bazel rules for building Grafana dashboards.
22
33
This module provides rules for building Grafana dashboards from JSON files
4-
or Python scripts using the grafana-foundation-sdk.
5-
6-
Example Python dashboard using grafana-foundation-sdk:
7-
8-
import json
9-
from grafana_foundation_sdk.builders import dashboard as dashboard_builder
10-
from grafana_foundation_sdk.builders import text, timeseries
11-
from grafana_foundation_sdk.cog.encoder import JSONEncoder
12-
from grafana_foundation_sdk.models.dashboard import GridPos
13-
14-
dashboard = (
15-
dashboard_builder.Dashboard("My Dashboard")
16-
.with_panel(
17-
text.Panel()
18-
.title("Welcome")
19-
.grid_pos(GridPos(h=4, w=24, x=0, y=0))
20-
)
21-
.build()
4+
or Python scripts using grafanalib.
5+
6+
Example Python dashboard using grafanalib:
7+
8+
from grafanalib.core import *
9+
from grafanalib._gen import print_dashboard
10+
11+
dashboard = Dashboard(
12+
title="My Dashboard",
13+
rows=[
14+
Row(panels=[
15+
Text(content="Welcome"),
16+
]),
17+
],
2218
)
2319
24-
print(json.dumps(dashboard, cls=JSONEncoder, indent=2))
20+
print_dashboard(dashboard.auto_panel_ids())
2521
"""
2622

2723
load("@rules_grafana_deps//:requirements.bzl", "requirement")
@@ -100,7 +96,7 @@ def _py_dashboard_builder(src, deps = None):
10096
if deps == None:
10197
deps = []
10298
py_binary_name = src.replace(".py", "_builder")
103-
grafana_deps = requirement("grafana_foundation_sdk")
99+
grafana_deps = requirement("grafanalib")
104100
py_binary(
105101
name = py_binary_name,
106102
srcs = [src],

grafana/requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# run `bazel run //grafana:requirements.update` when you update this file
2-
grafana-foundation-sdk==1759917919!11.6.0
2+
grafanalib==0.7.1

grafana/requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#
55
# bazel run //grafana:requirements.update
66
#
7-
grafana-foundation-sdk==1759917919!11.6.0 \
8-
--hash=sha256:681f8a0464b5f1a6ffc02bdb538b6190bb73f7d03cff8c3b6d71267c0ec6362b \
9-
--hash=sha256:ab3d4882c6cecd2a50015b83b13940b1bb5c040e21d052d63ea6d8e7f0cebac6
7+
attrs==25.4.0 \
8+
--hash=sha256:adcf7e2a1fb3b36ac48d97835bb6d8ade15b8dcce26aba8bf1d14847b57a3373
9+
# via grafanalib
10+
grafanalib==0.7.1 \
11+
--hash=sha256:6fab5d7b837a1f2d1322ef762cd52e565ec0422707a7512765c59f668bdceb58
1012
# via -r grafana/requirements.in

test/dash.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import json
1+
from grafanalib.core import *
2+
from grafanalib._gen import print_dashboard
23
import sys
3-
from grafana_foundation_sdk.builders import dashboard as dashboard_builder
4-
from grafana_foundation_sdk.builders import timeseries, prometheus
5-
from grafana_foundation_sdk.cog.encoder import JSONEncoder
6-
from grafana_foundation_sdk.models.dashboard import GridPos
74

85
# this should fail if loaded in python2
96
if b'test' == 'test':
107
sys.exit(1)
118

12-
dashboard = (
13-
dashboard_builder.Dashboard("Python sample")
14-
# UID is set by uid_injector based on filename
15-
.with_panel(
16-
timeseries.Panel()
17-
.title("Sample data")
18-
.grid_pos(GridPos(h=8, w=24, x=0, y=0))
19-
.with_target(
20-
prometheus.Dataquery()
21-
.expr('up{namespace="kube-system"}')
22-
)
23-
)
24-
.build()
9+
dashboard = Dashboard(
10+
title="Python sample",
11+
rows=[
12+
Row(panels=[
13+
Graph(
14+
title="Sample data",
15+
targets=[
16+
Target(expr='up{namespace="kube-system"}', ),
17+
],
18+
),
19+
]),
20+
],
2521
)
2622

27-
print(json.dumps(dashboard, cls=JSONEncoder, indent=2))
23+
print_dashboard(dashboard)

0 commit comments

Comments
 (0)