-
Notifications
You must be signed in to change notification settings - Fork 691
/
Copy pathMakefile
56 lines (44 loc) · 1.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Prometheus Mixin Makefile
# Heavily copied from upstream project kubenetes-mixin
PROMETHEUS_IMAGE := prom/prometheus:v2.21.0
JSONNET_FMT := jsonnetfmt
all: fmt prometheus_alerts.yaml prometheus_rules.yaml dashboards_out lint test ## Generate files, lint and test
fmt: ## Format Jsonnet
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- $(JSONNET_FMT) -i
prometheus_alerts.yaml: mixin.libsonnet lib/alerts.jsonnet alerts/*.libsonnet ## Generate Alerts YAML
@mkdir -p manifests
jsonnet -S lib/alerts.jsonnet > manifests/$@
prometheus_rules.yaml: mixin.libsonnet lib/rules.jsonnet rules/*.libsonnet ## Generate Rules YAML
@mkdir -p manifests
jsonnet -S lib/rules.jsonnet > manifests/$@
dashboards_out: mixin.libsonnet lib/dashboards.jsonnet dashboards/*.libsonnet ## Generate Dashboards JSON
jsonnet -J vendor -m manifests lib/dashboards.jsonnet
lint: prometheus_alerts.yaml prometheus_rules.yaml ## Lint and check YAML
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
while read f; do \
$(JSONNET_FMT) "$$f" | diff -u "$$f" -; \
done
docker run \
-v $(PWD)/manifests:/tmp \
--entrypoint '/bin/promtool' \
$(PROMETHEUS_IMAGE) \
check rules /tmp/prometheus_rules.yaml; \
docker run \
-v $(PWD)/manifests:/tmp \
--entrypoint '/bin/promtool' \
$(PROMETHEUS_IMAGE) \
check rules /tmp/prometheus_alerts.yaml
clean: ## Clean up generated files
rm -rf manifests/
# TODO: Find out why official prom images segfaults during `test rules` if not root
test: prometheus_alerts.yaml prometheus_rules.yaml ## Test generated files
docker run \
-v $(PWD):/tmp \
--user root \
--entrypoint '/bin/promtool' \
$(PROMETHEUS_IMAGE) \
test rules /tmp/tests.yaml
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'