forked from rhobs/configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
222 lines (180 loc) · 11.9 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
include .bingo/Variables.mk
SED ?= $(shell which gsed 2>/dev/null || which sed)
XARGS ?= $(shell which gxargs 2>/dev/null || which xargs)
FILES_TO_FMT ?= $(shell find . -path './vendor*' -not -prune -o -name '*.go' -print)
CRD_DIR := $(shell pwd)/crds
TMP_DIR := $(shell pwd)/tmp
BIN_DIR ?= $(TMP_DIR)/bin
OS ?= $(shell uname -s | tr '[A-Z]' '[a-z]')
OC_VERSION ?= latest
OC ?= $(BIN_DIR)/oc
ifeq ($(OS),darwin)
OS = mac
endif
JSONNET_SRC = $(shell find . -type f -not -path './*vendor_jsonnet/*' \( -name '*.libsonnet' -o -name '*.jsonnet' \))
# Given we have Go module in the root of repo we need to have custom dir for jsonnet vendor.
JSONNET_VENDOR_DIR = vendor_jsonnet
.PHONY: all
all: $(JSONNET_VENDOR_DIR) prometheusrules grafana manifests whitelisted_metrics
$(JSONNET_VENDOR_DIR): $(JB) jsonnetfile.json jsonnetfile.lock.json
@$(JB) install --jsonnetpkg-home="$(JSONNET_VENDOR_DIR)"
@echo "module fake // Required for repo-wide go.mod to work with JB that pulls unnecessary go code!" > $(JSONNET_VENDOR_DIR)/go.mod
.PHONY: update
update: $(JB) jsonnetfile.json jsonnetfile.lock.json
@$(JB) update --jsonnetpkg-home="$(JSONNET_VENDOR_DIR)" https://github.com/rhobs/obsctl-reloader/jsonnet/lib@main
.PHONY: format
format: $(JSONNET_SRC) $(JSONNETFMT) go-format
@echo ">>>>> Running format"
$(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s -i $(JSONNET_SRC)
.PHONY: lint
lint: $(JSONNET_LINT) $(JSONNET_VENDOR_DIR) go-lint
@echo ">>>>> Running linter"
echo ${JSONNET_SRC} | $(XARGS) -n 1 -- $(JSONNET_LINT) -J "$(JSONNET_VENDOR_DIR)" -J lib
.PHONY: go-lint
go-lint: ## Runs various static analysis against our code.
go-lint: $(FAILLINT) $(GOLANGCI_LINT) go-format go-deps
@echo ">> verifying modules being imported"
@$(FAILLINT) -paths "fmt.{Print,Printf,Println},io/ioutil.{Discard,NopCloser,ReadAll,ReadDir,ReadFile,TempDir,TempFile,Writefile}" -ignore-tests ./...
@echo ">> examining all of the Go files"
@go vet -stdmethods=false ./...
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCI_LINT) run
.PHONY: go-deps
go-deps: go.mod go.sum
go mod tidy
go mod download
go mod verify
.PHONY: go-format
go-format: ## Formats Go code.
go-format: $(GOIMPORTS) $(GOLANGCI_LINT)
@echo ">> formatting code"
@gofmt -s -w $(FILES_TO_FMT)
@$(GOIMPORTS) -w $(FILES_TO_FMT)
.PHONY: validate
validate: $(OC)
@echo ">>>>> Validating OpenShift Templates"
find . -type f \( -name '*template.yaml' \) | $(XARGS) -I{} $(OC) process -f {} --local -o yaml > /dev/null
.PHONE: sync-crds
sync-crds: $(YQ) $(GOJQ)
@curl https://raw.githubusercontent.com/grafana/loki/main/operator/bundle/community/manifests/loki.grafana.com_alertingrules.yaml | $(YQ) eval -j > $(CRD_DIR)/loki.grafana.com_alertingrules.libsonnet
@curl https://raw.githubusercontent.com/grafana/loki/main/operator/bundle/community/manifests/loki.grafana.com_recordingrules.yaml | $(YQ) eval -j > $(CRD_DIR)/loki.grafana.com_recordingrules.libsonnet
$(MAKE) format
.PHONY: prometheusrules
prometheusrules: resources/observability/prometheusrules
$(MAKE) clean
yes | cp -r observability/prometheus_rule_tests/* resources/observability/prometheusrules/
resources/observability/prometheusrules: format observability/prometheusrules.jsonnet $(JSONNET) $(GOJSONTOYAML)
@echo ">>>>> Running prometheusrules"
rm -f resources/observability/prometheusrules/*.yaml
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" -m resources/observability/prometheusrules observability/prometheusrules.jsonnet | $(XARGS) -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml' -- {}
find resources/observability/prometheusrules/*.yaml | $(XARGS) -I{} sh -c '$(SED) -i "1s;^;---\n\$$schema: /openshift/prometheus-rule-1.yml\n;" {}'
$(MAKE) mimic
.PHONY: test-rules
test-rules: prometheusrules $(PROMTOOL) $(YQ) $(wildcard observability/prometheus_rule_tests/*.prometheusrulestests.yaml) $(wildcard resources/observability/prometheusrules/*.prometheusrules.yaml)
find resources/observability/prometheusrules/ -type f -name *.prometheusrules.yaml | $(XARGS) -I{} sh -c 'cat {} | $(YQ) e ".spec" - > {}.test' -- {}
$(PROMTOOL) check rules `find resources/observability/prometheusrules/ -type f -name *.test`
$(PROMTOOL) test rules `find resources/observability/prometheusrules/ -type f -name *.prometheusrulestests.yaml`
find resources/observability/prometheusrules -type f -name '*.test' -delete
.PHONY: grafana
grafana: resources/observability/grafana/observatorium resources/observability/grafana/observatorium-logs $(JSONNET_VENDOR_DIR)
$(MAKE) clean
resources/observability/grafana/observatorium: format observability/grafana.jsonnet $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running grafana observatorium"
rm -f resources/observability/grafana/observatorium/*.yaml
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" -m resources/observability/grafana/observatorium observability/grafana.jsonnet | $(XARGS) -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml' -- {}
resources/observability/grafana/observatorium-logs: format observability/grafana-obs-logs.jsonnet $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running grafana observatorium-logs"
rm -f resources/observability/grafana/observatorium-logs/*.yaml
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" -m resources/observability/grafana/observatorium-logs observability/grafana-obs-logs.jsonnet | $(XARGS) -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml' -- {}
.PHONY: whitelisted_metrics
whitelisted_metrics: $(GOJSONTOYAML) $(GOJQ)
@echo ">>>>> Running whitelisted_metrics"
# Download the latest metrics file to extract the new added metrics.
# NOTE: Because old clusters could still send metrics the whitelisting is append only
# (configuration/telemeter/metrics.json).
curl -q https://raw.githubusercontent.com/openshift/cluster-monitoring-operator/master/manifests/0000_50_cluster-monitoring-operator_04-config.yaml | \
$(GOJSONTOYAML) -yamltojson | \
$(GOJQ) -r '.data["metrics.yaml"]' | \
$(GOJSONTOYAML) -yamltojson | \
$(GOJQ) -r '.matches | sort' | \
cat configuration/telemeter/metrics.json - | \
$(GOJQ) -s '.[0] + .[1] | sort | unique' > /tmp/metrics.json
cp /tmp/metrics.json configuration/telemeter/metrics.json
.PHONY: migrate-vendor
migrate-vendor:
@# Remove old jsonnet vendor. If vendor is present Go module tools are confused (e.g Goland). It\'s not needed for normal operations.
@rm -rf "./vendor"
.PHONY: manifests
manifests: migrate-vendor format $(JSONNET_VENDOR_DIR)
manifests: resources/services/telemeter-template.yaml resources/services/rhelemeter-template.yaml resources/services/jaeger-template.yaml tests/deploy/manifests/minio-template.yaml tests/deploy/manifests/dex-template.yaml
manifests: resources/services/observatorium-template.yaml resources/services/observatorium-metrics-template.yaml resources/services/observatorium-logs-template.yaml resources/services/observatorium-traces-subscriptions-template.yaml resources/services/observatorium-traces-template.yaml resources/crds/observatorium-logs-crds-template.yaml
manifests: resources/services/metric-federation-rule-template.yaml
$(MAKE) clean
resources/services/jaeger-template.yaml: $(wildcard services/jaeger-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running jaeger-template"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/jaeger-template.jsonnet | $(GOJSONTOYAML) > $@
tests/deploy/manifests/minio-template.yaml: $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running minio-template"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/minio-template.jsonnet | $(GOJSONTOYAML) > $@
tests/deploy/manifests/dex-template.yaml: $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running dex-template"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/dex-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/telemeter-template.yaml: $(wildcard services/telemeter-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running telemeter templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/telemeter-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/rhelemeter-template.yaml: $(wildcard services/telemeter-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running rhelemeter templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/rhelemeter-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-tenants-template.yaml: services/observatorium-tenants-template.jsonnet $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium mst tenants templates"
$(JSONNET) -J vendor services/observatorium-tenants-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-template.yaml: resources/.tmp/tenants/rbac.json services/observatorium.libsonnet services/observatorium-template.jsonnet $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" -J lib services/observatorium-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-metrics-template.yaml: $(wildcard services/observatorium-metrics-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium-metrics templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/observatorium-metrics-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-logs-template.yaml: $(wildcard services/observatorium-logs-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium-logs templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" -J lib services/observatorium-logs-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-traces-template.yaml: $(wildcard services/observatorium-traces-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium-traces templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/observatorium-traces-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/observatorium-traces-subscriptions-template.yaml: $(wildcard services/observatorium-traces-*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running observatorium-traces-subscriptions templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/observatorium-traces-subscriptions-template.jsonnet | $(GOJSONTOYAML) > $@
resources/services/metric-federation-rule-template.yaml: $(wildcard services/metric-federation-rule*) $(wildcard configuration/observatorium/metric-federation-rule*) $(JSONNET) $(GOJSONTOYAML) $(JSONNETFMT)
@echo ">>>>> Running metric-federation-rule templates"
$(JSONNET) -J "$(JSONNET_VENDOR_DIR)" services/metric-federation-rule-template.jsonnet | $(GOJSONTOYAML) > $@
resources/crds/observatorium-logs-crds-template.yaml: $(wildcard crds/loki*) sync-crds $(JSONNET) $(GOJSONTOYAML)
@echo ">>>>> Running obsevatorium-logs-crds template"
$(JSONNET) crds/observatorium-logs-crds-template.jsonnet | $(GOJSONTOYAML) > $@
.PHONY: clean
clean:
find resources/crds -type f ! -name '*.yaml' -delete
find resources/services -type f ! -name '*.yaml' -delete
find resources/observability/prometheusrules -type f ! -name '*.yaml' -delete
find resources/observability/grafana/observatorium -type f ! -name '*.yaml' -delete
find resources/observability/grafana/observatorium-logs -type f ! -name '*.yaml' -delete
find resources/services/telemeter-template.yaml -type f ! -name '*.yaml' -delete
resources/.tmp/tenants/rbac.json: configuration/observatorium/rbac.go
$(MAKE) mimic
# Generate rbac and Pyrra-based Prometheus rules for SLO.
.PHONY: mimic
mimic:
GOFLAGS="-mod=mod" go run ./mimic.go generate -o resources
# In theory we'd be able to run Pyrra as a CLI directly.
# PYRRA_DIR := $(shell pwd)/test
#
# .PHONY: docker-pyrra
# docker-pyrra:
# @chmod -R 777 $(PYRRA_DIR)
# docker run -v $(PYRRA_DIR):/shared -i ghcr.io/pyrra-dev/pyrra:main generate --config-files=/shared/pyrra/*.yaml --prometheus-folder=/shared/rules/ --generic-rules
# Tools
$(TMP_DIR):
mkdir -p $(TMP_DIR)
$(BIN_DIR): $(TMP_DIR)
mkdir -p $(BIN_DIR)
$(OC): $(BIN_DIR)
@echo "Downloading OpenShift CLI"
curl -sNL "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$(OC_VERSION)/openshift-client-$(OS).tar.gz" | tar -xzf - -C $(BIN_DIR)