github.com/thanos-io/thanos@v0.32.5/Makefile (about) 1 include .bingo/Variables.mk 2 include .busybox-versions 3 4 FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -path ./internal/cortex -prune -o -name '*.go' -print) 5 MD_FILES_TO_FORMAT = $(shell find docs -name "*.md") $(shell find examples -name "*.md") $(filter-out mixin/runbook.md, $(shell find mixin -name "*.md")) $(shell ls *.md) 6 FAST_MD_FILES_TO_FORMAT = $(shell git diff --name-only | grep "\.md") 7 8 DOCKER_IMAGE_REPO ?= quay.io/thanos/thanos 9 DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short HEAD) 10 DOCKER_CI_TAG ?= test 11 12 GH_PARALLEL ?= 1 13 GH_INDEX ?= 0 14 15 BASE_DOCKER_SHA='' 16 arch = $(shell uname -m) 17 18 # The include .busybox-versions includes the SHA's of all the platforms, which can be used as var. 19 ifeq ($(arch), x86_64) 20 # amd64 21 BASE_DOCKER_SHA=${amd64} 22 else ifeq ($(arch), armv8) 23 # arm64 24 BASE_DOCKER_SHA=${arm64} 25 else ifeq ($(arch), arm64) 26 # arm64 27 BASE_DOCKER_SHA=${arm64} 28 else ifeq ($(arch), aarch64) 29 # arm64 30 BASE_DOCKER_SHA=${arm64} 31 else ifeq ($(arch), ppc64le) 32 # ppc64le 33 BASE_DOCKER_SHA=${ppc64le} 34 else 35 echo >&2 "only support amd64, arm64 or ppc64le arch" && exit 1 36 endif 37 DOCKER_ARCHS ?= amd64 arm64 ppc64le 38 # Generate three targets: docker-xxx-amd64, docker-xxx-arm64, docker-xxx-ppc64le. 39 # Run make docker-xxx -n to see the result with dry run. 40 BUILD_DOCKER_ARCHS = $(addprefix docker-build-,$(DOCKER_ARCHS)) 41 TEST_DOCKER_ARCHS = $(addprefix docker-test-,$(DOCKER_ARCHS)) 42 PUSH_DOCKER_ARCHS = $(addprefix docker-push-,$(DOCKER_ARCHS)) 43 44 # Ensure everything works even if GOPATH is not set, which is often the case. 45 # The `go env GOPATH` will work for all cases for Go 1.8+. 46 GOPATH ?= $(shell go env GOPATH) 47 TMP_GOPATH ?= /tmp/thanos-go 48 GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin 49 export GOBIN 50 51 # Promu is using this exact variable name, do not rename. 52 PREFIX ?= $(GOBIN) 53 54 GO111MODULE ?= on 55 export GO111MODULE 56 GOPROXY ?= https://proxy.golang.org 57 export GOPROXY 58 59 GOTEST_OPTS ?= -failfast -timeout 10m -v 60 BIN_DIR ?= $(shell pwd)/tmp/bin 61 OS ?= $(shell uname -s | tr '[A-Z]' '[a-z]') 62 ARCH ?= $(shell uname -m) 63 64 # Tools. 65 PROTOC ?= $(GOBIN)/protoc-$(PROTOC_VERSION) 66 PROTOC_VERSION ?= 3.20.1 67 GIT ?= $(shell which git) 68 69 # Support gsed on OSX (installed via brew), falling back to sed. On Linux 70 # systems gsed won't be installed, so will use sed as expected. 71 SED ?= $(shell which gsed 2>/dev/null || which sed) 72 73 THANOS_MIXIN ?= mixin 74 JSONNET_VENDOR_DIR ?= mixin/vendor 75 76 WEB_DIR ?= website 77 WEBSITE_BASE_URL ?= https://thanos.io 78 MDOX_VALIDATE_CONFIG ?= .mdox.validate.yaml 79 # for website pre process 80 export MDOX 81 PUBLIC_DIR ?= $(WEB_DIR)/public 82 ME ?= $(shell whoami) 83 84 REACT_APP_PATH = pkg/ui/react-app 85 REACT_APP_SOURCE_FILES = $(shell find $(REACT_APP_PATH)/public/ $(REACT_APP_PATH)/src/ $(REACT_APP_PATH)/tsconfig.json) 86 REACT_APP_OUTPUT_DIR = pkg/ui/static/react 87 REACT_APP_NODE_MODULES_PATH = $(REACT_APP_PATH)/node_modules 88 89 define require_clean_work_tree 90 @git update-index -q --ignore-submodules --refresh 91 92 @if ! git diff-files --quiet --ignore-submodules --; then \ 93 echo >&2 "cannot $1: you have unstaged changes."; \ 94 git diff -r --ignore-submodules -- >&2; \ 95 echo >&2 "Please commit or stash them."; \ 96 exit 1; \ 97 fi 98 99 @if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \ 100 echo >&2 "cannot $1: your index contains uncommitted changes."; \ 101 git diff --cached -r --ignore-submodules HEAD -- >&2; \ 102 echo >&2 "Please commit or stash them."; \ 103 exit 1; \ 104 fi 105 106 endef 107 108 help: ## Displays help. 109 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-z0-9A-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) 110 111 .PHONY: all 112 all: format build 113 114 $(REACT_APP_NODE_MODULES_PATH): $(REACT_APP_PATH)/package.json $(REACT_APP_PATH)/package-lock.json 115 cd $(REACT_APP_PATH) && npm ci 116 117 $(REACT_APP_OUTPUT_DIR): $(REACT_APP_NODE_MODULES_PATH) $(REACT_APP_SOURCE_FILES) 118 @echo ">> building React app" 119 @scripts/build-react-app.sh 120 121 .PHONY: assets 122 assets: # Repacks all static assets into go file for easier deploy. 123 assets: $(GO_BINDATA) $(REACT_APP_OUTPUT_DIR) 124 @echo ">> deleting asset file" 125 @rm pkg/ui/bindata.go || true 126 @echo ">> writing assets" 127 @$(GO_BINDATA) $(bindata_flags) -pkg ui -o pkg/ui/bindata.go pkg/ui/static/... 128 @$(MAKE) format 129 130 .PHONY: react-app-lint 131 react-app-lint: $(REACT_APP_NODE_MODULES_PATH) 132 @echo ">> running React app linting" 133 cd $(REACT_APP_PATH) && npm run lint:ci 134 135 .PHONY: react-app-lint-fix 136 react-app-lint-fix: 137 @echo ">> running React app linting and fixing errors where possible" 138 cd $(REACT_APP_PATH) && npm run lint 139 140 .PHONY: react-app-test 141 react-app-test: | $(REACT_APP_NODE_MODULES_PATH) react-app-lint 142 @echo ">> running React app tests" 143 cd $(REACT_APP_PATH) && export CI=true && npm test --no-watch 144 145 .PHONY: react-app-start 146 react-app-start: $(REACT_APP_NODE_MODULES_PATH) 147 @echo ">> running React app" 148 cd $(REACT_APP_PATH) && npm start 149 150 .PHONY: build 151 build: ## Builds Thanos binary using `promu`. 152 build: check-git deps $(PROMU) 153 @echo ">> building Thanos binary in $(PREFIX)" 154 @$(PROMU) build --prefix $(PREFIX) 155 156 GIT_BRANCH=$(shell $(GIT) rev-parse --abbrev-ref HEAD) 157 .PHONY: crossbuild 158 crossbuild: ## Builds all binaries for all platforms. 159 ifeq ($(GIT_BRANCH), main) 160 crossbuild: | $(PROMU) 161 @echo ">> crossbuilding all binaries" 162 # we only care about below two for the main branch 163 $(PROMU) crossbuild -v -p linux/amd64 -p linux/arm64 -p linux/ppc64le 164 else 165 crossbuild: | $(PROMU) 166 @echo ">> crossbuilding all binaries" 167 $(PROMU) crossbuild -v 168 endif 169 170 171 .PHONY: deps 172 deps: ## Ensures fresh go.mod and go.sum. 173 @go mod tidy 174 @go mod verify 175 176 # NOTICE: This is a temporary workaround for the cyclic dependency issue documented in: 177 # https://github.com/thanos-io/thanos/issues/3832 178 # The real solution is to have our own version of needed packages, or extract them out from a dedicated module. 179 # vendor dependencies 180 .PHONY: internal/cortex 181 internal/cortex: ## Ensures the latest packages from 'cortex' are synced. 182 rm -rf internal/cortex 183 rm -rf tmp/cortex 184 git clone --depth 1 https://github.com/cortexproject/cortex tmp/cortex 185 mkdir -p internal/cortex 186 rsync -avur --delete tmp/cortex/pkg/* internal/cortex --include-from=.cortex-packages.txt 187 mkdir -p internal/cortex/integration 188 cp -R tmp/cortex/integration/ca internal/cortex/integration/ca 189 find internal/cortex -type f -exec sed -i 's/github.com\/cortexproject\/cortex\/pkg/github.com\/thanos-io\/thanos\/internal\/cortex/g' {} + 190 find internal/cortex -type f -exec sed -i 's/github.com\/cortexproject\/cortex\/integration/github.com\/thanos-io\/thanos\/internal\/cortex\/integration/g' {} + 191 rm -rf tmp/cortex 192 @echo ">> ensuring Copyright headers" 193 @go run ./scripts/copyright 194 195 .PHONY: docker 196 docker: ## Builds 'thanos' docker with no tag. 197 ifeq ($(OS)_$(ARCH), linux_x86_64) 198 docker: build 199 @echo ">> copying Thanos from $(PREFIX) to ./thanos_tmp_for_docker" 200 @cp $(PREFIX)/thanos ./thanos_tmp_for_docker 201 @echo ">> building docker image 'thanos'" 202 @docker build -t "thanos" --build-arg BASE_DOCKER_SHA=$(BASE_DOCKER_SHA) . 203 @rm ./thanos_tmp_for_docker 204 else 205 docker: docker-multi-stage 206 endif 207 208 .PHONY: docker-multi-stage 209 docker-multi-stage: ## Builds 'thanos' docker image using multi-stage. 210 docker-multi-stage: 211 @echo ">> building docker image 'thanos' with Dockerfile.multi-stage" 212 @docker build -f Dockerfile.multi-stage -t "thanos" --build-arg BASE_DOCKER_SHA=$(BASE_DOCKER_SHA) . 213 214 # docker-build builds docker images with multiple architectures. 215 .PHONY: docker-build $(BUILD_DOCKER_ARCHS) 216 docker-build: $(BUILD_DOCKER_ARCHS) 217 $(BUILD_DOCKER_ARCHS): docker-build-%: 218 @docker build -t "thanos-linux-$*" \ 219 --build-arg BASE_DOCKER_SHA="$($*)" \ 220 --build-arg ARCH="$*" \ 221 -f Dockerfile.multi-arch . 222 223 .PHONY: docker-test $(TEST_DOCKER_ARCHS) 224 docker-test: $(TEST_DOCKER_ARCHS) 225 $(TEST_DOCKER_ARCHS): docker-test-%: 226 @echo ">> testing image" 227 @docker run "thanos-linux-$*" --help 228 229 # docker-manifest push docker manifest to support multiple architectures. 230 .PHONY: docker-manifest 231 docker-manifest: 232 @echo ">> creating and pushing manifest" 233 @DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_IMAGE_REPO)-linux-$(ARCH):$(DOCKER_IMAGE_TAG)) 234 @DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)" 235 236 .PHONY: docker-push $(PUSH_DOCKER_ARCHS) 237 docker-push: ## Pushes Thanos docker image build to "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)". 238 docker-push: $(PUSH_DOCKER_ARCHS) 239 $(PUSH_DOCKER_ARCHS): docker-push-%: 240 @echo ">> pushing image" 241 @docker tag "thanos-linux-$*" "$(DOCKER_IMAGE_REPO)-linux-$*:$(DOCKER_IMAGE_TAG)" 242 @docker push "$(DOCKER_IMAGE_REPO)-linux-$*:$(DOCKER_IMAGE_TAG)" 243 244 .PHONY: docs 245 docs: ## Generates docs for all thanos commands, localise links, ensure GitHub format. 246 docs: build examples $(MDOX) 247 @echo ">> generating docs" 248 PATH="${PATH}:$(GOBIN)" $(MDOX) fmt --links.localize.address-regex="https://thanos.io/.*" $(MD_FILES_TO_FORMAT) 249 $(MAKE) white-noise-cleanup 250 251 .PHONY: changed-docs 252 changed-docs: ## Only do the docs check for files that have been changed (git status) 253 changed-docs: build examples $(MDOX) 254 @echo ">> generating docs on changed files" 255 PATH="${PATH}:$(GOBIN)" $(MDOX) fmt --links.localize.address-regex="https://thanos.io/.*" $(FAST_MD_FILES_TO_FORMAT) 256 $(MAKE) white-noise-cleanup 257 258 .PHONY: check-docs 259 check-docs: ## Checks docs against discrepancy with flags, links, white noise. 260 check-docs: build examples $(MDOX) 261 @echo ">> checking docs" 262 PATH="${PATH}:$(GOBIN)" $(MDOX) fmt -l --links.localize.address-regex="https://thanos.io/.*" --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) $(MD_FILES_TO_FORMAT) 263 $(MAKE) white-noise-cleanup 264 $(call require_clean_work_tree,'run make docs and commit changes') 265 266 .PHONY: white-noise-cleanup 267 white-noise-cleanup: ## Cleans up white noise in docs. 268 white-noise-cleanup: 269 @echo ">> cleaning up white noise" 270 @find . -type f \( -name "*.md" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh 271 272 .PHONY: shell-format 273 shell-format: $(SHFMT) 274 @echo ">> formatting shell scripts" 275 @$(SHFMT) -i 2 -ci -w -s $(shell find . -type f -name "*.sh" -not -path "*vendor*" -not -path "tmp/*") 276 277 .PHONY: format 278 format: ## Formats code including imports and cleans up white noise. 279 format: go-format shell-format 280 @SED_BIN="$(SED)" scripts/cleanup-white-noise.sh $(FILES_TO_FMT) 281 282 .PHONY: go-format 283 go-format: ## Formats Go code including imports. 284 go-format: $(GOIMPORTS) 285 @echo ">> formatting go code" 286 @gofmt -s -w $(FILES_TO_FMT) 287 @$(GOIMPORTS) -w $(FILES_TO_FMT) 288 289 .PHONY: proto 290 proto: ## Generates Go files from Thanos proto files. 291 proto: check-git $(GOIMPORTS) $(PROTOC) $(PROTOC_GEN_GOGOFAST) 292 @GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" PROTOC_GEN_GOGOFAST_BIN="$(PROTOC_GEN_GOGOFAST)" PROTOC_VERSION="$(PROTOC_VERSION)" scripts/genproto.sh 293 294 .PHONY: tarballs-release 295 tarballs-release: ## Build tarballs. 296 tarballs-release: $(PROMU) 297 @echo ">> Publishing tarballs" 298 $(PROMU) crossbuild -v tarballs 299 $(PROMU) checksum -v .tarballs 300 $(PROMU) release -v .tarballs 301 302 .PHONY: test 303 test: ## Runs all Thanos Go unit tests against each supported version of Prometheus. This excludes tests in ./test/e2e. 304 test: export GOCACHE= $(TMP_GOPATH)/gocache 305 test: export THANOS_TEST_MINIO_PATH= $(MINIO) 306 test: export THANOS_TEST_PROMETHEUS_PATHS= $(PROMETHEUS) 307 test: export THANOS_TEST_ALERTMANAGER_PATH= $(ALERTMANAGER) 308 test: check-git install-tool-deps 309 @echo ">> install thanos GOOPTS=${GOOPTS}" 310 @echo ">> running unit tests (without /test/e2e). Do export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS if you want to skip e2e tests against all real store buckets. Current value: ${THANOS_TEST_OBJSTORE_SKIP}" 311 @go test -timeout 15m $(shell go list ./... | grep -v /vendor/ | grep -v /test/e2e); 312 313 .PHONY: test-local 314 test-local: ## Runs test excluding tests for ALL object storage integrations. 315 test-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS 316 test-local: 317 $(MAKE) test 318 319 .PHONY: test-e2e 320 test-e2e: ## Runs all Thanos e2e docker-based e2e tests from test/e2e. Required access to docker daemon. 321 test-e2e: docker $(GOTESPLIT) 322 @echo ">> cleaning docker environment." 323 @docker system prune -f --volumes 324 @echo ">> cleaning e2e test garbage." 325 @rm -rf ./test/e2e/e2e_* 326 @echo ">> running /test/e2e tests." 327 # NOTE(bwplotka): 328 # * If you see errors on CI (timeouts), but not locally, try to add -parallel 1 (Wiard note: to the GOTEST_OPTS arg) to limit to single CPU to reproduce small 1CPU machine. 329 # NOTE(GiedriusS): 330 # * If you want to limit CPU time available in e2e tests then pass E2E_DOCKER_CPUS environment variable. For example, E2E_DOCKER_CPUS=0.05 limits CPU time available 331 # to spawned Docker containers to 0.05 cores. 332 @$(GOTESPLIT) -total ${GH_PARALLEL} -index ${GH_INDEX} ./test/e2e/... -- ${GOTEST_OPTS} 333 334 .PHONY: test-e2e-local 335 test-e2e-local: ## Runs all thanos e2e tests locally. 336 test-e2e-local: export THANOS_TEST_OBJSTORE_SKIP=GCS,S3,AZURE,SWIFT,COS,ALIYUNOSS,BOS,OCI,OBS 337 test-e2e-local: 338 $(MAKE) test-e2e 339 340 .PHONY: quickstart 341 quickstart: ## Installs and runs a quickstart example of thanos. 342 quickstart: build install-tool-deps 343 quickstart: 344 scripts/quickstart.sh 345 346 .PHONY: install-tool-deps 347 install-tool-deps: ## Installs dependencies for integration tests. It installs supported versions of Prometheus and alertmanager to test against in integration tests. 348 install-tool-deps: $(ALERTMANAGER) $(MINIO) $(PROMETHEUS) 349 @echo ">>GOBIN=$(GOBIN)" 350 351 .PHONY: check-git 352 check-git: 353 ifneq ($(GIT),) 354 @test -x $(GIT) || (echo >&2 "No git executable binary found at $(GIT)."; exit 1) 355 else 356 @echo >&2 "No git binary found."; exit 1 357 endif 358 359 .PHONY: web-pre-process 360 web-pre-process: $(MDOX) 361 @echo ">> running documentation website pre processing" 362 scripts/website/websitepreprocess.sh 363 364 .PHONY: web 365 web: ## Builds our website. 366 web: web-pre-process $(HUGO) 367 @echo ">> building documentation website" 368 @rm -rf "$(WEB_DIR)/public" 369 @cd $(WEB_DIR) && HUGO_ENV=production $(HUGO) --config hugo.yaml --minify -v -b $(WEBSITE_BASE_URL) 370 371 .PHONY: web-serve 372 web-serve: ## Builds and serves Thanos website on localhost. 373 web-serve: web-pre-process $(HUGO) 374 @echo ">> serving documentation website" 375 @cd $(WEB_DIR) && $(HUGO) --config hugo.yaml -v server 376 377 .PHONY:lint 378 lint: ## Runs various static analysis against our code. 379 lint: go-lint react-app-lint shell-lint 380 @echo ">> detecting white noise" 381 @find . -type f \( -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh 382 $(call require_clean_work_tree,'detected white noise, run make lint and commit changes') 383 384 # PROTIP: 385 # Add 386 # --cpu-profile-path string Path to CPU profile output file 387 # --mem-profile-path string Path to memory profile output file 388 # to debug big allocations during linting. 389 .PHONY: go-lint 390 go-lint: check-git deps $(GOLANGCI_LINT) $(FAILLINT) 391 $(call require_clean_work_tree,'detected not clean work tree before running lint, previous job changed something?') 392 @echo ">> verifying modules being imported" 393 @# TODO(bwplotka): Add, Printf, DefaultRegisterer, NewGaugeFunc and MustRegister once exception are accepted. Add fmt.{Errorf}=github.com/pkg/errors.{Errorf} once https://github.com/fatih/faillint/issues/10 is addressed. 394 @$(FAILLINT) -paths "errors=github.com/pkg/errors,\ 395 github.com/prometheus/tsdb=github.com/prometheus/prometheus/tsdb,\ 396 github.com/prometheus/prometheus/pkg/testutils=github.com/thanos-io/thanos/pkg/testutil,\ 397 github.com/prometheus/client_golang/prometheus.{DefaultGatherer,DefBuckets,NewUntypedFunc,UntypedFunc},\ 398 github.com/prometheus/client_golang/prometheus.{NewCounter,NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,\ 399 NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec}=github.com/prometheus/client_golang/prometheus/promauto.{NewCounter,\ 400 NewCounterVec,NewCounterVec,NewGauge,NewGaugeVec,NewGaugeFunc,NewHistorgram,NewHistogramVec,NewSummary,NewSummaryVec},\ 401 github.com/NYTimes/gziphandler.{GzipHandler}=github.com/klauspost/compress/gzhttp.{GzipHandler},\ 402 sync/atomic=go.uber.org/atomic,github.com/cortexproject/cortex=github.com/thanos-io/thanos/internal/cortex,\ 403 io/ioutil.{Discard,NopCloser,ReadAll,ReadDir,ReadFile,TempDir,TempFile,Writefile}" $(shell go list ./... | grep -v "internal/cortex") 404 @$(FAILLINT) -paths "fmt.{Print,Println,Sprint}" -ignore-tests ./... 405 @echo ">> linting all of the Go files GOGC=${GOGC}" 406 @$(GOLANGCI_LINT) run 407 @echo ">> ensuring Copyright headers" 408 @go run ./scripts/copyright 409 @echo ">> ensuring generated proto files are up to date" 410 @$(MAKE) proto 411 $(call require_clean_work_tree,'detected files without copyright, run make lint and commit changes') 412 413 .PHONY: shell-lint 414 shell-lint: ## Runs static analysis against our shell scripts. 415 shell-lint: $(SHELLCHECK) 416 @echo ">> linting all of the shell script files" 417 @$(SHELLCHECK) --severity=error -o all -s bash $(shell find . -type f -name "*.sh" -not -path "*vendor*" -not -path "tmp/*" -not -path "*node_modules*") 418 419 .PHONY: examples 420 examples: jsonnet-vendor jsonnet-format ${THANOS_MIXIN}/README.md examples/alerts/alerts.md examples/alerts/alerts.yaml examples/alerts/rules.yaml examples/dashboards examples/tmp mixin/runbook.md 421 422 .PHONY: examples/tmp 423 examples/tmp: 424 -rm -rf examples/tmp/ 425 -mkdir -p examples/tmp/ 426 $(JSONNET) -J ${JSONNET_VENDOR_DIR} -m examples/tmp/ ${THANOS_MIXIN}/separated-alerts.jsonnet | xargs -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml; rm -f {}' -- {} 427 428 .PHONY: examples/dashboards # to keep examples/dashboards/dashboards.md. 429 examples/dashboards: $(JSONNET) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/dashboards/* 430 -rm -rf examples/dashboards/*.json 431 $(JSONNET) -J ${JSONNET_VENDOR_DIR} -m examples/dashboards ${THANOS_MIXIN}/dashboards.jsonnet 432 433 examples/alerts/alerts.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/alerts/* 434 $(JSONNET) ${THANOS_MIXIN}/alerts.jsonnet | $(GOJSONTOYAML) > $@ 435 436 examples/alerts/rules.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/rules/* 437 $(JSONNET) ${THANOS_MIXIN}/rules.jsonnet | $(GOJSONTOYAML) > $@ 438 439 .PHONY: mixin/runbook.md 440 mixin/runbook.md: $(PROMDOC) examples/alerts/alerts.yaml 441 $(PROMDOC) generate examples/alerts/alerts.yaml -i mixin -o $@ 442 443 .PHONY: jsonnet-vendor 444 jsonnet-vendor: $(JB) $(THANOS_MIXIN)/jsonnetfile.json $(THANOS_MIXIN)/jsonnetfile.lock.json 445 rm -rf ${JSONNET_VENDOR_DIR} 446 cd ${THANOS_MIXIN} && $(JB) install 447 448 JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s 449 450 .PHONY: jsonnet-format 451 jsonnet-format: $(JSONNETFMT) 452 find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ 453 xargs -n 1 -- $(JSONNETFMT_CMD) -i 454 455 .PHONY: jsonnet-lint 456 jsonnet-lint: $(JSONNET_LINT) jsonnet-vendor 457 find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \ 458 xargs -n 1 -- $(JSONNET_LINT) -J ${JSONNET_VENDOR_DIR} 459 find ./mixin -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | sed -E \ 460 -e 's/.*\///' \ 461 -e '/^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\.(lib|j)sonnet$$/!{s/(.*)/Non-RFC1123 filename: \1/;q1};{d}' 462 463 .PHONY: example-rules-lint 464 example-rules-lint: $(PROMTOOL) examples/alerts/alerts.yaml examples/alerts/rules.yaml 465 $(PROMTOOL) check rules examples/alerts/alerts.yaml examples/alerts/rules.yaml 466 $(PROMTOOL) test rules examples/alerts/tests.yaml 467 468 .PHONY: check-examples 469 check-examples: examples example-rules-lint 470 $(call require_clean_work_tree,'all generated files should be committed, run make check-examples and commit changes.') 471 472 .PHONY: examples-clean 473 examples-clean: 474 rm -f examples/alerts/alerts.yaml 475 rm -f examples/alerts/rules.yaml 476 rm -f examples/dashboards/*.json 477 rm -f examples/tmp/*.yaml 478 479 # non-phony targets 480 $(BIN_DIR): 481 mkdir -p $(BIN_DIR) 482 483 SHELLCHECK ?= $(BIN_DIR)/shellcheck 484 $(SHELLCHECK): $(BIN_DIR) 485 @echo "Downloading Shellcheck" 486 curl -sNL "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.$(OS).$(ARCH).tar.xz" | tar --strip-components=1 -xJf - -C $(BIN_DIR) 487 488 $(PROTOC): 489 @mkdir -p $(TMP_GOPATH) 490 @echo ">> fetching protoc@${PROTOC_VERSION}" 491 @PROTOC_VERSION="$(PROTOC_VERSION)" TMP_GOPATH="$(TMP_GOPATH)" scripts/installprotoc.sh 492 @echo ">> installing protoc@${PROTOC_VERSION}" 493 @mv -- "$(TMP_GOPATH)/bin/protoc" "$(GOBIN)/protoc-$(PROTOC_VERSION)" 494 @echo ">> produced $(GOBIN)/protoc-$(PROTOC_VERSION)"