2022-11-29 21:53:28 +00:00
|
|
|
# Copyright The OpenTelemetry Authors
|
2024-04-11 07:46:22 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
TOOLS_MOD_DIR := ./internal/tools
|
|
|
|
|
|
|
|
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
|
|
|
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
|
|
|
|
OTEL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(ALL_GO_MOD_DIRS))
|
2022-12-06 07:28:14 +00:00
|
|
|
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | grep -E -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
GO = go
|
|
|
|
TIMEOUT = 60
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := precommit
|
|
|
|
|
|
|
|
.PHONY: precommit ci
|
2024-05-22 19:58:38 +00:00
|
|
|
precommit: generate license-check misspell go-mod-tidy golangci-lint-fix verify-readmes test-default
|
|
|
|
ci: generate license-check lint vanity-import-check verify-readmes build test-default check-clean-work-tree test-coverage
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
# Tools
|
|
|
|
|
|
|
|
TOOLS = $(CURDIR)/.tools
|
|
|
|
|
|
|
|
$(TOOLS):
|
|
|
|
@mkdir -p $@
|
2024-05-12 14:17:38 +00:00
|
|
|
$(TOOLS)/%: $(TOOLS_MOD_DIR)/go.mod | $(TOOLS)
|
2022-11-29 21:53:28 +00:00
|
|
|
cd $(TOOLS_MOD_DIR) && \
|
|
|
|
$(GO) build -o $@ $(PACKAGE)
|
|
|
|
|
|
|
|
MULTIMOD = $(TOOLS)/multimod
|
|
|
|
$(TOOLS)/multimod: PACKAGE=go.opentelemetry.io/build-tools/multimod
|
|
|
|
|
|
|
|
SEMCONVGEN = $(TOOLS)/semconvgen
|
|
|
|
$(TOOLS)/semconvgen: PACKAGE=go.opentelemetry.io/build-tools/semconvgen
|
|
|
|
|
|
|
|
CROSSLINK = $(TOOLS)/crosslink
|
|
|
|
$(TOOLS)/crosslink: PACKAGE=go.opentelemetry.io/build-tools/crosslink
|
|
|
|
|
|
|
|
SEMCONVKIT = $(TOOLS)/semconvkit
|
|
|
|
$(TOOLS)/semconvkit: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/semconvkit
|
|
|
|
|
|
|
|
GOLANGCI_LINT = $(TOOLS)/golangci-lint
|
|
|
|
$(TOOLS)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint
|
|
|
|
|
|
|
|
MISSPELL = $(TOOLS)/misspell
|
|
|
|
$(TOOLS)/misspell: PACKAGE=github.com/client9/misspell/cmd/misspell
|
|
|
|
|
|
|
|
GOCOVMERGE = $(TOOLS)/gocovmerge
|
|
|
|
$(TOOLS)/gocovmerge: PACKAGE=github.com/wadey/gocovmerge
|
|
|
|
|
|
|
|
STRINGER = $(TOOLS)/stringer
|
|
|
|
$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer
|
|
|
|
|
|
|
|
PORTO = $(TOOLS)/porto
|
|
|
|
$(TOOLS)/porto: PACKAGE=github.com/jcchavezs/porto/cmd/porto
|
|
|
|
|
|
|
|
GOJQ = $(TOOLS)/gojq
|
|
|
|
$(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq
|
|
|
|
|
2023-08-29 11:12:56 +00:00
|
|
|
GOTMPL = $(TOOLS)/gotmpl
|
|
|
|
$(GOTMPL): PACKAGE=go.opentelemetry.io/build-tools/gotmpl
|
|
|
|
|
|
|
|
GORELEASE = $(TOOLS)/gorelease
|
|
|
|
$(GORELEASE): PACKAGE=golang.org/x/exp/cmd/gorelease
|
|
|
|
|
2023-11-13 17:50:16 +00:00
|
|
|
GOVULNCHECK = $(TOOLS)/govulncheck
|
|
|
|
$(TOOLS)/govulncheck: PACKAGE=golang.org/x/vuln/cmd/govulncheck
|
|
|
|
|
2022-11-29 21:53:28 +00:00
|
|
|
.PHONY: tools
|
2024-05-22 19:58:38 +00:00
|
|
|
tools: $(CROSSLINK) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(GOJQ) $(SEMCONVGEN) $(MULTIMOD) $(SEMCONVKIT) $(GOTMPL) $(GORELEASE)
|
2022-11-29 21:53:28 +00:00
|
|
|
|
2023-07-07 07:05:50 +00:00
|
|
|
# Virtualized python tools via docker
|
|
|
|
|
|
|
|
# The directory where the virtual environment is created.
|
|
|
|
VENVDIR := venv
|
|
|
|
|
|
|
|
# The directory where the python tools are installed.
|
|
|
|
PYTOOLS := $(VENVDIR)/bin
|
|
|
|
|
|
|
|
# The pip executable in the virtual environment.
|
|
|
|
PIP := $(PYTOOLS)/pip
|
|
|
|
|
|
|
|
# The directory in the docker image where the current directory is mounted.
|
|
|
|
WORKDIR := /workdir
|
|
|
|
|
|
|
|
# The python image to use for the virtual environment.
|
|
|
|
PYTHONIMAGE := python:3.11.3-slim-bullseye
|
|
|
|
|
|
|
|
# Run the python image with the current directory mounted.
|
|
|
|
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
|
|
|
|
|
|
|
|
# Create a virtual environment for Python tools.
|
|
|
|
$(PYTOOLS):
|
|
|
|
# The `--upgrade` flag is needed to ensure that the virtual environment is
|
|
|
|
# created with the latest pip version.
|
|
|
|
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"
|
2022-11-29 21:53:28 +00:00
|
|
|
|
2023-07-07 07:05:50 +00:00
|
|
|
# Install python packages into the virtual environment.
|
2024-05-12 14:17:38 +00:00
|
|
|
$(PYTOOLS)/%: $(PYTOOLS)
|
2023-07-07 07:05:50 +00:00
|
|
|
@$(DOCKERPY) $(PIP) install -r requirements.txt
|
|
|
|
|
|
|
|
CODESPELL = $(PYTOOLS)/codespell
|
|
|
|
$(CODESPELL): PACKAGE=codespell
|
|
|
|
|
|
|
|
# Generate
|
|
|
|
|
|
|
|
.PHONY: generate
|
2023-08-29 11:12:56 +00:00
|
|
|
generate: go-generate vanity-import-fix
|
2022-11-29 21:53:28 +00:00
|
|
|
|
2023-08-29 11:12:56 +00:00
|
|
|
.PHONY: go-generate
|
|
|
|
go-generate: $(OTEL_GO_MOD_DIRS:%=go-generate/%)
|
|
|
|
go-generate/%: DIR=$*
|
2024-05-12 14:17:38 +00:00
|
|
|
go-generate/%: $(STRINGER) $(GOTMPL)
|
2022-11-29 21:53:28 +00:00
|
|
|
@echo "$(GO) generate $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
2023-08-29 11:12:56 +00:00
|
|
|
&& PATH="$(TOOLS):$${PATH}" $(GO) generate ./...
|
|
|
|
|
|
|
|
.PHONY: vanity-import-fix
|
2024-05-12 14:17:38 +00:00
|
|
|
vanity-import-fix: $(PORTO)
|
2023-08-29 11:12:56 +00:00
|
|
|
@$(PORTO) --include-internal -w .
|
|
|
|
|
|
|
|
# Generate go.work file for local development.
|
|
|
|
.PHONY: go-work
|
2024-05-12 14:17:38 +00:00
|
|
|
go-work: $(CROSSLINK)
|
2023-08-29 11:12:56 +00:00
|
|
|
$(CROSSLINK) work --root=$(shell pwd)
|
2022-11-29 21:53:28 +00:00
|
|
|
|
2023-07-07 07:05:50 +00:00
|
|
|
# Build
|
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
|
|
|
|
build: $(OTEL_GO_MOD_DIRS:%=build/%) $(OTEL_GO_MOD_DIRS:%=build-tests/%)
|
2022-11-29 21:53:28 +00:00
|
|
|
build/%: DIR=$*
|
|
|
|
build/%:
|
|
|
|
@echo "$(GO) build $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) build ./...
|
|
|
|
|
|
|
|
build-tests/%: DIR=$*
|
|
|
|
build-tests/%:
|
|
|
|
@echo "$(GO) build tests $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| xargs $(GO) test -vet=off -run xxxxxMatchNothingxxxxx >/dev/null
|
|
|
|
|
|
|
|
# Tests
|
|
|
|
|
|
|
|
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
|
|
|
|
.PHONY: $(TEST_TARGETS) test
|
|
|
|
test-default test-race: ARGS=-race
|
|
|
|
test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=.
|
|
|
|
test-short: ARGS=-short
|
|
|
|
test-verbose: ARGS=-v -race
|
|
|
|
$(TEST_TARGETS): test
|
|
|
|
test: $(OTEL_GO_MOD_DIRS:%=test/%)
|
|
|
|
test/%: DIR=$*
|
|
|
|
test/%:
|
|
|
|
@echo "$(GO) test -timeout $(TIMEOUT)s $(ARGS) $(DIR)/..." \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| xargs $(GO) test -timeout $(TIMEOUT)s $(ARGS)
|
|
|
|
|
|
|
|
COVERAGE_MODE = atomic
|
|
|
|
COVERAGE_PROFILE = coverage.out
|
|
|
|
.PHONY: test-coverage
|
2024-05-12 14:17:38 +00:00
|
|
|
test-coverage: $(GOCOVMERGE)
|
2022-11-29 21:53:28 +00:00
|
|
|
@set -e; \
|
|
|
|
printf "" > coverage.txt; \
|
|
|
|
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
|
|
|
|
echo "$(GO) test -coverpkg=go.opentelemetry.io/otel/... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" $${dir}/..."; \
|
|
|
|
(cd "$${dir}" && \
|
|
|
|
$(GO) list ./... \
|
|
|
|
| grep -v third_party \
|
|
|
|
| grep -v 'semconv/v.*' \
|
|
|
|
| xargs $(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" && \
|
|
|
|
$(GO) tool cover -html=coverage.out -o coverage.html); \
|
|
|
|
done; \
|
|
|
|
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt
|
|
|
|
|
2024-02-24 01:22:39 +00:00
|
|
|
# Adding a directory will include all benchmarks in that directory if a filter is not specified.
|
2023-11-13 17:50:16 +00:00
|
|
|
BENCHMARK_TARGETS := sdk/trace
|
|
|
|
.PHONY: benchmark
|
|
|
|
benchmark: $(BENCHMARK_TARGETS:%=benchmark/%)
|
|
|
|
BENCHMARK_FILTER = .
|
|
|
|
# You can override the filter for a particular directory by adding a rule here.
|
|
|
|
benchmark/sdk/trace: BENCHMARK_FILTER = SpanWithAttributes_8/AlwaysSample
|
|
|
|
benchmark/%:
|
|
|
|
@echo "$(GO) test -timeout $(TIMEOUT)s -run=xxxxxMatchNothingxxxxx -bench=$(BENCHMARK_FILTER) $*..." \
|
|
|
|
&& cd $* \
|
|
|
|
$(foreach filter, $(BENCHMARK_FILTER), && $(GO) test -timeout $(TIMEOUT)s -run=xxxxxMatchNothingxxxxx -bench=$(filter))
|
|
|
|
|
2022-11-29 21:53:28 +00:00
|
|
|
.PHONY: golangci-lint golangci-lint-fix
|
|
|
|
golangci-lint-fix: ARGS=--fix
|
|
|
|
golangci-lint-fix: golangci-lint
|
|
|
|
golangci-lint: $(OTEL_GO_MOD_DIRS:%=golangci-lint/%)
|
|
|
|
golangci-lint/%: DIR=$*
|
2024-05-12 14:17:38 +00:00
|
|
|
golangci-lint/%: $(GOLANGCI_LINT)
|
2022-11-29 21:53:28 +00:00
|
|
|
@echo 'golangci-lint $(if $(ARGS),$(ARGS) ,)$(DIR)' \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GOLANGCI_LINT) run --allow-serial-runners $(ARGS)
|
|
|
|
|
|
|
|
.PHONY: crosslink
|
2024-05-12 14:17:38 +00:00
|
|
|
crosslink: $(CROSSLINK)
|
2022-11-29 21:53:28 +00:00
|
|
|
@echo "Updating intra-repository dependencies in all go modules" \
|
|
|
|
&& $(CROSSLINK) --root=$(shell pwd) --prune
|
|
|
|
|
|
|
|
.PHONY: go-mod-tidy
|
|
|
|
go-mod-tidy: $(ALL_GO_MOD_DIRS:%=go-mod-tidy/%)
|
|
|
|
go-mod-tidy/%: DIR=$*
|
2024-05-12 14:17:38 +00:00
|
|
|
go-mod-tidy/%: crosslink
|
2022-11-29 21:53:28 +00:00
|
|
|
@echo "$(GO) mod tidy in $(DIR)" \
|
|
|
|
&& cd $(DIR) \
|
2024-04-11 07:46:22 +00:00
|
|
|
&& $(GO) mod tidy -compat=1.21
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
.PHONY: lint-modules
|
|
|
|
lint-modules: go-mod-tidy
|
|
|
|
|
|
|
|
.PHONY: lint
|
2023-11-13 17:50:16 +00:00
|
|
|
lint: misspell lint-modules golangci-lint govulncheck
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
.PHONY: vanity-import-check
|
2024-05-12 14:17:38 +00:00
|
|
|
vanity-import-check: $(PORTO)
|
2023-08-29 11:12:56 +00:00
|
|
|
@$(PORTO) --include-internal -l . || ( echo "(run: make vanity-import-fix)"; exit 1 )
|
2022-11-29 21:53:28 +00:00
|
|
|
|
|
|
|
.PHONY: misspell
|
2024-05-12 14:17:38 +00:00
|
|
|
misspell: $(MISSPELL)
|
2022-11-29 21:53:28 +00:00
|
|
|
@$(MISSPELL) -w $(ALL_DOCS)
|
|
|
|
|
2023-11-13 17:50:16 +00:00
|
|
|
.PHONY: govulncheck
|
|
|
|
govulncheck: $(OTEL_GO_MOD_DIRS:%=govulncheck/%)
|
|
|
|
govulncheck/%: DIR=$*
|
2024-05-12 14:17:38 +00:00
|
|
|
govulncheck/%: $(GOVULNCHECK)
|
2023-11-13 17:50:16 +00:00
|
|
|
@echo "govulncheck ./... in $(DIR)" \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GOVULNCHECK) ./...
|
|
|
|
|
2023-07-07 07:05:50 +00:00
|
|
|
.PHONY: codespell
|
2024-05-12 14:17:38 +00:00
|
|
|
codespell: $(CODESPELL)
|
2023-07-07 07:05:50 +00:00
|
|
|
@$(DOCKERPY) $(CODESPELL)
|
|
|
|
|
2022-11-29 21:53:28 +00:00
|
|
|
.PHONY: license-check
|
|
|
|
license-check:
|
|
|
|
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*' ! -path './.git/*' ) ; do \
|
2023-08-29 11:12:56 +00:00
|
|
|
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=4 { found=1; next } END { if (!found) print FILENAME }' $$f; \
|
2022-11-29 21:53:28 +00:00
|
|
|
done); \
|
|
|
|
if [ -n "$${licRes}" ]; then \
|
|
|
|
echo "license header checking failed:"; echo "$${licRes}"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: check-clean-work-tree
|
|
|
|
check-clean-work-tree:
|
|
|
|
@if ! git diff --quiet; then \
|
|
|
|
echo; \
|
|
|
|
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
|
|
|
|
echo; \
|
|
|
|
git status; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
SEMCONVPKG ?= "semconv/"
|
|
|
|
.PHONY: semconv-generate
|
2024-05-12 14:17:38 +00:00
|
|
|
semconv-generate: $(SEMCONVGEN) $(SEMCONVKIT)
|
2023-08-29 11:12:56 +00:00
|
|
|
[ "$(TAG)" ] || ( echo "TAG unset: missing opentelemetry semantic-conventions tag"; exit 1 )
|
|
|
|
[ "$(OTEL_SEMCONV_REPO)" ] || ( echo "OTEL_SEMCONV_REPO unset: missing path to opentelemetry semantic-conventions repo"; exit 1 )
|
|
|
|
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=span -p conventionType=trace -f trace.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
|
|
|
|
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
|
|
|
|
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=event -p conventionType=event -f event.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
|
|
|
|
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=resource -p conventionType=resource -f resource.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
|
2024-04-11 07:46:22 +00:00
|
|
|
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=metric -f metric.go -t "$(SEMCONVPKG)/metric_template.j2" -s "$(TAG)"
|
2023-01-31 19:03:20 +00:00
|
|
|
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"
|
2022-11-29 21:53:28 +00:00
|
|
|
|
2023-08-29 11:12:56 +00:00
|
|
|
.PHONY: gorelease
|
|
|
|
gorelease: $(OTEL_GO_MOD_DIRS:%=gorelease/%)
|
|
|
|
gorelease/%: DIR=$*
|
|
|
|
gorelease/%:| $(GORELEASE)
|
|
|
|
@echo "gorelease in $(DIR):" \
|
|
|
|
&& cd $(DIR) \
|
|
|
|
&& $(GORELEASE) \
|
|
|
|
|| echo ""
|
|
|
|
|
2022-11-29 21:53:28 +00:00
|
|
|
.PHONY: prerelease
|
2024-05-12 14:17:38 +00:00
|
|
|
prerelease: $(MULTIMOD)
|
2022-11-29 21:53:28 +00:00
|
|
|
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
|
|
|
|
$(MULTIMOD) verify && $(MULTIMOD) prerelease -m ${MODSET}
|
|
|
|
|
|
|
|
COMMIT ?= "HEAD"
|
|
|
|
.PHONY: add-tags
|
2024-05-12 14:17:38 +00:00
|
|
|
add-tags: $(MULTIMOD)
|
2022-11-29 21:53:28 +00:00
|
|
|
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
|
|
|
|
$(MULTIMOD) verify && $(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}
|
2023-11-13 17:50:16 +00:00
|
|
|
|
|
|
|
.PHONY: lint-markdown
|
2024-04-11 07:46:22 +00:00
|
|
|
lint-markdown:
|
2024-02-24 01:22:39 +00:00
|
|
|
docker run -v "$(CURDIR):$(WORKDIR)" avtodev/markdown-lint:v1 -c $(WORKDIR)/.markdownlint.yaml $(WORKDIR)/**/*.md
|
2024-04-11 07:46:22 +00:00
|
|
|
|
|
|
|
.PHONY: verify-readmes
|
|
|
|
verify-readmes:
|
|
|
|
./verify_readmes.sh
|