forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
418 lines (344 loc) · 14.4 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
include ./Makefile.Common
RUN_CONFIG?=local/config.yaml
CMD?=
OTEL_VERSION=main
BUILD_INFO_IMPORT_PATH=github.com/open-telemetry/opentelemetry-collector-contrib/internal/otelcontribcore/internal/version
VERSION=$(shell git describe --always --match "v[0-9]*" HEAD)
BUILD_INFO=-ldflags "-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION)"
COMP_REL_PATH=internal/components/components.go
MOD_NAME=github.com/open-telemetry/opentelemetry-collector-contrib
GROUP ?= all
FOR_GROUP_TARGET=for-$(GROUP)-target
FIND_MOD_ARGS=-type f -name "go.mod"
TO_MOD_DIR=dirname {} \; | sort | egrep '^./'
EX_COMPONENTS=-not -path "./receiver/*" -not -path "./processor/*" -not -path "./exporter/*" -not -path "./extension/*"
EX_INTERNAL=-not -path "./internal/*"
# NONROOT_MODS includes ./* dirs (excludes . dir)
NONROOT_MODS := $(shell find . $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
RECEIVER_MODS_0 := $(shell find ./receiver/[a-k]* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
RECEIVER_MODS_1 := $(shell find ./receiver/[l-z]* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
RECEIVER_MODS := $(RECEIVER_MODS_0) $(RECEIVER_MODS_1)
PROCESSOR_MODS := $(shell find ./processor/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
EXPORTER_MODS := $(shell find ./exporter/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
EXTENSION_MODS := $(shell find ./extension/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
INTERNAL_MODS := $(shell find ./internal/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
OTHER_MODS := $(shell find . $(EX_COMPONENTS) $(EX_INTERNAL) $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) ) $(PWD)
ALL_MODS := $(RECEIVER_MODS) $(PROCESSOR_MODS) $(EXPORTER_MODS) $(EXTENSION_MODS) $(INTERNAL_MODS) $(OTHER_MODS)
# find -exec dirname cannot be used to process multiple matching patterns
FIND_INTEGRATION_TEST_MODS={ find . -type f -name "*integration_test.go" & find . -type f -name "*e2e_test.go" -not -path "./testbed/*"; }
INTEGRATION_MODS := $(shell $(FIND_INTEGRATION_TEST_MODS) | uniq | xargs $(TO_MOD_DIR) )
ifeq ($(GOOS),windows)
EXTENSION := .exe
endif
.DEFAULT_GOAL := all
all-modules:
@echo $(NONROOT_MODS) | tr ' ' '\n' | sort
all-groups:
@echo "receiver-0: $(RECEIVER_MODS_0)"
@echo "\nreceiver-1: $(RECEIVER_MODS_1)"
@echo "\nreceiver: $(RECEIVER_MODS)"
@echo "\nprocessor: $(PROCESSOR_MODS)"
@echo "\nexporter: $(EXPORTER_MODS)"
@echo "\nextension: $(EXTENSION_MODS)"
@echo "\ninternal: $(INTERNAL_MODS)"
@echo "\nother: $(OTHER_MODS)"
.PHONY: all
all: install-tools all-common gotest otelcontribcol otelcontribcol-unstable
.PHONY: all-common
all-common:
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="common"
.PHONY: e2e-test
e2e-test: otelcontribcol otelcontribcol-unstable otelcontribcol-testbed
$(MAKE) -C testbed run-tests
.PHONY: unit-tests-with-cover
unit-tests-with-cover:
@echo Verifying that all packages have test files to count in coverage
@internal/buildscripts/check-test-files.sh $(subst github.com/open-telemetry/opentelemetry-collector-contrib/,./,$(ALL_PKGS))
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="do-unit-tests-with-cover"
TARGET="do-integration-tests-with-cover"
.PHONY: integration-tests-with-cover
integration-tests-with-cover: $(INTEGRATION_MODS)
# Long-running e2e tests
.PHONY: stability-tests
stability-tests: otelcontribcol
@echo Stability tests are disabled until we have a stable performance environment.
@echo To enable the tests replace this echo by $(MAKE) -C testbed run-stability-tests
.PHONY: gotidy
gotidy:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="tidy"
.PHONY: gomoddownload
gomoddownload:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="moddownload"
.PHONY: gotest
gotest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="test"
.PHONY: gofmt
gofmt:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="fmt"
.PHONY: golint
golint:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="lint"
.PHONY: goimpi
goimpi:
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="impi"
.PHONY: goporto
goporto:
porto -w --include-internal --skip-dirs "^cmd$$" ./
.PHONY: for-all
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(NONROOT_MODS); do \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
.PHONY: add-tag
add-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Adding tag ${TAG}"
@git tag -a ${TAG} -s -m "Version ${TAG}"
@set -e; for dir in $(NONROOT_MODS); do \
(echo Adding tag "$${dir:2}/$${TAG}" && \
git tag -a "$${dir:2}/$${TAG}" -s -m "Version ${dir:2}/${TAG}" ); \
done
.PHONY: push-tag
push-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Pushing tag ${TAG}"
@git push [email protected]:open-telemetry/opentelemetry-collector-contrib.git ${TAG}
@set -e; for dir in $(NONROOT_MODS); do \
(echo Pushing tag "$${dir:2}/$${TAG}" && \
git push [email protected]:open-telemetry/opentelemetry-collector-contrib.git "$${dir:2}/$${TAG}"); \
done
.PHONY: delete-tag
delete-tag:
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
@echo "Deleting tag ${TAG}"
@git tag -d ${TAG}
@set -e; for dir in $(NONROOT_MODS); do \
(echo Deleting tag "$${dir:2}/$${TAG}" && \
git tag -d "$${dir:2}/$${TAG}" ); \
done
DEPENDABOT_PATH=".github/dependabot.yml"
.PHONY: gendependabot
gendependabot:
@echo "Recreating ${DEPENDABOT_PATH} file"
@echo "# File generated by \"make gendependabot\"; DO NOT EDIT." > ${DEPENDABOT_PATH}
@echo "" >> ${DEPENDABOT_PATH}
@echo "version: 2" >> ${DEPENDABOT_PATH}
@echo "updates:" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\" github-actions"
@echo " - package-ecosystem: \"github-actions\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\" docker"
@echo " - package-ecosystem: \"docker\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\" gomod"
@echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@set -e; for dir in $(NONROOT_MODS); do \
echo "Add entry for \"$${dir:1}\""; \
echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}; \
echo " directory: \"$${dir:1}\"" >> ${DEPENDABOT_PATH}; \
echo " schedule:" >> ${DEPENDABOT_PATH}; \
echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}; \
done
# Define a delegation target for each module
.PHONY: $(ALL_MODS)
$(ALL_MODS):
@echo "Running target '$(TARGET)' in module '$@' as part of group '$(GROUP)'"
$(MAKE) -C $@ $(TARGET)
# Trigger each module's delegation target
.PHONY: for-all-target
for-all-target: $(ALL_MODS)
.PHONY: for-receiver-target
for-receiver-target: $(RECEIVER_MODS)
.PHONY: for-receiver-0-target
for-receiver-0-target: $(RECEIVER_MODS_0)
.PHONY: for-receiver-1-target
for-receiver-1-target: $(RECEIVER_MODS_1)
.PHONY: for-processor-target
for-processor-target: $(PROCESSOR_MODS)
.PHONY: for-exporter-target
for-exporter-target: $(EXPORTER_MODS)
.PHONY: for-extension-target
for-extension-target: $(EXTENSION_MODS)
.PHONY: for-internal-target
for-internal-target: $(INTERNAL_MODS)
.PHONY: for-other-target
for-other-target: $(OTHER_MODS)
# Debugging target, which helps to quickly determine whether for-all-target is working or not.
.PHONY: all-pwd
all-pwd:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="pwd"
TOOLS_MOD_DIR := ./internal/tools
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/client9/misspell/cmd/misspell
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/jstemmer/go-junit-report
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/pavius/impi/cmd/impi
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/tcnksm/ghr
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/checkdoc
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/issuegenerator
cd $(TOOLS_MOD_DIR) && $(GOCMD) install golang.org/x/tools/cmd/goimports
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/multimod
cd $(TOOLS_MOD_DIR) && $(GOCMD) install github.com/jcchavezs/porto/cmd/porto
cd $(TOOLS_MOD_DIR) && $(GOCMD) install go.opentelemetry.io/build-tools/crosslink
.PHONY: run
run:
GO111MODULE=on $(GOCMD) run --race ./cmd/otelcontribcol/... --config ${RUN_CONFIG} ${RUN_ARGS}
.PHONY: docker-component # Not intended to be used directly
docker-component: check-component
GOOS=linux GOARCH=amd64 $(MAKE) $(COMPONENT)
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
rm ./cmd/$(COMPONENT)/$(COMPONENT)
.PHONY: check-component
check-component:
ifndef COMPONENT
$(error COMPONENT variable was not defined)
endif
.PHONY: docker-otelcontribcol
docker-otelcontribcol:
COMPONENT=otelcontribcol $(MAKE) docker-component
.PHONY: generate
generate:
cd cmd/mdatagen && $(GOCMD) install .
$(MAKE) for-all CMD="$(GOCMD) generate ./..."
.PHONY: chlog-install
chlog-install:
cd cmd/chloggen && $(GOCMD) install .
FILENAME?=$(shell git branch --show-current)
.PHONY: chlog-new
chlog-new: chlog-install
chloggen new -filename $(FILENAME)
.PHONY: chlog-validate
chlog-validate: chlog-install
chloggen validate
.PHONY: chlog-preview
chlog-preview: chlog-install
chloggen update -dry
.PHONY: chlog-update
chlog-update: chlog-install
chloggen update -version $(VERSION)
# Build the Collector executable.
.PHONY: otelcontribcol
otelcontribcol:
GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ./bin/otelcontribcol_$(GOOS)_$(GOARCH)$(EXTENSION) \
$(BUILD_INFO) -tags $(GO_BUILD_TAGS) ./cmd/otelcontribcol
# Build the Collector executable, including unstable functionality.
.PHONY: otelcontribcol-unstable
otelcontribcol-unstable:
GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ./bin/otelcontribcol_unstable_$(GOOS)_$(GOARCH)$(EXTENSION) \
$(BUILD_INFO) -tags $(GO_BUILD_TAGS),enable_unstable ./cmd/otelcontribcol
# Build the Collector executable, with only components used in testbed.
.PHONY: otelcontribcol-testbed
otelcontribcol-testbed:
GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ./bin/otelcontribcol_testbed_$(GOOS)_$(GOARCH)$(EXTENSION) \
$(BUILD_INFO) -tags $(GO_BUILD_TAGS),testbed ./cmd/otelcontribcol
.PHONY: update-dep
update-dep:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="updatedep"
$(MAKE) otelcontribcol
.PHONY: update-otel
update-otel:
$(MAKE) update-dep MODULE=go.opentelemetry.io/collector VERSION=$(OTEL_VERSION)
.PHONY: otel-from-tree
otel-from-tree:
# This command allows you to make changes to your local checkout of otel core and build
# contrib against those changes without having to push to github and update a bunch of
# references. The workflow is:
#
# 1. Hack on changes in core (assumed to be checked out in ../opentelemetry-collector from this directory)
# 2. Run `make otel-from-tree` (only need to run it once to remap go modules)
# 3. You can now build contrib and it will use your local otel core changes.
# 4. Before committing/pushing your contrib changes, undo by running `make otel-from-lib`.
$(MAKE) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector=$(SRC_ROOT)/../opentelemetry-collector"
.PHONY: otel-from-lib
otel-from-lib:
# Sets opentelemetry core to be not be pulled from local source tree. (Undoes otel-from-tree.)
$(MAKE) for-all CMD="$(GOCMD) mod edit -dropreplace go.opentelemetry.io/collector"
.PHONY: build-examples
build-examples:
docker-compose -f examples/tracing/docker-compose.yml build
docker-compose -f exporter/splunkhecexporter/example/docker-compose.yml build
.PHONY: deb-rpm-package
%-package: ARCH ?= amd64
%-package:
GOOS=linux GOARCH=$(ARCH) $(MAKE) otelcontribcol
docker build -t otelcontribcol-fpm internal/buildscripts/packaging/fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcontribcol-fpm
# Verify existence of READMEs for components specified as default components in the collector.
.PHONY: checkdoc
checkdoc:
checkdoc --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME)
.PHONY: all-checklinks
all-checklinks:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="checklinks"
# Function to execute a command. Note the empty line before endef to make sure each command
# gets executed separately instead of concatenated with previous one.
# Accepts command to execute as first parameter.
define exec-command
$(1)
endef
# List of directories where certificates are stored for unit tests.
CERT_DIRS := receiver/sapmreceiver/testdata \
receiver/signalfxreceiver/testdata \
receiver/splunkhecreceiver/testdata \
receiver/mongodbatlasreceiver/testdata/alerts/cert \
receiver/mongodbreceiver/testdata/certs
# Generate certificates for unit tests relying on certificates.
.PHONY: certs
certs:
$(foreach dir, $(CERT_DIRS), $(call exec-command, @internal/buildscripts/gen-certs.sh -o $(dir)))
.PHONY: multimod-verify
multimod-verify: install-tools
@echo "Validating versions.yaml"
multimod verify
.PHONY: multimod-prerelease
multimod-prerelease: install-tools
multimod prerelease -v ./versions.yaml -m contrib-base
.PHONY: crosslink
crosslink: install-tools
@echo "Executing crosslink"
crosslink --root=$(shell pwd)
.PHONY: clean
clean:
@echo "Removing coverage files"
find . -type f -name 'coverage.txt' -delete
find . -type f -name 'coverage.html' -delete
find . -type f -name 'integration-coverage.txt' -delete
find . -type f -name 'integration-coverage.html' -delete
.PHONY: genconfigdocs
genconfigdocs:
cd cmd/configschema && $(GOCMD) run ./docsgen all
.PHONY: generate-all-labels
generate-all-labels:
$(MAKE) generate-labels TYPE="cmd" COLOR="#483C32"
$(MAKE) generate-labels TYPE="pkg" COLOR="#F9DE22"
$(MAKE) generate-labels TYPE="extension" COLOR="#FF794D"
$(MAKE) generate-labels TYPE="receiver" COLOR="#E91B7B"
$(MAKE) generate-labels TYPE="processor" COLOR="#800080"
$(MAKE) generate-labels TYPE="exporter" COLOR="#50C878"
.PHONY: generate-labels
generate-labels:
if [ -z $${TYPE+x} ] || [ -z $${COLOR+x} ]; then \
echo "Must provide a TYPE and COLOR"; \
exit 1; \
fi; \
echo "Generating labels for $${TYPE}" ; \
COMPONENTS=$$(find ./$${TYPE} -type d -maxdepth 1 -mindepth 1 -exec basename \{\} \;); \
for comp in $${COMPONENTS}; do \
NAME=$${comp//"$${TYPE}"}; \
gh label create "$${TYPE}/$${NAME}" -c "$${COLOR}"; \
done; \
exit 0