Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. include ./Makefile.Common
  2. RUN_CONFIG?=local/config.yaml
  3. CMD?=
  4. OTEL_VERSION=main
  5. OTEL_RC_VERSION=main
  6. OTEL_STABLE_VERSION=main
  7. VERSION=$(shell git describe --always --match "v[0-9]*" HEAD)
  8. COMP_REL_PATH=cmd/otelcontribcol/components.go
  9. MOD_NAME=github.com/open-telemetry/opentelemetry-collector-contrib
  10. GROUP ?= all
  11. FOR_GROUP_TARGET=for-$(GROUP)-target
  12. FIND_MOD_ARGS=-type f -name "go.mod"
  13. TO_MOD_DIR=dirname {} \; | sort | grep -E '^./'
  14. EX_COMPONENTS=-not -path "./receiver/*" -not -path "./processor/*" -not -path "./exporter/*" -not -path "./extension/*" -not -path "./connector/*"
  15. EX_INTERNAL=-not -path "./internal/*"
  16. EX_PKG=-not -path "./pkg/*"
  17. EX_CMD=-not -path "./cmd/*"
  18. # NONROOT_MODS includes ./* dirs (excludes . dir)
  19. NONROOT_MODS := $(shell find . $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  20. RECEIVER_MODS_0 := $(shell find ./receiver/[a-k]* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  21. RECEIVER_MODS_1 := $(shell find ./receiver/[l-z]* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  22. RECEIVER_MODS := $(RECEIVER_MODS_0) $(RECEIVER_MODS_1)
  23. PROCESSOR_MODS := $(shell find ./processor/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  24. EXPORTER_MODS := $(shell find ./exporter/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  25. EXTENSION_MODS := $(shell find ./extension/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  26. CONNECTOR_MODS := $(shell find ./connector/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  27. INTERNAL_MODS := $(shell find ./internal/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  28. PKG_MODS := $(shell find ./pkg/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  29. CMD_MODS := $(shell find ./cmd/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
  30. OTHER_MODS := $(shell find . $(EX_COMPONENTS) $(EX_INTERNAL) $(EX_PKG) $(EX_CMD) $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) ) $(PWD)
  31. ALL_MODS := $(RECEIVER_MODS) $(PROCESSOR_MODS) $(EXPORTER_MODS) $(EXTENSION_MODS) $(CONNECTOR_MODS) $(INTERNAL_MODS) $(PKG_MODS) $(CMD_MODS) $(OTHER_MODS)
  32. # find -exec dirname cannot be used to process multiple matching patterns
  33. FIND_INTEGRATION_TEST_MODS={ find . -type f -name "*integration_test.go" & find . -type f -name "*e2e_test.go" -not -path "./testbed/*"; }
  34. INTEGRATION_MODS := $(shell $(FIND_INTEGRATION_TEST_MODS) | xargs $(TO_MOD_DIR) | uniq)
  35. ifeq ($(GOOS),windows)
  36. EXTENSION := .exe
  37. endif
  38. .DEFAULT_GOAL := all
  39. all-modules:
  40. @echo $(NONROOT_MODS) | tr ' ' '\n' | sort
  41. all-groups:
  42. @echo "receiver-0: $(RECEIVER_MODS_0)"
  43. @echo "\nreceiver-1: $(RECEIVER_MODS_1)"
  44. @echo "\nreceiver: $(RECEIVER_MODS)"
  45. @echo "\nprocessor: $(PROCESSOR_MODS)"
  46. @echo "\nexporter: $(EXPORTER_MODS)"
  47. @echo "\nextension: $(EXTENSION_MODS)"
  48. @echo "\nconnector: $(CONNECTOR_MODS)"
  49. @echo "\ninternal: $(INTERNAL_MODS)"
  50. @echo "\npkg: $(PKG_MODS)"
  51. @echo "\ncmd: $(CMD_MODS)"
  52. @echo "\nother: $(OTHER_MODS)"
  53. .PHONY: all
  54. all: install-tools all-common goporto multimod-verify gotest otelcontribcol
  55. .PHONY: all-common
  56. all-common:
  57. @$(MAKE) $(FOR_GROUP_TARGET) TARGET="common"
  58. .PHONY: e2e-test
  59. e2e-test: otelcontribcol oteltestbedcol
  60. $(MAKE) -C testbed run-tests
  61. .PHONY: integration-test
  62. integration-test:
  63. @$(MAKE) for-integration-target TARGET="mod-integration-test"
  64. .PHONY: integration-tests-with-cover
  65. integration-tests-with-cover:
  66. @$(MAKE) for-integration-target TARGET="do-integration-tests-with-cover"
  67. # Long-running e2e tests
  68. .PHONY: stability-tests
  69. stability-tests: otelcontribcol
  70. @echo Stability tests are disabled until we have a stable performance environment.
  71. @echo To enable the tests replace this echo by $(MAKE) -C testbed run-stability-tests
  72. .PHONY: gogci
  73. gogci:
  74. $(MAKE) $(FOR_GROUP_TARGET) TARGET="gci"
  75. .PHONY: gotidy
  76. gotidy:
  77. $(MAKE) $(FOR_GROUP_TARGET) TARGET="tidy"
  78. .PHONY: gomoddownload
  79. gomoddownload:
  80. $(MAKE) $(FOR_GROUP_TARGET) TARGET="moddownload"
  81. .PHONY: gotest
  82. gotest:
  83. $(MAKE) $(FOR_GROUP_TARGET) TARGET="test"
  84. .PHONY: gotest-with-cover
  85. gotest-with-cover:
  86. @$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover"
  87. $(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt
  88. .PHONY: gofmt
  89. gofmt:
  90. $(MAKE) $(FOR_GROUP_TARGET) TARGET="fmt"
  91. .PHONY: golint
  92. golint:
  93. $(MAKE) $(FOR_GROUP_TARGET) TARGET="lint"
  94. .PHONY: gogovulncheck
  95. gogovulncheck:
  96. $(MAKE) $(FOR_GROUP_TARGET) TARGET="govulncheck"
  97. .PHONY: goporto
  98. goporto: $(PORTO)
  99. $(PORTO) -w --include-internal --skip-dirs "^cmd$$" ./
  100. .PHONY: for-all
  101. for-all:
  102. @echo "running $${CMD} in root"
  103. @$${CMD}
  104. @set -e; for dir in $(NONROOT_MODS); do \
  105. (cd "$${dir}" && \
  106. echo "running $${CMD} in $${dir}" && \
  107. $${CMD} ); \
  108. done
  109. COMMIT?=HEAD
  110. MODSET?=contrib-core
  111. REMOTE?=git@github.com:open-telemetry/opentelemetry-collector-contrib.git
  112. .PHONY: push-tags
  113. push-tags: $(MULTIMOD)
  114. $(MULTIMOD) verify
  115. set -e; for tag in `$(MULTIMOD) tag -m ${MODSET} -c ${COMMIT} --print-tags | grep -v "Using" `; do \
  116. echo "pushing tag $${tag}"; \
  117. git push ${REMOTE} $${tag}; \
  118. done;
  119. # Define a delegation target for each module
  120. .PHONY: $(ALL_MODS)
  121. $(ALL_MODS):
  122. @echo "Running target '$(TARGET)' in module '$@' as part of group '$(GROUP)'"
  123. $(MAKE) -C $@ $(TARGET)
  124. # Trigger each module's delegation target
  125. .PHONY: for-all-target
  126. for-all-target: $(ALL_MODS)
  127. .PHONY: for-receiver-target
  128. for-receiver-target: $(RECEIVER_MODS)
  129. .PHONY: for-receiver-0-target
  130. for-receiver-0-target: $(RECEIVER_MODS_0)
  131. .PHONY: for-receiver-1-target
  132. for-receiver-1-target: $(RECEIVER_MODS_1)
  133. .PHONY: for-processor-target
  134. for-processor-target: $(PROCESSOR_MODS)
  135. .PHONY: for-exporter-target
  136. for-exporter-target: $(EXPORTER_MODS)
  137. .PHONY: for-extension-target
  138. for-extension-target: $(EXTENSION_MODS)
  139. .PHONY: for-connector-target
  140. for-connector-target: $(CONNECTOR_MODS)
  141. .PHONY: for-internal-target
  142. for-internal-target: $(INTERNAL_MODS)
  143. .PHONY: for-pkg-target
  144. for-pkg-target: $(PKG_MODS)
  145. .PHONY: for-cmd-target
  146. for-cmd-target: $(CMD_MODS)
  147. .PHONY: for-other-target
  148. for-other-target: $(OTHER_MODS)
  149. .PHONY: for-integration-target
  150. for-integration-target: $(INTEGRATION_MODS)
  151. # Debugging target, which helps to quickly determine whether for-all-target is working or not.
  152. .PHONY: all-pwd
  153. all-pwd:
  154. $(MAKE) $(FOR_GROUP_TARGET) TARGET="pwd"
  155. .PHONY: run
  156. run:
  157. cd ./cmd/otelcontribcol && GO111MODULE=on $(GOCMD) run --race . --config ../../${RUN_CONFIG} ${RUN_ARGS}
  158. .PHONY: docker-component # Not intended to be used directly
  159. docker-component: check-component
  160. GOOS=linux GOARCH=amd64 $(MAKE) $(COMPONENT)
  161. cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
  162. docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
  163. rm ./cmd/$(COMPONENT)/$(COMPONENT)
  164. .PHONY: check-component
  165. check-component:
  166. ifndef COMPONENT
  167. $(error COMPONENT variable was not defined)
  168. endif
  169. .PHONY: docker-otelcontribcol
  170. docker-otelcontribcol:
  171. COMPONENT=otelcontribcol $(MAKE) docker-component
  172. docker-obcol:
  173. COMPONENT=obcol $(MAKE) docker-component
  174. docker-push: docker-obcol
  175. docker tag obcol:latest reg.cestong.com.cn/cecf/obcol:latest
  176. docker push reg.cestong.com.cn/cecf/obcol:latest
  177. .PHONY: docker-telemetrygen
  178. docker-telemetrygen:
  179. COMPONENT=telemetrygen $(MAKE) docker-component
  180. .PHONY: generate
  181. generate: install-tools
  182. cd cmd/mdatagen && $(GOCMD) install .
  183. $(MAKE) for-all CMD="$(GOCMD) generate ./..."
  184. .PHONY: mdatagen-test
  185. mdatagen-test:
  186. cd cmd/mdatagen && $(GOCMD) install .
  187. cd cmd/mdatagen && $(GOCMD) generate ./...
  188. cd cmd/mdatagen && $(GOCMD) test ./...
  189. .PHONY: gengithub
  190. gengithub:
  191. cd cmd/githubgen && $(GOCMD) install .
  192. githubgen
  193. .PHONY: update-codeowners
  194. update-codeowners: gengithub generate
  195. FILENAME?=$(shell git branch --show-current)
  196. .PHONY: chlog-new
  197. chlog-new: $(CHLOGGEN)
  198. $(CHLOGGEN) new --config $(CHLOGGEN_CONFIG) --filename $(FILENAME)
  199. .PHONY: chlog-validate
  200. chlog-validate: $(CHLOGGEN)
  201. $(CHLOGGEN) validate --config $(CHLOGGEN_CONFIG)
  202. .PHONY: chlog-preview
  203. chlog-preview: $(CHLOGGEN)
  204. $(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --dry
  205. .PHONY: chlog-update
  206. chlog-update: $(CHLOGGEN)
  207. $(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --version $(VERSION)
  208. .PHONY: genotelcontribcol
  209. genotelcontribcol: $(BUILDER)
  210. $(BUILDER) --skip-compilation --config cmd/otelcontribcol/builder-config.yaml --output-path cmd/otelcontribcol
  211. $(MAKE) -C cmd/otelcontribcol fmt
  212. .PHONY: genobcol
  213. genobcol: $(BUILDER)
  214. $(BUILDER) --skip-compilation --config cmd/obcol/builder-config.yaml --output-path cmd/obcol
  215. $(MAKE) -C cmd/obcol fmt
  216. # Build the Collector executable.
  217. .PHONY: otelcontribcol
  218. otelcontribcol:
  219. cd ./cmd/otelcontribcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelcontribcol_$(GOOS)_$(GOARCH)$(EXTENSION) \
  220. -tags $(GO_BUILD_TAGS) .
  221. # Build the Collector executable.
  222. .PHONY: otelcontribcol
  223. obcol:
  224. cd ./cmd/obcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/obcol_$(GOOS)_$(GOARCH)$(EXTENSION) \
  225. -tags $(GO_BUILD_TAGS) .
  226. .PHONY: genoteltestbedcol
  227. genoteltestbedcol: $(BUILDER)
  228. $(BUILDER) --skip-compilation --config cmd/oteltestbedcol/builder-config.yaml --output-path cmd/oteltestbedcol
  229. $(MAKE) -C cmd/oteltestbedcol fmt
  230. # Build the Collector executable, with only components used in testbed.
  231. .PHONY: oteltestbedcol
  232. oteltestbedcol:
  233. cd ./cmd/oteltestbedcol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/oteltestbedcol_$(GOOS)_$(GOARCH)$(EXTENSION) \
  234. -tags $(GO_BUILD_TAGS) .
  235. # Build the telemetrygen executable.
  236. .PHONY: telemetrygen
  237. telemetrygen:
  238. cd ./cmd/telemetrygen && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/telemetrygen_$(GOOS)_$(GOARCH)$(EXTENSION) \
  239. -tags $(GO_BUILD_TAGS) .
  240. .PHONY: update-dep
  241. update-dep:
  242. $(MAKE) $(FOR_GROUP_TARGET) TARGET="updatedep"
  243. $(MAKE) otelcontribcol
  244. .PHONY: update-otel
  245. update-otel:
  246. $(MAKE) update-dep MODULE=go.opentelemetry.io/collector VERSION=$(OTEL_VERSION) RC_VERSION=$(OTEL_RC_VERSION) STABLE_VERSION=$(OTEL_STABLE_VERSION)
  247. .PHONY: otel-from-tree
  248. otel-from-tree:
  249. # This command allows you to make changes to your local checkout of otel core and build
  250. # contrib against those changes without having to push to github and update a bunch of
  251. # references. The workflow is:
  252. #
  253. # 1. Hack on changes in core (assumed to be checked out in ../opentelemetry-collector from this directory)
  254. # 2. Run `make otel-from-tree` (only need to run it once to remap go modules)
  255. # 3. You can now build contrib and it will use your local otel core changes.
  256. # 4. Before committing/pushing your contrib changes, undo by running `make otel-from-lib`.
  257. $(MAKE) for-all CMD="$(GOCMD) mod edit -replace go.opentelemetry.io/collector=$(SRC_ROOT)/../opentelemetry-collector"
  258. .PHONY: otel-from-lib
  259. otel-from-lib:
  260. # Sets opentelemetry core to be not be pulled from local source tree. (Undoes otel-from-tree.)
  261. $(MAKE) for-all CMD="$(GOCMD) mod edit -dropreplace go.opentelemetry.io/collector"
  262. .PHONY: build-examples
  263. build-examples:
  264. docker-compose -f examples/demo/docker-compose.yaml build
  265. docker-compose -f exporter/splunkhecexporter/example/docker-compose.yml build
  266. .PHONY: deb-rpm-package
  267. %-package: ARCH ?= amd64
  268. %-package:
  269. GOOS=linux GOARCH=$(ARCH) $(MAKE) otelcontribcol
  270. docker build -t otelcontribcol-fpm internal/buildscripts/packaging/fpm
  271. docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcontribcol-fpm
  272. # Verify existence of READMEs for components specified as default components in the collector.
  273. .PHONY: checkdoc
  274. checkdoc: $(CHECKFILE)
  275. $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "README.md"
  276. # Verify existence of metadata.yaml for components specified as default components in the collector.
  277. .PHONY: checkmetadata
  278. checkmetadata: $(CHECKFILE)
  279. $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "metadata.yaml"
  280. .PHONY: checkapi
  281. checkapi:
  282. $(GOCMD) run cmd/checkapi/main.go .
  283. .PHONY: all-checklinks
  284. all-checklinks:
  285. $(MAKE) $(FOR_GROUP_TARGET) TARGET="checklinks"
  286. # Function to execute a command. Note the empty line before endef to make sure each command
  287. # gets executed separately instead of concatenated with previous one.
  288. # Accepts command to execute as first parameter.
  289. define exec-command
  290. $(1)
  291. endef
  292. # List of directories where certificates are stored for unit tests.
  293. CERT_DIRS := receiver/sapmreceiver/testdata \
  294. receiver/signalfxreceiver/testdata \
  295. receiver/splunkhecreceiver/testdata \
  296. receiver/mongodbatlasreceiver/testdata/alerts/cert \
  297. receiver/mongodbreceiver/testdata/certs \
  298. receiver/cloudflarereceiver/testdata/cert
  299. # Generate certificates for unit tests relying on certificates.
  300. .PHONY: certs
  301. certs:
  302. $(foreach dir, $(CERT_DIRS), $(call exec-command, @internal/buildscripts/gen-certs.sh -o $(dir)))
  303. .PHONY: multimod-verify
  304. multimod-verify: $(MULTIMOD)
  305. @echo "Validating versions.yaml"
  306. $(MULTIMOD) verify
  307. .PHONY: multimod-prerelease
  308. multimod-prerelease: $(MULTIMOD)
  309. $(MULTIMOD) prerelease -s=true -b=false -v ./versions.yaml -m contrib-base
  310. $(MAKE) gotidy
  311. .PHONY: multimod-sync
  312. multimod-sync: $(MULTIMOD)
  313. $(MULTIMOD) sync -a=true -s=true -o ../opentelemetry-collector
  314. $(MAKE) gotidy
  315. .PHONY: crosslink
  316. crosslink: $(CROSSLINK)
  317. @echo "Executing crosslink"
  318. $(CROSSLINK) --root=$(shell pwd) --prune
  319. .PHONY: clean
  320. clean:
  321. @echo "Removing coverage files"
  322. find . -type f -name 'coverage.txt' -delete
  323. find . -type f -name 'coverage.html' -delete
  324. find . -type f -name 'coverage.out' -delete
  325. find . -type f -name 'integration-coverage.txt' -delete
  326. find . -type f -name 'integration-coverage.html' -delete
  327. .PHONY: genconfigdocs
  328. genconfigdocs:
  329. cd cmd/configschema && $(GOCMD) run ./docsgen all
  330. .PHONY: generate-gh-issue-templates
  331. generate-gh-issue-templates:
  332. cd cmd/githubgen && $(GOCMD) install .
  333. githubgen issue-templates