prometheus
/
Makefile
173 строки · 5.8 Кб
1# Copyright 2018 The Prometheus Authors
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14# Needs to be defined before including Makefile.common to auto-generate targets
15DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le s390x
16
17UI_PATH = web/ui
18UI_NODE_MODULES_PATH = $(UI_PATH)/node_modules
19REACT_APP_NPM_LICENSES_TARBALL = "npm_licenses.tar.bz2"
20
21PROMTOOL = ./promtool
22TSDB_BENCHMARK_NUM_METRICS ?= 1000
23TSDB_BENCHMARK_DATASET ?= ./tsdb/testdata/20kseries.json
24TSDB_BENCHMARK_OUTPUT_DIR ?= ./benchout
25
26GOLANGCI_LINT_OPTS ?= --timeout 4m
27GOYACC_VERSION ?= v0.6.0
28
29include Makefile.common
30
31DOCKER_IMAGE_NAME ?= prometheus
32
33.PHONY: update-npm-deps
34update-npm-deps:
35@echo ">> updating npm dependencies"
36./scripts/npm-deps.sh "minor"
37
38.PHONY: upgrade-npm-deps
39upgrade-npm-deps:
40@echo ">> upgrading npm dependencies"
41./scripts/npm-deps.sh "latest"
42
43.PHONY: ui-bump-version
44ui-bump-version:
45version=$$(sed s/2/0/ < VERSION) && ./scripts/ui_release.sh --bump-version "$${version}"
46cd web/ui && npm install
47git add "./web/ui/package-lock.json" "./**/package.json"
48
49.PHONY: ui-install
50ui-install:
51cd $(UI_PATH) && npm install
52
53.PHONY: ui-build
54ui-build:
55cd $(UI_PATH) && CI="" npm run build
56
57.PHONY: ui-build-module
58ui-build-module:
59cd $(UI_PATH) && npm run build:module
60
61.PHONY: ui-test
62ui-test:
63cd $(UI_PATH) && CI=true npm run test
64
65.PHONY: ui-lint
66ui-lint:
67cd $(UI_PATH) && npm run lint
68
69.PHONY: assets
70assets: ui-install ui-build
71
72.PHONY: assets-compress
73assets-compress: assets
74@echo '>> compressing assets'
75scripts/compress_assets.sh
76
77.PHONY: assets-tarball
78assets-tarball: assets
79@echo '>> packaging assets'
80scripts/package_assets.sh
81
82.PHONY: parser
83parser:
84@echo ">> running goyacc to generate the .go file."
85ifeq (, $(shell command -v goyacc 2> /dev/null))
86@echo "goyacc not installed so skipping"
87@echo "To install: \"go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)\" or run \"make install-goyacc\""
88else
89$(MAKE) promql/parser/generated_parser.y.go
90endif
91
92promql/parser/generated_parser.y.go: promql/parser/generated_parser.y
93@echo ">> running goyacc to generate the .go file."
94@goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y
95
96.PHONY: clean-parser
97clean-parser:
98@echo ">> cleaning generated parser"
99@rm -f promql/parser/generated_parser.y.go
100
101.PHONY: check-generated-parser
102check-generated-parser: clean-parser promql/parser/generated_parser.y.go
103@echo ">> checking generated parser"
104@git diff --exit-code -- promql/parser/generated_parser.y.go || (echo "Generated parser is out of date. Please run 'make parser' and commit the changes." && false)
105
106.PHONY: install-goyacc
107install-goyacc:
108@echo ">> installing goyacc $(GOYACC_VERSION)"
109@go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)
110
111.PHONY: test
112# If we only want to only test go code we have to change the test target
113# which is called by all.
114ifeq ($(GO_ONLY),1)
115test: common-test check-go-mod-version
116else
117test: check-generated-parser common-test ui-build-module ui-test ui-lint check-go-mod-version
118endif
119
120.PHONY: npm_licenses
121npm_licenses: ui-install
122@echo ">> bundling npm licenses"
123rm -f $(REACT_APP_NPM_LICENSES_TARBALL) npm_licenses
124ln -s . npm_licenses
125find npm_licenses/$(UI_NODE_MODULES_PATH) -iname "license*" | tar cfj $(REACT_APP_NPM_LICENSES_TARBALL) --files-from=-
126rm -f npm_licenses
127
128.PHONY: tarball
129tarball: npm_licenses common-tarball
130
131.PHONY: docker
132docker: npm_licenses common-docker
133
134plugins/plugins.go: plugins.yml plugins/generate.go
135@echo ">> creating plugins list"
136$(GO) generate -tags plugins ./plugins
137
138.PHONY: plugins
139plugins: plugins/plugins.go
140
141.PHONY: build
142build: assets npm_licenses assets-compress plugins common-build
143
144.PHONY: bench_tsdb
145bench_tsdb: $(PROMU)
146@echo ">> building promtool"
147@GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) promtool
148@echo ">> running benchmark, writing result to $(TSDB_BENCHMARK_OUTPUT_DIR)"
149@$(PROMTOOL) tsdb bench write --metrics=$(TSDB_BENCHMARK_NUM_METRICS) --out=$(TSDB_BENCHMARK_OUTPUT_DIR) $(TSDB_BENCHMARK_DATASET)
150@$(GO) tool pprof -svg $(PROMTOOL) $(TSDB_BENCHMARK_OUTPUT_DIR)/cpu.prof > $(TSDB_BENCHMARK_OUTPUT_DIR)/cpuprof.svg
151@$(GO) tool pprof --inuse_space -svg $(PROMTOOL) $(TSDB_BENCHMARK_OUTPUT_DIR)/mem.prof > $(TSDB_BENCHMARK_OUTPUT_DIR)/memprof.inuse.svg
152@$(GO) tool pprof --alloc_space -svg $(PROMTOOL) $(TSDB_BENCHMARK_OUTPUT_DIR)/mem.prof > $(TSDB_BENCHMARK_OUTPUT_DIR)/memprof.alloc.svg
153@$(GO) tool pprof -svg $(PROMTOOL) $(TSDB_BENCHMARK_OUTPUT_DIR)/block.prof > $(TSDB_BENCHMARK_OUTPUT_DIR)/blockprof.svg
154@$(GO) tool pprof -svg $(PROMTOOL) $(TSDB_BENCHMARK_OUTPUT_DIR)/mutex.prof > $(TSDB_BENCHMARK_OUTPUT_DIR)/mutexprof.svg
155
156.PHONY: cli-documentation
157cli-documentation:
158$(GO) run ./cmd/prometheus/ --write-documentation > docs/command-line/prometheus.md
159$(GO) run ./cmd/promtool/ write-documentation > docs/command-line/promtool.md
160
161.PHONY: check-go-mod-version
162check-go-mod-version:
163@echo ">> checking go.mod version matching"
164@./scripts/check-go-mod-version.sh
165
166.PHONY: update-all-go-deps
167update-all-go-deps:
168@$(MAKE) update-go-deps
169@echo ">> updating Go dependencies in ./documentation/examples/remote_storage/"
170@cd ./documentation/examples/remote_storage/ && for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
171$(GO) get -d $$m; \
172done
173@cd ./documentation/examples/remote_storage/ && $(GO) mod tidy
174