forked from elastic/apm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
340 lines (272 loc) · 12.6 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
##############################################################################
# Variables used for various build targets.
##############################################################################
include go.mk
include packaging.mk
# By default we run tests with verbose output. This may be overridden, e.g.
# scripts may set GOTESTFLAGS=-json to format test output for processing.
GOTESTFLAGS?=-v
# Prevent unintended modifications of go.[mod|sum]
GOMODFLAG?=-mod=readonly
PYTHON_ENV?=.
PYTHON_VENV_DIR:=$(PYTHON_ENV)/build/ve/$(shell $(GO) env GOOS)
PYTHON_BIN:=$(PYTHON_VENV_DIR)/bin
PYTHON=$(PYTHON_BIN)/python
CURRENT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Create a local config.mk file to override configuration.
-include config.mk
##############################################################################
# Rules for building and unit-testing apm-server.
##############################################################################
.DEFAULT_GOAL := apm-server
APM_SERVER_BINARIES:= \
build/apm-server-linux-amd64 \
build/apm-server-linux-386 \
build/apm-server-linux-arm64 \
build/apm-server-windows-386.exe \
build/apm-server-windows-amd64.exe \
build/apm-server-darwin-amd64 \
build/apm-server-darwin-arm64
# Strip binary and inject the Git commit hash and timestamp.
LDFLAGS := \
-s \
-X github.com/elastic/beats/v7/libbeat/version.commit=$(GITCOMMIT) \
-X github.com/elastic/beats/v7/libbeat/version.buildTime=$(GITCOMMITTIMESTAMP)
# Rule to build apm-server binaries, using Go's native cross-compilation.
#
# Note, we do not export GO* environment variables in the Makefile,
# as they would be inherited by common dependencies, which is undesirable.
# Instead, we use the "env" command to export them just when cross-compiling
# the apm-server binaries.
.PHONY: $(APM_SERVER_BINARIES)
$(APM_SERVER_BINARIES):
env CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) \
$(GO) build -o $@ -trimpath $(GOFLAGS) $(GOMODFLAG) -ldflags "$(LDFLAGS)" ./x-pack/apm-server
build/apm-server-linux-%: GOOS=linux
build/apm-server-darwin-%: GOOS=darwin
build/apm-server-windows-%: GOOS=windows
build/apm-server-%-386 build/apm-server-%-386.exe: GOARCH=386
build/apm-server-%-amd64 build/apm-server-%-amd64.exe: GOARCH=amd64
build/apm-server-%-amd64 build/apm-server-%-amd64.exe: GOFLAGS+=-buildmode=pie
build/apm-server-%-arm64 build/apm-server-%-arm64.exe: GOARCH=arm64
build/apm-server-%-arm64 build/apm-server-%-arm64.exe: GOFLAGS+=-buildmode=pie
GOVERSIONINFO_FLAGS := \
-file-version "$(APM_SERVER_VERSION)" \
-product-version "$(APM_SERVER_VERSION)" \
-comment "commit=$(GITCOMMIT)"
build/apm-server-windows-386.exe: x-pack/apm-server/versioninfo_windows_386.syso
build/apm-server-windows-amd64.exe: x-pack/apm-server/versioninfo_windows_amd64.syso
x-pack/apm-server/versioninfo_windows_amd64.syso: GOVERSIONINFO_FLAGS+=-64
x-pack/apm-server/versioninfo_%.syso: $(GOVERSIONINFO) $(GITREFFILE) packaging/versioninfo.json
$(GOVERSIONINFO) -o $@ $(GOVERSIONINFO_FLAGS) packaging/versioninfo.json
.PHONY: apm-server
apm-server: build/apm-server-$(shell $(GO) env GOOS)-$(shell $(GO) env GOARCH)
@cp $^ $@
.PHONY: apm-server-oss
apm-server-oss:
@$(GO) build $(GOMODFLAG) -o $@ ./cmd/apm-server
.PHONY: test
test:
@$(GO) test $(GOMODFLAG) $(GOTESTFLAGS) ./...
.PHONY: system-test
system-test:
@(cd systemtest; $(GO) test $(GOMODFLAG) $(GOTESTFLAGS) -timeout=20m ./...)
.PHONY:
clean:
@rm -rf build apm-server apm-server.exe
##############################################################################
# Checks/tests.
##############################################################################
.PHONY: check-full
check-full: update check staticcheck check-docker-compose
.PHONY: check-approvals
check-approvals: $(APPROVALS)
@$(APPROVALS)
check: check-fmt check-headers check-git-diff check-package
.PHONY: check-git-diff
check-git-diff:
@sh script/check_git_clean.sh
BENCH_BENCHTIME?=100ms
BENCH_COUNT?=1
.PHONY: bench
bench:
@$(GO) test -count=$(BENCH_COUNT) -benchmem -run=XXX -benchtime=$(BENCH_BENCHTIME) -bench='.*' ./...
##############################################################################
# Rules for updating config files, etc.
##############################################################################
update: go-generate add-headers build-package notice apm-server.docker.yml
@go mod download all # make sure go.sum is complete
apm-server.docker.yml: apm-server.yml
sed -e 's/localhost:8200/0.0.0.0:8200/' -e 's/localhost:9200/elasticsearch:9200/' $< > $@
.PHONY: go-generate
go-generate:
@$(GO) run internal/model/modeldecoder/generator/cmd/main.go
@$(GO) run internal/model/modelprocessor/generate_internal_metrics.go
@bash script/vendor_otel.sh
@cd cmd/intake-receiver && APM_SERVER_VERSION=$(APM_SERVER_VERSION) $(GO) generate .
.PHONY: add-headers
add-headers: $(GOLICENSER)
ifndef CHECK_HEADERS_DISABLED
@$(GOLICENSER) -exclude x-pack -exclude internal/otel_collector -exclude internal/.otel_collector_mixin
@$(GOLICENSER) -license Elasticv2 x-pack
endif
## get-version : Get the apm server version
.PHONY: get-version
get-version:
@echo $(APM_SERVER_VERSION)
##############################################################################
# Integration package generation.
##############################################################################
build-package: build/packages/apm-$(APM_SERVER_VERSION).zip
build-package-snapshot: build/packages/apm-$(APM_SERVER_VERSION)-preview-$(GITCOMMITTIMESTAMPUNIX).zip
build/packages/apm-$(APM_SERVER_VERSION).zip: build/apmpackage
build/packages/apm-$(APM_SERVER_VERSION)-preview-$(GITCOMMITTIMESTAMPUNIX).zip: build/apmpackage-snapshot
build/packages/apm-%.zip: $(ELASTICPACKAGE)
cd $(filter build/apmpackage%, $^) && $(ELASTICPACKAGE) build
.PHONY: build/apmpackage build/apmpackage-snapshot
build/apmpackage: PACKAGE_VERSION=$(APM_SERVER_VERSION)
build/apmpackage-snapshot: PACKAGE_VERSION=$(APM_SERVER_VERSION)-preview-$(GITCOMMITTIMESTAMPUNIX)
build/apmpackage build/apmpackage-snapshot:
@mkdir -p $(@D) && rm -fr $@
@$(GO) run ./apmpackage/cmd/genpackage -o $@ -version=$(PACKAGE_VERSION)
##############################################################################
# Documentation.
##############################################################################
.PHONY: docs
docs: tf-docs
@rm -rf build/html_docs
sh script/build_apm_docs.sh apm-server docs/index.asciidoc build
.PHONY: tf-docs
tf-docs: $(TERRAFORMDOCS) $(addsuffix /README.md,$(wildcard testing/infra/terraform/modules/*))
testing/infra/terraform/modules/%/README.md: .FORCE
$(TERRAFORMDOCS) markdown --hide-empty --header-from header.md --output-file=README.md --output-mode replace $(subst README.md,,$@)
.PHONY: .FORCE
.FORCE:
##############################################################################
# Beats synchronisation.
##############################################################################
BEATS_VERSION?=main
BEATS_MODULE:=$(shell $(GO) list -m -f {{.Path}} all | grep github.com/elastic/beats)
.PHONY: update-beats
update-beats: update-beats-module update
@echo --- Use this commit message: Update to elastic/beats@$(shell $(GO) list -m -f {{.Version}} $(BEATS_MODULE) | cut -d- -f3)
.PHONY: update-beats-module
update-beats-module:
$(GO) get -d -u $(BEATS_MODULE)@$(BEATS_VERSION) && $(GO) mod tidy
cp -f $$($(GO) list -m -f {{.Dir}} $(BEATS_MODULE))/.go-version .go-version
find . -maxdepth 3 -name Dockerfile -exec sed -i'.bck' -E -e "s#(FROM golang):[0-9]+\.[0-9]+\.[0-9]+#\1:$$(cat .go-version)#g" {} \;
sed -i'.bck' -E -e "s#(:go-version): [0-9]+\.[0-9]+\.[0-9]+#\1: $$(cat .go-version)#g" docs/version.asciidoc
.PHONY: update-beats-docs
update-beats-docs:
$(GO) mod download $(BEATS_MODULE)
rsync -v -r --existing $$($(GO) list -m -f {{.Dir}} $(BEATS_MODULE))/libbeat/ ./docs/legacy/copied-from-beats
##############################################################################
# Linting, style-checking, license header checks, etc.
##############################################################################
# NOTE(axw) ST1000 is disabled for the moment as many packages do not have
# comments. It would be a good idea to add them later, and remove this exception,
# so we're a bit more intentional about the meaning of packages and how code is
# organised.
STATICCHECK_CHECKS?=all,-ST1000
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) -checks=$(STATICCHECK_CHECKS) ./...
.PHONY: check-headers
check-headers: $(GOLICENSER)
ifndef CHECK_HEADERS_DISABLED
@$(GOLICENSER) -d -exclude build -exclude x-pack -exclude internal/otel_collector -exclude internal/.otel_collector_mixin
@$(GOLICENSER) -d -exclude build -license Elasticv2 x-pack
endif
.PHONY: check-docker-compose
check-docker-compose:
./script/check_docker_compose.sh $(BEATS_VERSION)
check-package: build-package $(ELASTICPACKAGE)
@(cd build/apmpackage && $(ELASTICPACKAGE) format --fail-fast && $(ELASTICPACKAGE) lint)
.PHONY: check-gofmt gofmt
check-fmt: check-gofmt
fmt: gofmt
check-gofmt: $(GOIMPORTS)
@PATH=$(GOOSBUILD):$(PATH) sh script/check_goimports.sh
gofmt: $(GOIMPORTS) add-headers
@echo "fmt - goimports: Formatting Go code"
@PATH=$(GOOSBUILD):$(PATH) GOIMPORTSFLAGS=-w sh script/goimports.sh
##############################################################################
# NOTICE.txt & dependencies.csv generation.
##############################################################################
MODULE_DEPS=$(sort $(shell \
$(GO) list -deps -tags=darwin,linux,windows -f "{{with .Module}}{{if not .Main}}{{.Path}}{{end}}{{end}}" ./x-pack/apm-server))
notice: NOTICE.txt
NOTICE.txt build/dependencies-$(APM_SERVER_VERSION).csv: go.mod tools/go.mod
$(GO) list -m -json $(MODULE_DEPS) | go run -modfile=tools/go.mod go.elastic.co/go-licence-detector \
-includeIndirect \
-overrides tools/notice/overrides.json \
-rules tools/notice/rules.json \
-noticeTemplate tools/notice/NOTICE.txt.tmpl \
-noticeOut NOTICE.txt \
-depsTemplate tools/notice/dependencies.csv.tmpl \
-depsOut build/dependencies-$(APM_SERVER_VERSION).csv
##############################################################################
# Rules for creating and installing build tools.
##############################################################################
# PYTHON_EXE may be set in the environment to override the Python binary used
# for creating the virtual environment, or for executing simple scripts that
# do not require a virtual environment.
PYTHON_EXE?=python3
venv: $(PYTHON_BIN)
$(PYTHON): $(PYTHON_BIN)
$(PYTHON_BIN): $(PYTHON_BIN)/activate
$(PYTHON_BIN)/activate:
@$(PYTHON_EXE) -m venv $(PYTHON_VENV_DIR)
@$(PYTHON_BIN)/pip install -U pip wheel
##############################################################################
# Rally -- Elasticsearch performance benchmarking.
##############################################################################
RALLY_EXTRA_FLAGS?=
RALLY_CLIENT_OPTIONS?=basic_auth_user:'admin',basic_auth_password:'changeme'
RALLY_FLAGS?=--pipeline=benchmark-only --client-options="$(RALLY_CLIENT_OPTIONS)" $(RALLY_EXTRA_FLAGS)
RALLY_BULK_SIZE?=5000
RALLY_GENCORPORA_REPLAY_COUNT?=1
.PHONY: rally
rally: $(PYTHON_BIN)/esrally rally/corpora
@$(PYTHON_BIN)/esrally race \
--track-path=rally \
--track-params=expected_cluster_health:yellow,bulk_size:$(RALLY_BULK_SIZE) \
--kill-running-processes \
$(RALLY_FLAGS)
$(PYTHON_BIN)/esrally: $(PYTHON_BIN)
@$(PYTHON_BIN)/pip install -U esrally
.PHONY: rally/corpora
rally/corpora:
@rm -fr rally/corpora && mkdir rally/corpora
@cd systemtest/cmd/gencorpora && $(GO) run . -write-dir $(CURRENT_DIR)/rally/corpora/ -replay-count $(RALLY_GENCORPORA_REPLAY_COUNT)
##############################################################################
# Smoke tests -- Basic smoke tests for APM Server.
##############################################################################
SMOKETEST_VERSIONS ?= latest
SMOKETEST_DIRS = $$(find $(CURRENT_DIR)/testing/smoke -mindepth 1 -maxdepth 1 -type d)
.PHONY: smoketest/discover
smoketest/discover:
@echo "$(SMOKETEST_DIRS)"
.PHONY: smoketest/run
smoketest/run:
@ for version in $(shell echo $(SMOKETEST_VERSIONS) | tr ',' ' '); do \
echo "-> Running $(TEST_DIR) smoke tests for version $${version}..."; \
cd $(TEST_DIR) && ./test.sh $${version}; \
done
.PHONY: smoketest/cleanup
smoketest/cleanup:
@ cd $(TEST_DIR); \
if [ -f "./cleanup.sh" ]; then \
./cleanup.sh; \
fi
.PHONY: smoketest/all
smoketest/all:
@ for test_dir in $(SMOKETEST_DIRS); do \
$(MAKE) smoketest/run TEST_DIR=$${test_dir}; \
done
.PHONY: smoketest/all
smoketest/all/cleanup:
@ for test_dir in $(SMOKETEST_DIRS); do \
echo "-> Cleanup $${test_dir} smoke tests..."; \
$(MAKE) smoketest/cleanup TEST_DIR=$${test_dir}; \
done