Skip to content

Commit 7c79932

Browse files
authored
Merge pull request #736 from arajkumar/grafana-linter
2 parents c76b937 + 1a10840 commit 7c79932

File tree

6 files changed

+772
-113
lines changed

6 files changed

+772
-113
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
- push
44
- pull_request
55
env:
6-
golang-version: '1.16'
6+
golang-version: '1.17'
77
jobs:
88
generate:
99
runs-on: ubuntu-latest
@@ -23,6 +23,9 @@ jobs:
2323
- uses: actions/checkout@v2
2424
with:
2525
persist-credentials: false
26+
- uses: actions/setup-go@v2
27+
with:
28+
go-version: ${{ env.golang-version }}
2629
- run: make --always-make lint
2730
fmt:
2831
runs-on: ubuntu-latest
@@ -31,6 +34,9 @@ jobs:
3134
- uses: actions/checkout@v2
3235
with:
3336
persist-credentials: false
37+
- uses: actions/setup-go@v2
38+
with:
39+
go-version: ${{ env.golang-version }}
3440
- run: make --always-make fmt && git diff --exit-code
3541
unit-tests:
3642
runs-on: ubuntu-latest
@@ -39,4 +45,7 @@ jobs:
3945
- uses: actions/checkout@v2
4046
with:
4147
persist-credentials: false
48+
- uses: actions/setup-go@v2
49+
with:
50+
go-version: ${{ env.golang-version }}
4251
- run: make --always-make test

.lint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclusions:
2+
template-job-rule:
3+
panel-job-instance-rule:

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
BIN_DIR ?= $(shell pwd)/tmp/bin
22

33
JSONNET_VENDOR=vendor
4+
GRAFANA_DASHBOARD_LINTER_BIN=$(BIN_DIR)/dashboard-linter
45
JB_BIN=$(BIN_DIR)/jb
56
JSONNET_BIN=$(BIN_DIR)/jsonnet
67
JSONNETLINT_BIN=$(BIN_DIR)/jsonnet-lint
78
JSONNETFMT_BIN=$(BIN_DIR)/jsonnetfmt
89
PROMTOOL_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)
1011
JSONNETFMT_ARGS=-n 2 --max-blank-lines 2 --string-style s --comment-style s
1112

1213
.PHONY: all
1314
all: 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
2930
prometheus_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
4554
clean:
4655
# Remove all files and directories ignored by git.

scripts/go.mod

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,138 @@
11
module _
22

3-
go 1.14
3+
go 1.17
44

