forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
395 lines (319 loc) · 13.3 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
include ./Makefile.Common
# This is the code that we want to run lint, etc.
ALL_SRC := $(shell find . -name '*.go' \
-not -path './cmd/issuegenerator/*' \
-not -path './cmd/mdatagen/*' \
-not -path './cmd/schemagen/*' \
-not -path './cmd/checkdoc/*' \
-not -path './internal/tools/*' \
-not -path './examples/demo/app/*' \
-not -path './internal/data/protogen/*' \
-not -path './service/internal/zpages/tmplgen/*' \
-type f | sort)
# All source code and documents. Used in spell check.
ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
-type f | sort)
# ALL_MODULES includes ./* dirs (excludes . dir)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' )
CMD?=
TOOLS_MOD_DIR := ./internal/tools
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
BUILD_INFO_IMPORT_PATH=go.opentelemetry.io/collector/internal/version
VERSION=$(shell git describe --match "v[0-9]*" HEAD)
BUILD_INFO=-ldflags "-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION)"
RUN_CONFIG?=examples/local/otel-config.yaml
CONTRIB_PATH=$(CURDIR)/../opentelemetry-collector-contrib
COMP_REL_PATH=service/defaultcomponents/defaults.go
MOD_NAME=go.opentelemetry.io/collector
GO_ACC=go-acc
ADDLICENSE=addlicense
MISSPELL=misspell -error
MISSPELL_CORRECTION=misspell -w
# 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
.DEFAULT_GOAL := all
.PHONY: all
all: checklicense checkdoc misspell goimpi golint gotest otelcol
all-modules:
@echo $(ALL_MODULES) | tr ' ' '\n' | sort
.PHONY: testbed-loadtest
testbed-loadtest: otelcol
cd ./testbed/tests && ./runtests.sh
.PHONY: testbed-correctness-traces
testbed-correctness-traces: otelcol
cd ./testbed/correctness/traces && ./runtests.sh
.PHONY: testbed-correctness-metrics
testbed-correctness-metrics: otelcol
cd ./testbed/correctness/metrics && ./runtests.sh
.PHONY: testbed-list-loadtest
testbed-list-loadtest:
RUN_TESTBED=1 $(GOTEST) -v ./testbed/tests --test.list '.*'| grep "^Test"
.PHONY: gomoddownload
gomoddownload:
@$(MAKE) for-all CMD="go mod download"
.PHONY: gotestinstall
gotestinstall:
@$(MAKE) for-all CMD="make test GOTEST_OPT=\"-i\""
.PHONY: gotest
gotest:
@$(MAKE) for-all CMD="make test"
.PHONY: gobenchmark
gobenchmark:
@$(MAKE) for-all CMD="make benchmark"
.PHONY: gotest-with-cover
gotest-with-cover:
@echo pre-compiling tests
@time $(GOTEST) -i ./...
$(GO_ACC) ./...
go tool cover -html=coverage.txt -o coverage.html
.PHONY: golint
golint:
@$(MAKE) for-all CMD="make lint"
.PHONY: goimpi
goimpi:
@$(MAKE) for-all CMD="make impi"
.PHONY: gofmt
gofmt:
@$(MAKE) for-all CMD="make fmt"
.PHONY: gotidy
gotidy:
$(MAKE) for-all CMD="rm -fr go.sum"
$(MAKE) for-all CMD="go mod tidy"
.PHONY: addlicense
addlicense:
@ADDLICENSEOUT=`$(ADDLICENSE) -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi
.PHONY: checklicense
checklicense:
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
echo "Use 'make addlicense' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi
.PHONY: misspell
misspell:
$(MISSPELL) $(ALL_DOC)
.PHONY: misspell-correction
misspell-correction:
$(MISSPELL_CORRECTION) $(ALL_DOC)
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/client9/misspell/cmd/misspell
cd $(TOOLS_MOD_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && go install github.com/jstemmer/go-junit-report
cd $(TOOLS_MOD_DIR) && go install github.com/mjibson/esc
cd $(TOOLS_MOD_DIR) && go install github.com/ory/go-acc
cd $(TOOLS_MOD_DIR) && go install github.com/pavius/impi/cmd/impi
cd $(TOOLS_MOD_DIR) && go install github.com/tcnksm/ghr
cd $(TOOLS_MOD_DIR) && go install golang.org/x/exp/cmd/apidiff
cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports
cd cmd/mdatagen && go install ./
cd cmd/checkdoc && go install ./
.PHONY: otelcol
otelcol:
go generate ./...
$(MAKE) build-binary-internal
.PHONY: run
run:
GO111MODULE=on go run --race ./cmd/otelcol/... --config ${RUN_CONFIG} ${RUN_ARGS}
.PHONY: docker-component # Not intended to be used directly
docker-component: check-component
GOOS=linux $(MAKE) $(COMPONENT)
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
rm ./cmd/$(COMPONENT)/$(COMPONENT)
.PHONY: for-all
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
.PHONY: check-component
check-component:
ifndef COMPONENT
$(error COMPONENT variable was not defined)
endif
.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 $(ALL_MODULES); 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 upstream ${TAG}
@set -e; for dir in $(ALL_MODULES); do \
(echo Pushing tag "$${dir:2}/$${TAG}" && \
git push upstream "$${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 $(ALL_MODULES); do \
(echo Deleting tag "$${dir:2}/$${TAG}" && \
git tag -d "$${dir:2}/$${TAG}" ); \
done
.PHONY: docker-otelcol
docker-otelcol:
COMPONENT=otelcol $(MAKE) docker-component
# build collector binaries with different OS and Architecture
.PHONY: binaries-all-sys
binaries-all-sys: binaries-darwin_amd64 binaries-darwin_arm64 binaries-linux_amd64 binaries-linux_arm64 binaries-windows_amd64
.PHONY: binaries-darwin_amd64
binaries-darwin_amd64:
GOOS=darwin GOARCH=amd64 $(MAKE) build-binary-internal
.PHONY: binaries-darwin_arm64
binaries-darwin_arm64:
GOOS=darwin GOARCH=arm64 $(MAKE) build-binary-internal
.PHONY: binaries-linux_amd64
binaries-linux_amd64:
GOOS=linux GOARCH=amd64 $(MAKE) build-binary-internal
.PHONY: binaries-linux_arm64
binaries-linux_arm64:
GOOS=linux GOARCH=arm64 $(MAKE) build-binary-internal
.PHONY: binaries-windows_amd64
binaries-windows_amd64:
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) build-binary-internal
.PHONY: build-binary-internal
build-binary-internal:
GO111MODULE=on CGO_ENABLED=0 go build -trimpath -o ./bin/otelcol_$(GOOS)_$(GOARCH)$(EXTENSION) $(BUILD_INFO) ./cmd/otelcol
.PHONY: deb-rpm-package
%-package: ARCH ?= amd64
%-package:
$(MAKE) binaries-linux_$(ARCH)
docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcol-fpm
.PHONY: genmdata
genmdata:
$(MAKE) for-all CMD="go generate ./..."
DEPENDABOT_PATH=".github/dependabot.yml"
.PHONY: internal-gendependabot
internal-gendependabot:
@echo "Add rule for \"${PACKAGE}\" in \"${DIR}\"";
@echo " - package-ecosystem: \"${PACKAGE}\"" >> ${DEPENDABOT_PATH};
@echo " directory: \"${DIR}\"" >> ${DEPENDABOT_PATH};
@echo " schedule:" >> ${DEPENDABOT_PATH};
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH};
.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}
$(MAKE) internal-gendependabot DIR="/" PACKAGE="github-actions"
$(MAKE) internal-gendependabot DIR="/" PACKAGE="docker"
$(MAKE) internal-gendependabot DIR="/" PACKAGE="gomod"
@set -e; for dir in $(ALL_MODULES); do \
$(MAKE) internal-gendependabot DIR=$${dir:1} PACKAGE="gomod"; \
done
# Definitions for ProtoBuf generation.
# The source directory for OTLP ProtoBufs.
OPENTELEMETRY_PROTO_SRC_DIR=internal/data/opentelemetry-proto
# Find all .proto files.
OPENTELEMETRY_PROTO_FILES := $(subst $(OPENTELEMETRY_PROTO_SRC_DIR)/,,$(wildcard $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1/*.proto))
# Target directory to write generated files to.
PROTO_TARGET_GEN_DIR=internal/data/protogen
# Go package name to use for generated files.
PROTO_PACKAGE=go.opentelemetry.io/collector/$(PROTO_TARGET_GEN_DIR)
# Intermediate directory used during generation.
PROTO_INTERMEDIATE_DIR=internal/data/.patched-otlp-proto
DOCKER_PROTOBUF ?= otel/build-protobuf:0.2.1
PROTOC := docker run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD}/$(PROTO_INTERMEDIATE_DIR) ${DOCKER_PROTOBUF} --proto_path=${PWD}
PROTO_INCLUDES := -I/usr/include/github.com/gogo/protobuf -I./
# Generate OTLP Protobuf Go files. This will place generated files in PROTO_TARGET_GEN_DIR.
genproto:
git submodule update --init
# Call a sub-make to ensure OPENTELEMETRY_PROTO_FILES is populated after the submodule
# files are present.
$(MAKE) genproto_sub
$(MAKE) fmt
genproto_sub:
@echo Generating code for the following files:
@$(foreach file,$(OPENTELEMETRY_PROTO_FILES),$(call exec-command,echo $(file)))
@echo Delete intermediate directory.
@rm -rf $(PROTO_INTERMEDIATE_DIR)
@echo Copy .proto file to intermediate directory.
mkdir -p $(PROTO_INTERMEDIATE_DIR)/opentelemetry
cp -R $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/* $(PROTO_INTERMEDIATE_DIR)/opentelemetry
# Patch proto files. See proto_patch.sed for patching rules.
@echo Modify them in the intermediate directory.
$(foreach file,$(OPENTELEMETRY_PROTO_FILES),$(call exec-command,sed -f proto_patch.sed $(OPENTELEMETRY_PROTO_SRC_DIR)/$(file) > $(PROTO_INTERMEDIATE_DIR)/$(file)))
@echo Generate Go code from .proto files in intermediate directory.
$(foreach file,$(OPENTELEMETRY_PROTO_FILES),$(call exec-command,$(PROTOC) $(PROTO_INCLUDES) --gogofaster_out=plugins=grpc:./ $(file)))
@echo Generate gRPC gateway code.
$(PROTOC) $(PROTO_INCLUDES) --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/trace/v1/trace_service_http.yaml:./ opentelemetry/proto/collector/trace/v1/trace_service.proto
$(PROTOC) $(PROTO_INCLUDES) --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/metrics/v1/metrics_service_http.yaml:./ opentelemetry/proto/collector/metrics/v1/metrics_service.proto
$(PROTOC) $(PROTO_INCLUDES) --grpc-gateway_out=logtostderr=true,grpc_api_configuration=opentelemetry/proto/collector/logs/v1/logs_service_http.yaml:./ opentelemetry/proto/collector/logs/v1/logs_service.proto
@echo Move generated code to target directory.
mkdir -p $(PROTO_TARGET_GEN_DIR)
cp -R $(PROTO_INTERMEDIATE_DIR)/$(PROTO_PACKAGE)/* $(PROTO_TARGET_GEN_DIR)/
rm -rf $(PROTO_INTERMEDIATE_DIR)/go.opentelemetry.io
@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/*
@rm -rf $(OPENTELEMETRY_PROTO_SRC_DIR)/.* > /dev/null 2>&1 || true
# Generate structs, functions and tests for pdata package. Must be used after any changes
# to proto and after running `make genproto`
genpdata:
go run cmd/pdatagen/main.go
$(MAKE) fmt
# Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles
# against the current version of this repo.
.PHONY: check-contrib
check-contrib:
@echo Setting contrib at $(CONTRIB_PATH) to use this core checkout
make -C $(CONTRIB_PATH) for-all CMD="go mod edit -replace go.opentelemetry.io/collector=$(CURDIR)"
make -C $(CONTRIB_PATH) gotidy
make -C $(CONTRIB_PATH) test
@echo Restoring contrib to no longer use this core checkout
make -C $(CONTRIB_PATH) for-all CMD="go mod edit -dropreplace go.opentelemetry.io/collector"
# List of directories where certificates are stored for unit tests.
CERT_DIRS := config/configgrpc/testdata \
config/confighttp/testdata \
receiver/jaegerreceiver/testdata \
exporter/jaegerexporter/testdata
# 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)))
# Generate certificates for unit tests relying on certificates without copying certs to specific test directories.
.PHONY: certs-dryrun
certs-dryrun:
@internal/buildscripts/gen-certs.sh -d
# Verify existence of READMEs for components specified as default components in the collector.
.PHONY: checkdoc
checkdoc:
go run cmd/checkdoc/main.go cmd/checkdoc/docs.go --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME)
# Construct new API state snapshots
.PHONY: apidiff-build
apidiff-build:
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/gen-apidiff.sh -p $(pkg)))
# Compare API state snapshots
.PHONY: apidiff-compare
apidiff-compare:
@$(foreach pkg,$(ALL_PKGS),$(call exec-command,./internal/buildscripts/compare-apidiff.sh -p $(pkg)))