-
Notifications
You must be signed in to change notification settings - Fork 525
/
Makefile
338 lines (268 loc) · 12.1 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
##############################################################################
# Variables used for various build targets.
##############################################################################
include go.mk
include packaging.mk
include release.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 $(shell readlink -f $(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-arm64 \
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-%-amd64 build/apm-server-%-amd64.exe: GOARCH=amd64
build/apm-server-%-arm64 build/apm-server-%-arm64.exe: GOARCH=arm64
GOVERSIONINFO_FLAGS := \
-file-version "$(APM_SERVER_VERSION)" \
-product-version "$(APM_SERVER_VERSION)" \
-comment "commit=$(GITCOMMIT)"
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: $(GITREFFILE) packaging/versioninfo.json
go run -modfile=tools/go.mod github.com/josephspurrier/goversioninfo/cmd/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
.PHONY: check-approvals
check-approvals:
@go run -modfile=tools/go.mod github.com/elastic/apm-tools/cmd/check-approvals
check: check-fmt check-headers check-git-diff
.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.
##############################################################################
tidy:
@go mod tidy # make sure go.sum is complete
update: tidy go-generate add-headers notice apm-server.docker.yml docs/spec
apm-server.docker.yml: apm-server.yml
sed -e 's/127.0.0.1:8200/0.0.0.0:8200/' -e 's/localhost:9200/elasticsearch:9200/' $< > $@
.PHONY: go-generate
go-generate:
@cd cmd/intake-receiver && APM_SERVER_VERSION=$(APM_SERVER_VERSION) go generate .
.PHONY: add-headers
add-headers:
ifndef CHECK_HEADERS_DISABLED
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -exclude x-pack
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -license Elasticv2 x-pack
endif
## get-version : Get the apm server version
.PHONY: get-version
get-version:
@echo $(APM_SERVER_VERSION)
# update-go-version updates .go-version, documentation, and build files
# to use the most recent patch version for the major.minor Go version
# defined in go.mod.
.PHONY: update-go-version
update-go-version:
$(GITROOT)/script/update_go_version.sh
##############################################################################
# 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: $(addsuffix /README.md,$(wildcard testing/infra/terraform/modules/*))
testing/infra/terraform/modules/%/README.md: .FORCE
go run -modfile=tools/go.mod github.com/terraform-docs/terraform-docs markdown --hide-empty --header-from header.md --output-file=README.md --output-mode replace $(subst README.md,,$@)
.PHONY: .FORCE
.FORCE:
# Copy docs/spec from apm-data to trigger updates to agents.
#
# TODO in the future we should probably trigger the updates from apm-data,
# and just keep the JSON Schema there.
docs/spec: go.mod
@go mod download github.com/elastic/apm-data
rsync -v --delete --filter='P spec/openapi/' --chmod=Du+rwx,go+rx --chmod=Fu+rw,go+r -r $$(go list -m -f {{.Dir}} github.com/elastic/apm-data)/input/elasticapm/docs/spec ./docs
##############################################################################
# Beats synchronisation.
##############################################################################
BEATS_VERSION?=main
BEATS_MODULE:=github.com/elastic/beats/v7
.PHONY: update-beats
update-beats: update-beats-module tidy notice
@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 $(BEATS_MODULE)@$(BEATS_VERSION) && go mod tidy
##############################################################################
# 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:
go run -modfile=tools/go.mod honnef.co/go/tools/cmd/staticcheck -checks=$(STATICCHECK_CHECKS) ./...
.PHONY: check-headers
check-headers:
ifndef CHECK_HEADERS_DISABLED
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -d -exclude build -exclude x-pack
@go run -modfile=tools/go.mod github.com/elastic/go-licenser -d -exclude build -license Elasticv2 x-pack
endif
.PHONY: check-docker-compose
check-docker-compose:
./script/check_docker_compose.sh $(BEATS_VERSION)
.PHONY: check-gofmt gofmt
check-fmt: check-gofmt
fmt: gofmt
check-gofmt:
@sh script/check_goimports.sh
gofmt: add-headers
@echo "fmt - goimports: Formatting Go code"
@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
mkdir -p build/
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
RALLY_BULK_CLIENTS?=1
.PHONY: rally
rally: $(PYTHON_BIN)/esrally testing/rally/corpora
@$(PYTHON_BIN)/esrally race \
--track-path=testing/rally \
--track-params=expected_cluster_health:yellow,bulk_size:$(RALLY_BULK_SIZE),bulk_clients:$(RALLY_BULK_CLIENTS) \
--kill-running-processes \
$(RALLY_FLAGS)
$(PYTHON_BIN)/esrally: $(PYTHON_BIN)
@$(PYTHON_BIN)/pip install -U esrally
.PHONY: testing/rally/corpora
testing/rally/corpora:
@rm -fr testing/rally/corpora && mkdir testing/rally/corpora
@cd systemtest/cmd/gencorpora && go run . -write-dir $(CURRENT_DIR)/testing/rally/corpora/ -replay-count $(RALLY_GENCORPORA_REPLAY_COUNT)
##############################################################################
# Smoke tests -- Basic smoke tests for APM Server.
##############################################################################
SMOKETEST_VERSIONS ?= latest
# supported-os tests are exclude and hence they are not running as part of this process
# since they are required to run against different versions in a different CI pipeline.
SMOKETEST_DIRS = $$(find $(CURRENT_DIR)/testing/smoke -mindepth 1 -maxdepth 1 -type d | grep -v supported-os | grep -v /managed)
.PHONY: smoketest/discover
smoketest/discover:
@ echo "$(SMOKETEST_DIRS)" | jq -cnR '[inputs | select(length > 0)]'
.PHONY: smoketest/run-version
smoketest/run-version:
@ echo "-> Running $(TEST_DIR) smoke tests for version $${SMOKETEST_VERSION}..."
@ cd $(TEST_DIR) && ./test.sh "$(SMOKETEST_VERSION)"
.PHONY: smoketest/run
smoketest/run:
@ for version in $(shell echo $(SMOKETEST_VERSIONS) | tr ',' ' '); do \
$(MAKE) smoketest/run-version SMOKETEST_VERSION=$${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/cleanup
smoketest/all/cleanup:
@ for test_dir in $(SMOKETEST_DIRS); do \
echo "-> Cleanup $${test_dir} smoke tests..."; \
$(MAKE) smoketest/cleanup TEST_DIR=$${test_dir}; \
done
.PHONY: api-docs
api-docs: ## Generate bundled OpenAPI documents
@npx @redocly/cli bundle "docs/spec/openapi/apm-openapi.yaml" --ext yaml --output "docs/spec/openapi/bundled.yaml"
@npx @redocly/cli bundle "docs/spec/openapi/apm-openapi.yaml" --ext json --output "docs/spec/openapi/bundled.json"
.PHONY: api-docs-lint
api-docs-lint: ## Run spectral API docs linter
@npx @stoplight/spectral-cli lint "docs/spec/openapi/bundled.yaml" --ruleset "docs/spec/openapi/.spectral.yaml"