55
require (
66
github.com/google/go-jsonnet v0.17.1-0.20210520122306-7373f5b60678
7+
github.com/grafana/dashboard-linter v0.0.0-20220121193616-222f7f5cfe30
78
github.com/jsonnet-bundler/jsonnet-bundler v0.4.0
8-
github.com/prometheus/prometheus v1.8.2-0.20210701133801-b0944590a1c9
9+
github.com/prometheus/prometheus v1.8.2-0.20211011171444-354d8d2ecfac
10+
)
11+
12+
require (
13+
cloud.google.com/go v0.93.3 // indirect
14+
github.com/Azure/azure-sdk-for-go v57.1.0+incompatible // indirect
15+
github.com/Azure/go-autorest/autorest v0.11.20 // indirect
16+
github.com/Azure/go-autorest/autorest/adal v0.9.15 // indirect
17+
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
18+
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
19+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
20+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
21+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
22+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
23+
github.com/alecthomas/units v0.0.0-20210912230133-d1bdfacee922 // indirect
24+
github.com/armon/go-metrics v0.3.3 // indirect
25+
github.com/aws/aws-sdk-go v1.40.37 // indirect
26+
github.com/beorn7/perks v1.0.1 // indirect
27+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
28+
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed // indirect
29+
github.com/containerd/containerd v1.5.4 // indirect
30+
github.com/davecgh/go-spew v1.1.1 // indirect
31+
github.com/dennwc/varint v1.0.0 // indirect
32+
github.com/digitalocean/godo v1.65.0 // indirect
33+
github.com/docker/distribution v2.7.1+incompatible // indirect
34+
github.com/docker/docker v20.10.8+incompatible // indirect
35+
github.com/docker/go-connections v0.4.0 // indirect
36+
github.com/docker/go-units v0.4.0 // indirect
37+
github.com/edsrzf/mmap-go v1.0.0 // indirect
38+
github.com/envoyproxy/go-control-plane v0.9.9 // indirect
39+
github.com/envoyproxy/protoc-gen-validate v0.6.1 // indirect
40+
github.com/fatih/color v1.10.0 // indirect
41+
github.com/fsnotify/fsnotify v1.5.1 // indirect
42+
github.com/go-kit/log v0.1.0 // indirect
43+
github.com/go-logfmt/logfmt v0.5.1 // indirect
44+
github.com/go-logr/logr v0.4.0 // indirect
45+
github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 // indirect
46+
github.com/go-zookeeper/zk v1.0.2 // indirect
47+
github.com/gogo/protobuf v1.3.2 // indirect
48+
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
49+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
50+
github.com/golang/protobuf v1.5.2 // indirect
51+
github.com/golang/snappy v0.0.4 // indirect
52+
github.com/google/go-cmp v0.5.6 // indirect
53+
github.com/google/go-querystring v1.0.0 // indirect
54+
github.com/google/gofuzz v1.1.0 // indirect
55+
github.com/google/pprof v0.0.0-20210827144239-02619b876842 // indirect
56+
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
57+
github.com/googleapis/gnostic v0.5.5 // indirect
58+
github.com/gophercloud/gophercloud v0.20.0 // indirect
59+
github.com/hashicorp/consul/api v1.10.1 // indirect
60+
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
61+
github.com/hashicorp/go-hclog v0.12.2 // indirect
62+
github.com/hashicorp/go-immutable-radix v1.2.0 // indirect
63+
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
64+
github.com/hashicorp/golang-lru v0.5.4 // indirect
65+
github.com/hashicorp/hcl v1.0.0 // indirect
66+
github.com/hashicorp/serf v0.9.5 // indirect
67+
github.com/hetznercloud/hcloud-go v1.32.0 // indirect
68+
github.com/imdario/mergo v0.3.11 // indirect
69+
github.com/jmespath/go-jmespath v0.4.0 // indirect
70+
github.com/jpillora/backoff v1.0.0 // indirect
71+
github.com/json-iterator/go v1.1.11 // indirect
72+
github.com/linode/linodego v0.32.0 // indirect
73+
github.com/magiconair/properties v1.8.5 // indirect
74+
github.com/mattn/go-colorable v0.1.8 // indirect
75+
github.com/mattn/go-isatty v0.0.12 // indirect
76+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
77+
github.com/miekg/dns v1.1.43 // indirect
78+
github.com/mitchellh/go-homedir v1.1.0 // indirect
79+
github.com/mitchellh/mapstructure v1.4.2 // indirect
80+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
81+
github.com/modern-go/reflect2 v1.0.1 // indirect
82+
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
83+
github.com/oklog/ulid v1.3.1 // indirect
84+
github.com/opencontainers/go-digest v1.0.0 // indirect
85+
github.com/opencontainers/image-spec v1.0.1 // indirect
86+
github.com/opentracing/opentracing-go v1.2.0 // indirect
87+
github.com/pelletier/go-toml v1.9.4 // indirect
88+
github.com/pkg/errors v0.9.1 // indirect
89+
github.com/pmezard/go-difflib v1.0.0 // indirect
90+
github.com/prometheus/client_golang v1.11.0 // indirect
91+
github.com/prometheus/client_model v0.2.0 // indirect
92+
github.com/prometheus/common v0.31.1 // indirect
93+
github.com/prometheus/common/sigv4 v0.1.0 // indirect
94+
github.com/prometheus/exporter-toolkit v0.6.1 // indirect
95+
github.com/prometheus/procfs v0.6.0 // indirect
96+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210223165440-c65ae3540d44 // indirect
97+
github.com/sirupsen/logrus v1.7.0 // indirect
98+
github.com/spf13/afero v1.6.0 // indirect
99+
github.com/spf13/cast v1.4.1 // indirect
100+
github.com/spf13/cobra v1.2.1 // indirect
101+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
102+
github.com/spf13/pflag v1.0.5 // indirect
103+
github.com/spf13/viper v1.9.0 // indirect
104+
github.com/stretchr/testify v1.7.0 // indirect
105+
github.com/subosito/gotenv v1.2.0 // indirect
106+
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
107+
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
108+
go.opencensus.io v0.23.0 // indirect
109+
go.uber.org/atomic v1.9.0 // indirect
110+
go.uber.org/goleak v1.1.10 // indirect
111+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
112+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
113+
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
114+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
115+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
116+
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34 // indirect
117+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
118+
golang.org/x/text v0.3.6 // indirect
119+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
120+
golang.org/x/tools v0.1.5 // indirect
121+
google.golang.org/api v0.56.0 // indirect
122+
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 // indirect
123+
google.golang.org/grpc v1.40.0 // indirect
124+
google.golang.org/protobuf v1.27.1 // indirect
125+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
126+
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
127+
gopkg.in/inf.v0 v0.9.1 // indirect
128+
gopkg.in/ini.v1 v1.63.2 // indirect
129+
gopkg.in/yaml.v2 v2.4.0 // indirect
130+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
131+
k8s.io/api v0.22.1 // indirect
132+
k8s.io/apimachinery v0.22.1 // indirect
133+
k8s.io/client-go v0.22.1 // indirect
134+
k8s.io/klog/v2 v2.10.0 // indirect
135+
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 // indirect
136+
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
137+
sigs.k8s.io/yaml v1.2.0 // indirect
9138
)

0 commit comments

Comments
 (0)