-
Notifications
You must be signed in to change notification settings - Fork 527
/
Copy pathMakefile
295 lines (235 loc) · 11 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
##############################################################################
# Variables used for various build targets.
##############################################################################
GOOSBUILD=./build/$(shell go env GOOS)
APPROVALS=$(GOOSBUILD)/approvals
GOIMPORTS=$(GOOSBUILD)/goimports
GOLICENSER=$(GOOSBUILD)/go-licenser
GOLINT=$(GOOSBUILD)/golint
MAGE=$(GOOSBUILD)/mage
REVIEWDOG=$(GOOSBUILD)/reviewdog
STATICCHECK=$(GOOSBUILD)/staticcheck
PYTHON_ENV?=.
PYTHON_BIN=$(PYTHON_ENV)/build/ve/$(shell go env GOOS)/bin
PYTHON=$(PYTHON_BIN)/python
# Create a local config.mk file to override configuration,
# e.g. for setting "GOLINT_UPSTREAM".
-include config.mk
##############################################################################
# Rules for building and unit-testing apm-server.
##############################################################################
.DEFAULT_GOAL := apm-server
.PHONY: apm-server
apm-server:
go build
.PHONY: apm-server.test
apm-server.test:
go test -c -coverpkg=github.com/elastic/apm-server/...
.PHONY: apm-server.x-pack x-pack/apm-server/apm-server
apm-server.x-pack: x-pack/apm-server/apm-server
x-pack/apm-server/apm-server:
@go build -o $@ ./x-pack/apm-server
.PHONY: test
test:
go test -v ./...
.PHONY:
clean: $(MAGE)
@$(MAGE) clean
##############################################################################
# Checks/tests.
##############################################################################
# SYSTEM_TEST_TARGET is passed to nosetests in "system-tests".
#
# This may be overridden to specify which tests to run.
SYSTEM_TEST_TARGET?=./tests/system
# NOSETESTS_OPTIONS is passed to nosetests in "system-tests".
NOSETESTS_OPTIONS?=--process-timeout=90 --with-timer -v --with-xunit --xunit-file=build/TEST-system.xml
.PHONY: check-full
check-full: update check golint staticcheck
.PHONY: check-approvals
check-approvals: $(APPROVALS)
@$(APPROVALS)
.PHONY: check
check: $(MAGE) check-headers
@$(MAGE) check
.PHONY: bench
bench:
@go test -benchmem -run=XXX -benchtime=100ms -bench='.*' ./...
.PHONY: system-tests
system-tests: $(PYTHON_BIN) apm-server.test
INTEGRATION_TESTS=1 TZ=UTC $(PYTHON_BIN)/nosetests $(NOSETESTS_OPTIONS) $(SYSTEM_TEST_TARGET)
.PHONY: docker-system-tests
docker-system-tests: docker-compose.override.yml
docker-compose build
docker-compose run --rm -T beat make system-tests
# docker-compose.override.yml holds overrides for docker-compose.yml.
#
# Create this to ensure the UID used inside docker-compose is the same
# as the current user on the host, so files are created with the same
# privileges.
#
# Note that this target is intentionally non-.PHONY, so that users can
# modify the resulting file without it being overwritten. To recreate
# the file, remove it.
docker-compose.override.yml:
printf "version: '2.3'\nservices:\n beat:\n build:\n args: [UID=%d]" $(shell id -u) > $@
##############################################################################
# Rules for updating config files, fields.yml, etc.
##############################################################################
update: fields go-generate add-headers docs_data notice $(MAGE)
@$(MAGE) update
fields: include/fields.go fields.yml
include/fields.go fields.yml: $(MAGE) magefile.go _meta/fields.common.yml $(shell find model -name fields.yml)
@$(MAGE) fields
config: apm-server.yml apm-server.docker.yml
apm-server.yml apm-server.docker.yml: $(MAGE) magefile.go _meta/beat.yml
@$(MAGE) config
.PHONY: go-generate
go-generate:
@go generate
notice: NOTICE.txt
NOTICE.txt: $(PYTHON) vendor/vendor.json build/notice_overrides.json
@$(PYTHON) _beats/dev-tools/generate_notice.py . -e '_beats' -s "./vendor/github.com/elastic/beats" -b "Apm Server" --beats-origin build/notice_overrides.json
build/notice_overrides.json: $(PYTHON) _beats/vendor/vendor.json
mkdir -p build
$(PYTHON) script/generate_notice_overrides.py -o $@
.PHONY: add-headers
add-headers: $(GOLICENSER)
ifndef CHECK_HEADERS_DISABLED
@$(GOLICENSER) -exclude x-pack
@$(GOLICENSER) -license Elastic x-pack
endif
##############################################################################
# Documentation.
##############################################################################
.PHONY: docs
docs: $(docs_data_files)
@rm -rf build/html_docs
sh script/build_apm_docs.sh apm-server docs/index.asciidoc build
.PHONY: update-beats-docs
update-beats-docs: $(PYTHON)
@$(PYTHON) script/copy-docs.py
docs_data_files=\
docs/data/intake-api/generated/events.ndjson \
docs/data/intake-api/generated/rum_v3_events.ndjson \
docs/data/intake-api/generated/sourcemap/bundle.js.map \
docs/data/elasticsearch/generated/errors.json \
docs/data/elasticsearch/generated/spans.json \
docs/data/elasticsearch/generated/transactions.json \
docs/data/elasticsearch/generated/metricsets.json \
docs/data/elasticsearch/generated/rum_v3_transactions.json \
docs/data/elasticsearch/generated/rum_v3_errors.json
docs_data: $(docs_data_files)
$(docs_data_files):
install -D -m 0644 $^ $@
docs/data/intake-api/generated/events.ndjson: testdata/intake-v2/events.ndjson
docs/data/intake-api/generated/rum_v3_events.ndjson: testdata/intake-v3/rum_events.ndjson
docs/data/intake-api/generated/sourcemap/bundle.js.map: testdata/sourcemap/bundle.js.map
docs/data/elasticsearch/generated/errors.json: processor/stream/test_approved_es_documents/testIntakeIntegrationErrors.approved.json
docs/data/elasticsearch/generated/spans.json: processor/stream/test_approved_es_documents/testIntakeIntegrationSpans.approved.json
docs/data/elasticsearch/generated/transactions.json: processor/stream/test_approved_es_documents/testIntakeIntegrationTransactions.approved.json
docs/data/elasticsearch/generated/metricsets.json: processor/stream/test_approved_es_documents/testIntakeIntegrationMetricsets.approved.json
docs/data/elasticsearch/generated/rum_v3_transactions.json: processor/stream/test_approved_es_documents/testIntakeRUMV3Transactions.approved.json
docs/data/elasticsearch/generated/rum_v3_errors.json: processor/stream/test_approved_es_documents/testIntakeRUMV3Errors.approved.json
##############################################################################
# Beats synchronisation.
##############################################################################
BEATS_VERSION?=master
.PHONY: is-beats-updated
is-beats-updated: $(PYTHON)
@$(PYTHON) ./script/is_beats_updated.py ${BEATS_VERSION}
.PHONY: update-beats
update-beats: vendor-beats update
@echo --- Use this commit message: Update beats framework to `cat vendor/vendor.json | python -c 'import sys, json;print([p["revision"] for p in json.load(sys.stdin)["package"] if p["path"] == "github.com/elastic/beats/libbeat/beat"][0][:7])'`
.PHONY: vendor-beats
vendor-beats:
rm -rf vendor/github.com/elastic/beats
govendor fetch github.com/elastic/beats/...@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/libbeat/generator/fields@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/libbeat/kibana@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/libbeat/outputs/transport/transptest@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/libbeat/scripts/cmd/global_fields@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/licenses@$(BEATS_VERSION)
govendor fetch github.com/elastic/beats/x-pack/libbeat/cmd@$(BEATS_VERSION)
@BEATS_VERSION=$(BEATS_VERSION) script/update_beats.sh
@find vendor/github.com/elastic/beats -type d -empty -delete
##############################################################################
# Kibana synchronisation.
##############################################################################
.PHONY: are-kibana-objects-updated
are-kibana-objects-updated: $(PYTHON) build/index-pattern.json
@$(PYTHON) ./script/are_kibana_saved_objects_updated.py --branch ${BEATS_VERSION} build/index-pattern.json
build/index-pattern.json: $(PYTHON) apm-server
@./apm-server --strict.perms=false export index-pattern > $@
##############################################################################
# Linting, style-checking, license header checks, etc.
##############################################################################
GOLINT_TARGETS?=$(shell go list ./...)
GOLINT_UPSTREAM?=origin/master
REVIEWDOG_FLAGS?=-conf=_beats/reviewdog.yml -f=golint -diff="git diff $(GOLINT_UPSTREAM)"
GOLINT_COMMAND=$(shell $(GOLINT) ${GOLINT_TARGETS} | grep -v "should have comment" | $(REVIEWDOG) $(REVIEWDOG_FLAGS))
.PHONY: golint
golint: $(GOLINT) $(REVIEWDOG)
@test -z "$(GOLINT_COMMAND)" || (echo "$(GOLINT_COMMAND)" && exit 1)
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) github.com/elastic/apm-server/...
.PHONY: check-changelogs
check-changelogs: $(PYTHON)
$(PYTHON) script/check_changelogs.py
.PHONY: check-headers
check-headers: $(GOLICENSER)
ifndef CHECK_HEADERS_DISABLED
@$(GOLICENSER) -d -exclude build -exclude x-pack
@$(GOLICENSER) -d -exclude build -license Elastic x-pack
endif
# TODO(axw) once we move to modules, start using "mage fmt" instead.
.PHONY: gofmt autopep8
fmt: gofmt autopep8
gofmt: $(GOIMPORTS) add-headers
@echo "fmt - goimports: Formatting Go code"
@$(GOIMPORTS) -local github.com/elastic -l -w \
$(shell find . -type f -name '*.go' -not -path "*/vendor/*" 2>/dev/null)
autopep8: $(MAGE)
@$(MAGE) pythonAutopep8
##############################################################################
# Rules for creating and installing build tools.
##############################################################################
# $GOBIN must be set to use "go get" below. Once we move to modules we
# can just use "go build" and it'll resolve all dependencies using modules.
export GOBIN=$(abspath $(GOOSBUILD))
$(MAGE): magefile.go vendor/vendor.json
go run ./vendor/github.com/magefile/mage -compile=$@
$(STATICCHECK): vendor/vendor.json
go get ./vendor/honnef.co/go/tools/cmd/staticcheck
$(GOLINT): vendor/vendor.json
go get ./vendor/golang.org/x/lint/golint
$(GOIMPORTS): vendor/vendor.json
go get ./vendor/golang.org/x/tools/cmd/goimports
$(GOLICENSER):
# go-licenser is not vendored, so we install it from network here.
go get -u github.com/elastic/go-licenser
$(REVIEWDOG): vendor/vendor.json
go get ./vendor/github.com/reviewdog/reviewdog/cmd/reviewdog
$(PYTHON): $(PYTHON_BIN)
$(PYTHON_BIN): $(PYTHON_BIN)/activate
$(PYTHON_BIN)/activate: _beats/libbeat/tests/system/requirements.txt $(MAGE)
@$(MAGE) pythonEnv
.PHONY: $(APPROVALS)
$(APPROVALS):
@go build -o $@ tests/scripts/approvals.go
##############################################################################
# Release manager.
##############################################################################
# Builds a snapshot release. The Go version defined in .go-version will be
# installed and used for the build.
release-manager-snapshot: export SNAPSHOT=true
release-manager-snapshot: release-manager-release
# Builds a snapshot release. The Go version defined in .go-version will be
# installed and used for the build.
.PHONY: release-manager-release
release-manager-release:
_beats/dev-tools/run_with_go_ver $(MAKE) release
.PHONY: release
release: $(MAGE)
$(MAGE) package