11BIN_DIR ?= $(shell pwd) /tmp/bin
22
33JSONNET_VENDOR =vendor
4+ GRAFANA_DASHBOARD_LINTER_BIN =$(BIN_DIR ) /dashboard-linter
45JB_BIN =$(BIN_DIR ) /jb
56JSONNET_BIN =$(BIN_DIR ) /jsonnet
67JSONNETLINT_BIN =$(BIN_DIR ) /jsonnet-lint
78JSONNETFMT_BIN =$(BIN_DIR ) /jsonnetfmt
89PROMTOOL_BIN =$(BIN_DIR ) /promtool
9- TOOLING =$(JB_BIN ) $(JSONNETLINT_BIN ) $(JSONNET_BIN ) $(JSONNETFMT_BIN ) $(PROMTOOL_BIN )
10+ TOOLING =$(JB_BIN ) $(JSONNETLINT_BIN ) $(JSONNET_BIN ) $(JSONNETFMT_BIN ) $(PROMTOOL_BIN ) $( GRAFANA_DASHBOARD_LINTER_BIN )
1011JSONNETFMT_ARGS =-n 2 --max-blank-lines 2 --string-style s --comment-style s
1112
1213.PHONY : all
1314all : fmt generate lint test
1415
1516.PHONY : generate
16- generate : prometheus_alerts.yaml prometheus_rules.yaml dashboards_out
17+ generate : prometheus_alerts.yaml prometheus_rules.yaml dashboards_out/.lint
1718
1819$(JSONNET_VENDOR ) : $(JB_BIN ) jsonnetfile.json
1920 $(JB_BIN ) install
@@ -29,18 +30,26 @@ prometheus_alerts.yaml: $(JSONNET_BIN) mixin.libsonnet lib/alerts.jsonnet alerts
2930prometheus_rules.yaml : $(JSONNET_BIN ) mixin.libsonnet lib/rules.jsonnet rules/* .libsonnet
3031 @$(JSONNET_BIN ) -J vendor -S lib/rules.jsonnet > $@
3132
32- dashboards_out : $(JSONNET_BIN ) $(JSONNET_VENDOR ) mixin.libsonnet lib/dashboards.jsonnet dashboards/* .libsonnet
33+ dashboards_out/.lint : $(JSONNET_BIN ) $(JSONNET_VENDOR ) mixin.libsonnet lib/dashboards.jsonnet dashboards/* .libsonnet
3334 @mkdir -p dashboards_out
3435 @$(JSONNET_BIN ) -J vendor -m dashboards_out lib/dashboards.jsonnet
36+ @cp .lint $@
3537
3638.PHONY : lint
37- lint : $(PROMTOOL_BIN ) $(JSONNET_VENDOR ) prometheus_alerts.yaml prometheus_rules.yaml
39+ lint : $(PROMTOOL_BIN ) $(JSONNET_VENDOR ) prometheus_alerts.yaml prometheus_rules.yaml dashboard_lint
3840 find . -name ' vendor' -prune -o -name ' *.libsonnet' -print -o -name ' *.jsonnet' -print | \
3941 xargs -n 1 -- $(JSONNETLINT_BIN ) -J vendor
4042
4143 @$(PROMTOOL_BIN) check rules prometheus_rules.yaml
4244 @$(PROMTOOL_BIN) check rules prometheus_alerts.yaml
4345
46+ .PHONY : dashboard_lint
47+ dashboard_lint : dashboards_out/.lint
48+ # Replace $$interval:$$resolution var with $$__rate_interval to make dashboard-linter happy.
49+ @sed -i -e ' s/$$interval:$$resolution/$$__rate_interval/g' dashboards_out/* .json
50+ @find dashboards_out -name ' *.json' -print0 | xargs -n 1 -0 $(GRAFANA_DASHBOARD_LINTER_BIN ) lint --strict
51+
52+
4453.PHONY : clean
4554clean :
4655 # Remove all files and directories ignored by git.
0 commit comments