Skip to content

Commit bdd7821

Browse files
authored
feat(grafana): Grizzly compatibility layer (#280)
## Overview Adds a grizzly compatibility layer in the grafana launcher. Grafana's native dashboard exporting functionality is not compatible with grizzly, and this makes it difficult to import dashboards. Now, the grafana launcher will check if the dashboard is already compatible with grizzly, and if not, will re-export the dashboard and set Grafana's `DS_PROMETHEUS` variable to `Prometheus`. ### Periphery changes - Imports `kona-node` and `op-reth` dashboards by default - Removes the requirement for a dashboard source to define folders.
1 parent 012b4b2 commit bdd7821

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ optimism_package:
122122
dashboard_sources:
123123
# Default public Optimism dashboards
124124
- github.com/ethereum-optimism/grafana-dashboards-public/resources
125+
- github.com/op-rs/kona/docker/recipes/kona-node/grafana
126+
- github.com/paradigmxyz/reth/etc/grafana
125127
# Resource management for grafana container
126128
# CPU is milicores
127129
# RAM is in MB

src/observability/grafana/grafana_launcher.star

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,49 @@ def provision_dashboards(plan, service_url, dashboard_sources):
121121
def grr_push(dir):
122122
return 'grr push "{0}" -e --disable-reporting'.format(dir)
123123

124-
def grr_push_dashboards(name):
125-
return [
126-
grr_push("{0}/folders".format(name)),
124+
def grr_compat(name):
125+
"""
126+
Checks if the dashboards are already compatible with grizzly, by checking if the `apiVersion` is set within all
127+
of the dashboard json files. If not, re-export them with grizzly.
128+
"""
129+
130+
compat_cmds = [
131+
# Check if the dashboard is compatible with grizzly
132+
"find {0}/dashboards -name '*.json' -exec grep -i 'grizzly.grafana.com' {{}} \\+".format(
133+
name
134+
),
135+
# If it is, upload it.
136+
grr_push("{0}/dashboards".format(name)),
137+
]
138+
compat_fix_cmds = [
139+
# Remove all files that aren't JSON files before exporting
140+
"find {0}/dashboards -type f ! -name '*.json' -delete".format(name),
141+
# Re-export the dashboards with grizzly to a temporary directory.
142+
"grr export {0}/dashboards {0}/grr-dashboards -o json".format(name),
143+
# Replace `dashboards` with `grr-dashboards`
144+
"rm -rf {0}/dashboards && mv {0}/grr-dashboards {0}/dashboards".format(
145+
name
146+
),
147+
# Replace Grafana's prometheus datasource placeholder with Prometheus
148+
"find {0}/dashboards -name '*.json' -exec sed -i 's/${{DS_PROMETHEUS}}/Prometheus/g' {{}} \\+".format(
149+
name
150+
),
151+
# Push the dashboard
127152
grr_push("{0}/dashboards".format(name)),
128153
]
129154

155+
# Force compatibility or push existing folders + dashboards
156+
return [
157+
"(({0} && {1}) || echo 'No folders to push') && (({2}) || ({3}))".format(
158+
# Upload folders, if they exist
159+
"ls {0}/folders".format(name),
160+
grr_push("{0}/folders".format(name)),
161+
# Upload the dashboards after
162+
util.join_cmds(compat_cmds),
163+
util.join_cmds(compat_fix_cmds),
164+
)
165+
]
166+
130167
grr_commands = [
131168
"grr config create-context kurtosis",
132169
]
@@ -137,7 +174,7 @@ def provision_dashboards(plan, service_url, dashboard_sources):
137174
dashboard_artifact_name = plan.upload_files(dashboard_src, name=dashboard_name)
138175

139176
files["/" + dashboard_name] = dashboard_artifact_name
140-
grr_commands += grr_push_dashboards(dashboard_name)
177+
grr_commands += grr_compat(dashboard_name)
141178

142179
plan.run_sh(
143180
description="upload dashboards",

src/package_io/input_parser.star

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ def default_grafana_params(registry):
461461
return {
462462
"image": registry.get(_registry.GRAFANA),
463463
"dashboard_sources": [
464-
"github.com/ethereum-optimism/grafana-dashboards-public/resources"
464+
"github.com/ethereum-optimism/grafana-dashboards-public/resources",
465+
"github.com/op-rs/kona/docker/recipes/kona-node/grafana",
466+
"github.com/paradigmxyz/reth/etc/grafana",
465467
],
466468
"min_cpu": 10,
467469
"max_cpu": 1000,

0 commit comments

Comments
 (0)