diff --git a/.github/workflows/build-and-test-arm.yml b/.github/workflows/build-and-test-arm.yml index 1603997be28..f6af77b7242 100644 --- a/.github/workflows/build-and-test-arm.yml +++ b/.github/workflows/build-and-test-arm.yml @@ -33,9 +33,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools arm-unittest-matrix: needs: [setup-environment] if: ${{ github.actor != 'dependabot[bot]' && (!contains(github.event.pull_request.labels.*.name, 'Skip ARM') || github.event_name == 'push' || github.event_name == 'merge_group') }} @@ -129,5 +126,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - make install-tools - ./.tools/issuegenerator -path ./internal/tools/testresults/ -labels "flaky tests,needs triage" + go -C ./internal/tools tool go.opentelemetry.io/build-tools/issuegenerator -path ./internal/tools/testresults/ -labels "flaky tests,needs triage" diff --git a/.github/workflows/build-and-test-darwin.yaml b/.github/workflows/build-and-test-darwin.yaml index 788ddf49723..11e478b1ba0 100644 --- a/.github/workflows/build-and-test-darwin.yaml +++ b/.github/workflows/build-and-test-darwin.yaml @@ -40,9 +40,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools darwin-build-unittest-binary: needs: [setup-environment] if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }} diff --git a/.github/workflows/build-and-test-windows.yml b/.github/workflows/build-and-test-windows.yml index c7159470021..ac2b9e03ddf 100644 --- a/.github/workflows/build-and-test-windows.yml +++ b/.github/workflows/build-and-test-windows.yml @@ -41,9 +41,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools windows-smoke-build: needs: [setup-environment] @@ -63,9 +60,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Generate nrdotcol files run: make gennrdotcol - name: Build Collector @@ -106,11 +100,11 @@ jobs: - name: Ensure required ports in the dynamic range are available run: | & ${{ github.workspace }}\.github\workflows\scripts\win-required-ports.ps1 - - name: Build shared test tools - # If component tests share Makefile targets they need to be added here to avoid - # concurrent component tests clashing when building such targets. This applies + - name: Pre-build shared test tools + # Pre-warms the go tool cache for gotestsum to avoid concurrent builds when + # multiple test matrix jobs start simultaneously on Windows. # specifically to Windows, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/34691 - run: make "$(${PWD} -replace '\\', '/')/.tools/gotestsum" + run: go -C ./internal/tools tool -n gotest.tools/gotestsum | Out-Null # Unit tests without JUnit output are much faster, so it's fine to run on every PR. # The only time we don't run them is when we already ran them with JUnit output. @@ -179,9 +173,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6 with: merge-multiple: true @@ -191,5 +182,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - make install-tools - ./.tools/issuegenerator -path ./internal/tools/testresults/ -labels "flaky tests,needs triage" + go -C ./internal/tools tool go.opentelemetry.io/build-tools/issuegenerator -path ./internal/tools/testresults/ -labels "flaky tests,needs triage" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b6d4ea784b1..60189e8ef96 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -54,9 +54,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools check-collector-module-version: runs-on: ubuntu-24.04 needs: [setup-environment] @@ -93,9 +90,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Fetch commit history up to date of fork run: git fetch origin main --shallow-since=2025-11-18 - name: Lint @@ -143,9 +137,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Run `govulncheck` run: | out=$(mktemp) @@ -167,9 +158,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - run: make gennrdotcol - name: Check Component Files run: make check-component-files @@ -247,9 +235,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Cache Test Build uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 with: @@ -401,9 +386,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Correctness run: make -C testbed run-correctness-traces-tests correctness-metrics: @@ -420,9 +402,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Correctness run: make -C testbed run-correctness-metrics-tests @@ -478,9 +457,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Generate collector files run: make gennrdotcol - name: Build Collector ${{ matrix.os }} ${{ matrix.arch }} ${{ matrix.arm }} @@ -526,9 +502,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Build Docker Image run: | make gennrdotcol diff --git a/.github/workflows/check-codeowners.yaml b/.github/workflows/check-codeowners.yaml index df942ab40e1..99db9f7b6b0 100644 --- a/.github/workflows/check-codeowners.yaml +++ b/.github/workflows/check-codeowners.yaml @@ -43,10 +43,6 @@ jobs: go-version: oldstable cache-dependency-path: "**/*.sum" - - name: Install tools - run: | - make install-tools - - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 with: ref: ${{github.event.pull_request.head.ref}} @@ -56,5 +52,5 @@ jobs: - name: Gen CODEOWNERS run: | cd pr - GITHUB_TOKEN=${{ secrets.OTELCOMBOT_TOKEN }} ../.tools/githubgen --default-codeowner="@newrelic/otelcomm" --github-org="newrelic" codeowners + GITHUB_TOKEN=${{ secrets.OTELCOMBOT_TOKEN }} go -C ../internal/tools tool go.opentelemetry.io/build-tools/githubgen --default-codeowner="@newrelic/otelcomm" --github-org="newrelic" codeowners git diff -s --exit-code || (echo 'Generated code is out of date, please run "make gencodeowners" or apply this diff and commit the changes in this PR.' && git diff && exit 1) diff --git a/.github/workflows/e2e-tests-windows.yml b/.github/workflows/e2e-tests-windows.yml index f1dab1f772e..69c38e2f6c8 100644 --- a/.github/workflows/e2e-tests-windows.yml +++ b/.github/workflows/e2e-tests-windows.yml @@ -42,9 +42,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Generate otelcontribcol files run: make gennrdotcol - name: Build Collector diff --git a/.github/workflows/lint-workflow-files.yml b/.github/workflows/lint-workflow-files.yml index 5a1a4efd551..4b3d20feeed 100644 --- a/.github/workflows/lint-workflow-files.yml +++ b/.github/workflows/lint-workflow-files.yml @@ -29,9 +29,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Run Actionlint run: | diff --git a/.github/workflows/scoped-test.yaml b/.github/workflows/scoped-test.yaml index 43662e2bff8..c7bfe0ddcf4 100644 --- a/.github/workflows/scoped-test.yaml +++ b/.github/workflows/scoped-test.yaml @@ -79,13 +79,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - - - name: Build gotestsum - shell: bash - run: make "$PWD/.tools/gotestsum" - name: Run changed tests if: needs.changedfiles.outputs.go_tests diff --git a/.github/workflows/tidy-dependencies.yml b/.github/workflows/tidy-dependencies.yml index c06146cbb85..839e77cce60 100644 --- a/.github/workflows/tidy-dependencies.yml +++ b/.github/workflows/tidy-dependencies.yml @@ -37,9 +37,6 @@ jobs: - name: Install dependencies if: steps.go-setup.outputs.cache-hit != 'true' run: make -j2 gomoddownload - - name: Install Tools - if: steps.go-setup.outputs.cache-hit != 'true' - run: make install-tools - name: Import GPG key uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6 with: diff --git a/Makefile b/Makefile index 24a8ae3d05d..b21f48465f2 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ all-groups: @echo -e "\ngenerated: $(GENERATED_MODS)" .PHONY: all -all: install-tools all-common goporto multimod-verify gotest nrdotcol +all: all-common goporto multimod-verify gotest nrdotcol .PHONY: all-common all-common: @@ -124,7 +124,7 @@ gogci: $(MAKE) $(FOR_GROUP_TARGET) TARGET="gci" .PHONY: tidylist -tidylist: $(CROSSLINK) +tidylist: cd internal/tidylist && \ $(CROSSLINK) tidylist \ --validate \ @@ -197,7 +197,7 @@ gogovulncheck: $(MAKE) $(FOR_GROUP_TARGET) TARGET="govulncheck" .PHONY: goporto -goporto: $(PORTO) +goporto: $(PORTO) -w --include-internal --skip-dirs "^cmd$$" ./ .PHONY: for-all @@ -220,7 +220,7 @@ COMMIT?=HEAD MODSET?=contrib-core REMOTE?=git@github.com:open-telemetry/opentelemetry-collector-contrib.git .PHONY: push-tags -push-tags: $(MULTIMOD) +push-tags: $(MULTIMOD) verify set -e; for tag in `$(MULTIMOD) tag -m ${MODSET} -c ${COMMIT} --print-tags | grep -v "Using" `; do \ echo "pushing tag $${tag}"; \ @@ -305,14 +305,14 @@ docker-golden: .PHONY: gengithub -gengithub: $(GITHUBGEN) +gengithub: $(GITHUBGEN) -default-codeowner "@newrelic/otelcomm" -github-org "newrelic" .PHONY: gendistributions -gendistributions: $(GITHUBGEN) +gendistributions: $(GITHUBGEN) distributions -gencodecov: $(CODECOVGEN) +gencodecov: $(CODECOVGEN) --base-prefix github.com/newrelic/nrdot-collector-components --skipped-modules **/*test,**/examples/**,pkg/**,cmd/**,internal/**,*/encoding/** .PHONY: update-codeowners @@ -320,7 +320,7 @@ update-codeowners: generate gengithub $(MAKE) genlabels .PHONY: gencodeowners -gencodeowners: install-tools +gencodeowners: $(GITHUBGEN) -skipgithub -default-codeowner "@newrelic/otelcomm" # Fix README links generated by mdatagen (which hardcodes OTel URLs) @@ -336,39 +336,39 @@ fix-readme-links: # Override generate from Makefile.Common to also fix README links .PHONY: generate -generate: generate-tools +generate: ifeq ($(CURDIR),$(SRC_ROOT)) - PATH="$(TOOLS_BIN_DIR_PORTABLE):$$PATH" $(MAKE) for-all CMD="$(GOCMD) generate ./..." + $(MAKE) for-all CMD="$(GOCMD) generate ./..." $(MAKE) gofmt else - PATH="$(TOOLS_BIN_DIR_PORTABLE):$$PATH" $(GOCMD) generate ./... + $(GOCMD) generate ./... $(MAKE) fmt endif $(MAKE) fix-readme-links .PHONY: generate-chloggen-components -generate-chloggen-components: $(GITHUBGEN) +generate-chloggen-components: $(GITHUBGEN) chloggen-components FILENAME?=$(shell git branch --show-current) .PHONY: chlog-new -chlog-new: $(CHLOGGEN) +chlog-new: $(CHLOGGEN) new --config $(CHLOGGEN_CONFIG) --filename $(FILENAME) .PHONY: chlog-validate -chlog-validate: $(CHLOGGEN) +chlog-validate: $(CHLOGGEN) validate --config $(CHLOGGEN_CONFIG) .PHONY: chlog-preview -chlog-preview: $(CHLOGGEN) +chlog-preview: $(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --dry .PHONY: chlog-update -chlog-update: $(CHLOGGEN) +chlog-update: $(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --version $(VERSION) .PHONY: gennrdotcol -gennrdotcol: $(BUILDER) +gennrdotcol: ./internal/buildscripts/ocb-add-replaces.sh nrdotcol $(BUILDER) --skip-compilation --config cmd/nrdotcol/builder-config-replaced.yaml @@ -385,7 +385,7 @@ nrdotcollite: gennrdotcol -tags $(GO_BUILD_TAGS) -ldflags $(GO_BUILD_LDFLAGS) . .PHONY: genoteltestbedcol -genoteltestbedcol: $(BUILDER) +genoteltestbedcol: ./internal/buildscripts/ocb-add-replaces.sh oteltestbedcol $(BUILDER) --skip-compilation --config cmd/oteltestbedcol/builder-config-replaced.yaml @@ -451,7 +451,7 @@ endif @./.github/workflows/scripts/update-golang.sh -v $(VERSION) .PHONY: update-otel -update-otel:$(MULTIMOD) +update-otel: # Make sure cmd/nrdotcol/go.mod and cmd/oteltestbedcol/go.mod are present $(MAKE) gennrdotcol $(MAKE) genoteltestbedcol @@ -513,7 +513,6 @@ endif $(MAKE) gotidy $(call updatehelper,$(CORE_VERSIONS),./cmd/nrdotcol/go.mod,./cmd/nrdotcol/builder-config.yaml) $(call updatehelper,$(CORE_VERSIONS),./cmd/oteltestbedcol/go.mod,./cmd/oteltestbedcol/builder-config.yaml) - $(MAKE) -B install-tools $(MAKE) gennrdotcol $(MAKE) genoteltestbedcol $(MAKE) generate @@ -567,17 +566,17 @@ otel-from-lib: # Verify existence of READMEs for components specified as default components in the collector. .PHONY: checkdoc -checkdoc: $(CHECKFILE) +checkdoc: $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "README.md" # Verify existence of metadata.yaml for components specified as default components in the collector. .PHONY: checkmetadata -checkmetadata: $(CHECKFILE) +checkmetadata: $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "metadata.yaml" # Run all component file checks to enforce required files per docs/ADDING_COMPONENTS.md .PHONY: check-component-files -check-component-files: checkdoc checkmetadata $(CHECKFILE) +check-component-files: checkdoc checkmetadata $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "doc.go" $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "go.mod" $(CHECKFILE) --project-path $(CURDIR) --component-rel-path $(COMP_REL_PATH) --module-name $(MOD_NAME) --file-name "Makefile" @@ -603,7 +602,7 @@ check-builder-integration: done .PHONY: checkapi -checkapi: $(CHECKAPI) +checkapi: $(CHECKAPI) -folder . -config .checkapi.yaml .PHONY: kind-ready @@ -660,22 +659,22 @@ certs: $(foreach dir, $(CERT_DIRS), $(call exec-command, @internal/buildscripts/gen-certs.sh -o $(dir))) .PHONY: multimod-verify -multimod-verify: $(MULTIMOD) +multimod-verify: @echo "Validating versions.yaml" $(MULTIMOD) verify .PHONY: multimod-prerelease -multimod-prerelease: $(MULTIMOD) +multimod-prerelease: $(MULTIMOD) prerelease -s=true -b=false -v ./versions.yaml -m beta $(MAKE) gotidy .PHONY: multimod-sync -multimod-sync: $(MULTIMOD) +multimod-sync: $(MULTIMOD) sync -a=true -s=true -o ../opentelemetry-collector $(MAKE) gotidy .PHONY: crosslink -crosslink: $(CROSSLINK) +crosslink: @echo "Executing crosslink" $(CROSSLINK) --root=$(shell pwd) --prune @@ -702,7 +701,7 @@ clean-cols: cd cmd/oteltestbedcol && git clean -fX .PHONY: generate-gh-issue-templates -generate-gh-issue-templates: $(GITHUBGEN) +generate-gh-issue-templates: $(GITHUBGEN) issue-templates .PHONY: checks diff --git a/Makefile.Common b/Makefile.Common index ea75e36eca2..345840944fc 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -43,59 +43,56 @@ DOCKERCMD ?= docker CURR_MOD := $(shell go list -m | tr '/' '-' ) -# In order to help reduce toil related to managing tooling for the open telemetry collector -# this section of the makefile looks at only requiring command definitions to be defined -# as part of $(TOOLS_MOD_DIR)/tools.go, following the existing practice. +# Tools are declared in $(TOOLS_MOD_DIR)/go.mod using the Go tool directive. # Modifying the tools' `go.mod` file will trigger a rebuild of the tools to help # ensure that all contributors are using the most recent version to make builds repeatable everywhere. -TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools -TOOLS_MOD_REGEX := "\s+_\s+\".*\"" -TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"") -TOOLS_BIN_DIR := $(SRC_ROOT)/.tools -TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES))) -CHLOGGEN_CONFIG := .chloggen/config.yaml +TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools +CHLOGGEN_CONFIG := .chloggen/config.yaml # no trailing slash JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults -.PHONY: install-tools -install-tools: $(TOOLS_BIN_NAMES) - -$(TOOLS_BIN_DIR): - mkdir -p $@ - -$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod - cd $(TOOLS_MOD_DIR) && GOOS="" GOARCH="" $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES)) - -ACTIONLINT := $(TOOLS_BIN_DIR)/actionlint -ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense -NRLICENSE := $(TOOLS_BIN_DIR)/nrlicense -MDLINKCHECK := $(TOOLS_BIN_DIR)/markdown-link-check -MISSPELL := $(TOOLS_BIN_DIR)/misspell -error -MISSPELL_CORRECTION := $(TOOLS_BIN_DIR)/misspell -w -LINT := $(TOOLS_BIN_DIR)/golangci-lint -MULTIMOD := $(TOOLS_BIN_DIR)/multimod -CHLOGGEN := $(TOOLS_BIN_DIR)/chloggen -GITHUBGEN := $(TOOLS_BIN_DIR)/githubgen -CODECOVGEN := $(TOOLS_BIN_DIR)/codecovgen -GOIMPORTS := $(TOOLS_BIN_DIR)/goimports -PORTO := $(TOOLS_BIN_DIR)/porto -CHECKFILE := $(TOOLS_BIN_DIR)/checkfile -CROSSLINK := $(TOOLS_BIN_DIR)/crosslink -GOJUNIT := $(TOOLS_BIN_DIR)/go-junit-report -BUILDER := $(TOOLS_BIN_DIR)/builder -GOFUMPT := $(TOOLS_BIN_DIR)/gofumpt -GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck -GCI := $(TOOLS_BIN_DIR)/gci -GOTESTSUM := $(TOOLS_BIN_DIR)/gotestsum -CHECKAPI := $(TOOLS_BIN_DIR)/checkapi -MODERNIZE := $(TOOLS_BIN_DIR)/modernize -LICENSE_DETECTOR := $(TOOLS_BIN_DIR)/go-licence-detector +# GO_TOOL invokes a tool declared in the tools module via the Go tool directive. +# Uses -C to run from the tools module directory so that replace directives with +# relative paths (e.g. local cmd/ modules) resolve correctly. +# On Windows, `go tool -n` returns paths with backslashes; $(subst \,/,...) normalises them. +GO_TOOL = GOOS= GOARCH= $(GOCMD) -C $(TOOLS_MOD_DIR) tool + + +ACTIONLINT = $(subst \,/,$(shell $(GO_TOOL) -n github.com/rhysd/actionlint/cmd/actionlint)) +ADDLICENSE = $(subst \,/,$(shell $(GO_TOOL) -n github.com/google/addlicense)) +NRLICENSE = $(subst \,/,$(shell $(GO_TOOL) -n github.com/newrelic/nrdot-collector-components/cmd/nrlicense)) +MDLINKCHECK = markdown-link-check +MISSPELL = $(subst \,/,$(shell $(GO_TOOL) -n github.com/client9/misspell/cmd/misspell)) -error +MISSPELL_CORRECTION = $(subst \,/,$(shell $(GO_TOOL) -n github.com/client9/misspell/cmd/misspell)) -w +LINT = $(subst \,/,$(shell $(GO_TOOL) -n github.com/golangci/golangci-lint/v2/cmd/golangci-lint)) +MULTIMOD = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/multimod)) +CHLOGGEN = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/chloggen)) +GITHUBGEN = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/githubgen)) +CODECOVGEN = $(subst \,/,$(shell $(GO_TOOL) -n github.com/newrelic/nrdot-collector-components/cmd/codecovgen)) +GOIMPORTS = $(subst \,/,$(shell $(GO_TOOL) -n golang.org/x/tools/cmd/goimports)) +PORTO = $(subst \,/,$(shell $(GO_TOOL) -n github.com/jcchavezs/porto/cmd/porto)) +CHECKFILE = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/checkfile)) +CROSSLINK = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/crosslink)) +GOJUNIT = $(subst \,/,$(shell $(GO_TOOL) -n github.com/jstemmer/go-junit-report/v2)) +BUILDER = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/collector/cmd/builder)) +GOFUMPT = $(subst \,/,$(shell $(GO_TOOL) -n mvdan.cc/gofumpt)) +GOVULNCHECK = $(subst \,/,$(shell $(GO_TOOL) -n golang.org/x/vuln/cmd/govulncheck)) +GCI = $(subst \,/,$(shell $(GO_TOOL) -n github.com/daixiang0/gci)) +GOTESTSUM = $(subst \,/,$(shell $(GO_TOOL) -n gotest.tools/gotestsum)) +CHECKAPI = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/build-tools/checkapi)) +MODERNIZE = $(subst \,/,$(shell $(GO_TOOL) -n golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize)) +LICENSE_DETECTOR = $(subst \,/,$(shell $(GO_TOOL) -n go.elastic.co/go-licence-detector)) # Tools used by go generate commands -MDATAGEN := $(TOOLS_BIN_DIR)/mdatagen -# The githubreceiver uses a "go generate" tool that is not used by other components. -GENQLIENT := $(TOOLS_BIN_DIR)/genqlient +MDATAGEN = $(subst \,/,$(shell $(GO_TOOL) -n go.opentelemetry.io/collector/cmd/mdatagen)) +GENQLIENT = $(subst \,/,$(shell $(GO_TOOL) -n github.com/Khan/genqlient)) + +MDATAGEN_METADATA_YAML?= metadata.yaml + +.PHONY: mdatagen +mdatagen: + @$(MDATAGEN) $(MDATAGEN_METADATA_YAML) GOTESTSUM_OPT?= --rerun-fails=1 @@ -125,7 +122,7 @@ pwd: common: lint test .PHONY: test -test: $(GOTESTSUM) +test: $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT) # This target is used in scoped tests. @@ -133,27 +130,27 @@ test: $(GOTESTSUM) # and run each changed test two times. # # This helps us catch flakes more easily before they land on main. -test-twice: $(GOTESTSUM) +test-twice: $(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -count=2 .PHONY: test-with-cover -test-with-cover: $(GOTESTSUM) +test-with-cover: mkdir -p $(PWD)/coverage/unit $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -args -test.gocoverdir="$(PWD)/coverage/unit" .PHONY: do-unit-tests-with-cover -do-unit-tests-with-cover: $(GOTESTSUM) +do-unit-tests-with-cover: @echo "running $(GOCMD) unit test ./... + coverage in `pwd`" $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT) ./... $(COVER_OPT) $(GOCMD) tool cover -html=coverage.txt -o coverage.html .PHONY: test-with-junit -test-with-junit: $(GOTESTSUM) +test-with-junit: mkdir -p $(JUNIT_OUT_DIR) $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./... .PHONY: test-with-junit-and-cover -test-with-junit-and-cover: $(GOTESTSUM) +test-with-junit-and-cover: mkdir -p $(COVER_DIR_ABS) mkdir -p $(JUNIT_OUT_DIR) $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./... $(COVER_OPT) @@ -165,7 +162,7 @@ ifneq (,$(wildcard ./*.go)) endif .PHONY: runbuilttest -runbuilttest: $(GOTESTSUM) +runbuilttest: ifneq (,$(wildcard ./builtunitetest.test)) $(GOTESTSUM) --raw-command -- $(GOCMD) tool test2json -p "./..." -t ./builtunitetest.test -test.v -test.failfast -test.timeout $(GOTEST_TIMEOUT) endif @@ -173,7 +170,7 @@ endif INTEGRATION_TEST_FILES := $(shell find . -name *integration_test.go) INTEGRATION_TESTS := $(if $(INTEGRATION_TEST_FILES),$(shell cat $(INTEGRATION_TEST_FILES) | sed -n "s/func \(Test[A-Za-z0-9_]*\).*/\1/p" | xargs | sed "s/ /|/g")) .PHONY: mod-integration-test -mod-integration-test: $(GOTESTSUM) +mod-integration-test: @echo "running $(GOCMD) integration test $(INTEGRATION_TESTS) in `pwd`" @if [ -n "$(INTEGRATION_TESTS)" ]; then \ $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- -run "$(INTEGRATION_TESTS)" $(GOTEST_OPT_WITH_INTEGRATION); \ @@ -185,7 +182,7 @@ mod-integration-test: $(GOTESTSUM) fi .PHONY: mod-integration-sudo-test -mod-integration-sudo-test: $(GOTESTSUM) +mod-integration-sudo-test: @echo "running $(GOCMD) integration sudo (root/privileged) test $(INTEGRATION_TESTS) in `pwd`" @if [ -n "$(INTEGRATION_TESTS)" ]; then \ $(GOTESTSUM) $(GOTESTSUM_OPT) --format standard-verbose --packages="./..." -- -run "$(INTEGRATION_TESTS)" $(GOTEST_OPT_WITH_INTEGRATION_SUDO); \ @@ -194,7 +191,7 @@ mod-integration-sudo-test: $(GOTESTSUM) fi .PHONY: do-integration-tests-with-cover -do-integration-tests-with-cover: $(GOTESTSUM) +do-integration-tests-with-cover: @echo "running $(GOCMD) integration test $(INTEGRATION_TESTS) + coverage in `pwd`" @if [ -n "$(INTEGRATION_TESTS)" ]; then \ $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- -run "$(INTEGRATION_TESTS)" $(GOTEST_OPT_WITH_INTEGRATION_COVERAGE); \ @@ -206,11 +203,11 @@ do-integration-tests-with-cover: $(GOTESTSUM) fi .PHONY: benchmark -benchmark: $(GOTESTSUM) +benchmark: $(GOTESTSUM) $(GOTESTSUM_OPT) --packages="$$(find . -name 'go.mod' -not -path '*/third_party/*' -not -path '*/local/*' -type f | xargs dirname | sort | uniq | xargs -L 1 bash -c 'cd $$0 && go list -f "{{ .Dir }}"' | xargs echo)" -- -bench=. -run=notests --tags=$(GO_BUILD_TAGS) .PHONY: addlicense -addlicense: $(NRLICENSE) addthirdparty +addlicense: addthirdparty @echo "Adding/updating license headers with nrlicense..." @$(NRLICENSE) --fix --fork-commit 51061db5838300734ff23888e2396263f61146d9 $$($(ALL_SRC_AND_SHELL_CMD)) @@ -230,7 +227,7 @@ addoverrides: popd .PHONY: addthirdparty -addthirdparty: $(LICENSE_DETECTOR) addoverrides +addthirdparty: addoverrides @echo "Generating third-party notices..." @rules_file="$(SRC_ROOT)/internal/assets/license/rules.json"; \ for dir in $$($(ALL_GO_MOD_DIR_CMD)); do \ @@ -248,7 +245,7 @@ addthirdparty: $(LICENSE_DETECTOR) addoverrides done .PHONY: checklicense -checklicense: $(NRLICENSE) addthirdparty +checklicense: addthirdparty @echo "Checking third party notices..." @(git diff --name-only; git ls-files --others --exclude-standard) | grep -q -e "THIRD_PARTY_NOTICES.md" -e "overrides.jsonl" && { \ echo "Third party notices or overrides out of date, please run \"make addlicense\" and commit the changes in this PR."; \ @@ -270,48 +267,31 @@ checklinks: --no-progress './**/*.md' .PHONY: fmt -fmt: $(GOFUMPT) $(GOIMPORTS) +fmt: $(GOFUMPT) -l -w -extra . $(GOIMPORTS) -w -local github.com/newrelic/nrdot-collector-components ./ -.PHONY: generate-tools -generate-tools: $(MDATAGEN) $(GENQLIENT) -ifeq ($(GOOS),windows) - @echo Adding "exe" extensions to generate tools - @for f in $^; do \ - cp -u "$$f" "$$f.exe"; \ - done -endif - -# On Windows changing path with absolute path includes ':' even escaping it is not enough to get it to correctly -# update PATH, so use a relative path when pre-pending to PATH on Windows. Unfortunately, realpath is not portable -# between mac and GNU based bash so keeping the full path on non-Windows OSes. -ifeq ($(GOOS),windows) - TOOLS_BIN_DIR_PORTABLE?=$(shell realpath --relative-to="$(CURDIR)" "$(TOOLS_BIN_DIR)") -else - TOOLS_BIN_DIR_PORTABLE?=$(TOOLS_BIN_DIR) -endif .PHONY: generate generate: generate-tools ifeq ($(CURDIR),$(SRC_ROOT)) - PATH="$(TOOLS_BIN_DIR_PORTABLE):$$PATH" $(MAKE) for-all CMD="$(GOCMD) generate ./..." + $(MAKE) for-all CMD="$(GOCMD) generate ./..." $(MAKE) gofmt else - PATH="$(TOOLS_BIN_DIR_PORTABLE):$$PATH" $(GOCMD) generate ./... + $(GOCMD) generate ./... $(MAKE) fmt endif .PHONY: lint -lint: $(LINT) checklicense misspell +lint: checklicense misspell $(LINT) run .PHONY: govulncheck -govulncheck: $(GOVULNCHECK) +govulncheck: $(GOVULNCHECK) ./... .PHONY: modernize -modernize: $(MODERNIZE) +modernize: $(MODERNIZE) -fix -test -v ./... .PHONY: tidy @@ -324,12 +304,12 @@ toolchain: $(GOCMD) get toolchain@none .PHONY: misspell -misspell: $(TOOLS_BIN_DIR)/misspell +misspell: @echo "running $(MISSPELL)" @$(MISSPELL) $$($(ALL_SRC_AND_DOC_CMD)) .PHONY: misspell-correction -misspell-correction: $(TOOLS_BIN_DIR)/misspell +misspell-correction: @$(MISSPELL_CORRECTION) $$($(ALL_SRC_AND_DOC_CMD)) .PHONY: moddownload @@ -337,7 +317,7 @@ moddownload: $(GOCMD) mod download .PHONY: gci -gci: $(TOOLS_BIN_DIR)/gci +gci: @echo "running $(GCI)" @$(GCI) write -s standard -s default -s "prefix(github.com/newrelic/nrdot-collector-components)" $$($(ALL_SRC_AND_DOC_CMD)) diff --git a/exporter/nopexporter/doc.go b/exporter/nopexporter/doc.go index 2304eeea79b..5d1cde12214 100644 --- a/exporter/nopexporter/doc.go +++ b/exporter/nopexporter/doc.go @@ -1,7 +1,7 @@ // Copyright New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -//go:generate mdatagen metadata.yaml +//go:generate make mdatagen // Package nopexporter serves as a placeholder exporter. package nopexporter // import "github.com/newrelic/nrdot-collector-components/exporter/nopexporter" diff --git a/internal/tools/THIRD_PARTY_NOTICES.md b/internal/tools/THIRD_PARTY_NOTICES.md index 084717eb1df..7038b14e498 100644 --- a/internal/tools/THIRD_PARTY_NOTICES.md +++ b/internal/tools/THIRD_PARTY_NOTICES.md @@ -60,7 +60,7 @@ Distributed under the following license(s): -## [github.com/jstemmer/go-junit-report](https://github.com/jstemmer/go-junit-report) +## [github.com/jstemmer/go-junit-report/v2](https://github.com/jstemmer/go-junit-report) Distributed under the following license(s): diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 714c4504dd8..925ef620878 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -2,6 +2,34 @@ module github.com/newrelic/nrdot-collector-components/internal/tools go 1.25.0 +tool ( + github.com/Khan/genqlient + github.com/client9/misspell/cmd/misspell + github.com/daixiang0/gci + github.com/golangci/golangci-lint/v2/cmd/golangci-lint + github.com/google/addlicense + github.com/jcchavezs/porto/cmd/porto + github.com/jstemmer/go-junit-report/v2 + github.com/newrelic/nrdot-collector-components/cmd/codecovgen + github.com/newrelic/nrdot-collector-components/cmd/nrlicense + github.com/rhysd/actionlint/cmd/actionlint + go.elastic.co/go-licence-detector + go.opentelemetry.io/build-tools/checkapi + go.opentelemetry.io/build-tools/checkfile + go.opentelemetry.io/build-tools/chloggen + go.opentelemetry.io/build-tools/crosslink + go.opentelemetry.io/build-tools/githubgen + go.opentelemetry.io/build-tools/issuegenerator + go.opentelemetry.io/build-tools/multimod + go.opentelemetry.io/collector/cmd/builder + go.opentelemetry.io/collector/cmd/mdatagen + golang.org/x/tools/cmd/goimports + golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize + golang.org/x/vuln/cmd/govulncheck + gotest.tools/gotestsum + mvdan.cc/gofumpt +) + require ( github.com/Khan/genqlient v0.8.1 github.com/client9/misspell v0.3.4 @@ -9,7 +37,7 @@ require ( github.com/golangci/golangci-lint/v2 v2.1.6 github.com/google/addlicense v1.2.0 github.com/jcchavezs/porto v0.6.0 - github.com/jstemmer/go-junit-report v1.0.0 + github.com/jstemmer/go-junit-report/v2 v2.1.0 github.com/newrelic/nrdot-collector-components/cmd/codecovgen v0.150.0 github.com/newrelic/nrdot-collector-components/cmd/nrlicense v0.150.0 github.com/rhysd/actionlint v1.7.8 diff --git a/internal/tools/go.sum b/internal/tools/go.sum index 34b16cb9bb8..c4cd3f2ec65 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -315,8 +315,8 @@ github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE github.com/joshdk/go-junit v1.0.0/go.mod h1:TiiV0PqkaNfFXjEiyjWM3XXrhVyCa1K4Zfga6W52ung= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds= -github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jstemmer/go-junit-report/v2 v2.1.0 h1:X3+hPYlSczH9IMIpSC9CQSZA0L+BipYafciZUWHEmsc= +github.com/jstemmer/go-junit-report/v2 v2.1.0/go.mod h1:mgHVr7VUo5Tn8OLVr1cKnLuEy0M92wdRntM99h7RkgQ= github.com/julz/importas v0.2.0 h1:y+MJN/UdL63QbFJHws9BVC5RpA2iq0kpjrFajTGivjQ= github.com/julz/importas v0.2.0/go.mod h1:pThlt589EnCYtMnmhmRYY/qn9lCf/frPOK+WMx3xiJY= github.com/kaptinlin/go-i18n v0.1.6 h1:XQT3qvE/xgNrAps/zXBHAKWhPlWSrFS9t1jCZ4PVnOs= diff --git a/internal/tools/tools.go b/internal/tools/tools.go index 8823d9bc5e1..50287ed3c4a 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -2,7 +2,7 @@ // Modifications copyright New Relic, Inc. // // Modifications can be found at the following URL: -// https://github.com/newrelic/nrdot-collector-components/commits/main/internal/tools/tools.go?since=2025-11-26 +// https://github.com/newrelic/nrdot-collector-components/commits/main/tools.go?since=2025-11-26 // // SPDX-License-Identifier: Apache-2.0 @@ -10,10 +10,11 @@ package tools // import "github.com/newrelic/nrdot-collector-components/internal/tools" -// This file follows the recommendation at -// https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module -// on how to pin tooling dependencies to a go.mod file. -// This ensures that all systems use the same version of tools in addition to regular dependencies. +// This file keeps tool dependencies as direct imports so that go-licence-detector +// classifies them as direct (not indirect) for THIRD_PARTY_NOTICES generation. +// go-licence-detector skips indirect deps; without these blank imports go mod tidy +// would mark all tool packages as // indirect, causing them to be omitted from notices. +// The go.mod `tool` directive remains the canonical tool declaration. import ( _ "github.com/Khan/genqlient" @@ -22,7 +23,7 @@ import ( _ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint" _ "github.com/google/addlicense" _ "github.com/jcchavezs/porto/cmd/porto" - _ "github.com/jstemmer/go-junit-report" + _ "github.com/jstemmer/go-junit-report/v2" _ "github.com/rhysd/actionlint/cmd/actionlint" _ "go.elastic.co/go-licence-detector" _ "go.opentelemetry.io/build-tools/checkapi" diff --git a/processor/adaptivetelemetryprocessor/doc.go b/processor/adaptivetelemetryprocessor/doc.go index 9853ac6016a..ab47e443e35 100644 --- a/processor/adaptivetelemetryprocessor/doc.go +++ b/processor/adaptivetelemetryprocessor/doc.go @@ -1,7 +1,7 @@ // Copyright New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -//go:generate mdatagen metadata.yaml +//go:generate make mdatagen // Package adaptivetelemetryprocessor implements a processor for adaptive telemetry. package adaptivetelemetryprocessor // import "github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor" diff --git a/receiver/nopreceiver/doc.go b/receiver/nopreceiver/doc.go index cbbdf71e66f..2cdb07bde9e 100644 --- a/receiver/nopreceiver/doc.go +++ b/receiver/nopreceiver/doc.go @@ -1,7 +1,7 @@ // Copyright New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -//go:generate mdatagen metadata.yaml +//go:generate make mdatagen // Package nopreceiver serves as a placeholder receiver. package nopreceiver // import "github.com/newrelic/nrdot-collector-components/receiver/nopreceiver" diff --git a/testbed/Makefile b/testbed/Makefile index 4c5d588027e..d340fb36408 100644 --- a/testbed/Makefile +++ b/testbed/Makefile @@ -7,7 +7,7 @@ list-tests: RUN_TESTBED=1 $(GOTEST) -v ./tests --test.list '.*' | grep "^Test" .PHONY: run-tests -run-tests: $(GOJUNIT) +run-tests: GOJUNIT=$(GOJUNIT) ./runtests.sh .PHONY: list-loadtest-tests @@ -27,7 +27,7 @@ list-correctness-metrics-tests: RUN_TESTBED=1 $(GOTEST) -v ./correctnesstests/metrics --test.list '.*' | grep "^Test" .PHONY: run-correctness-metrics-tests -run-correctness-metrics-tests: $(GOJUNIT) +run-correctness-metrics-tests: TESTS_DIR=correctnesstests/metrics GOJUNIT=$(GOJUNIT) ./runtests.sh .PHONY: list-correctness-traces-tests @@ -35,9 +35,9 @@ list-correctness-traces-tests: RUN_TESTBED=1 $(GOTEST) -v ./correctnesstests/traces --test.list '.*' | grep "^Test" .PHONY: run-correctness-traces-tests -run-correctness-traces-tests: $(GOJUNIT) +run-correctness-traces-tests: TESTS_DIR=correctnesstests/traces GOJUNIT=$(GOJUNIT) ./runtests.sh .PHONY: run-correctness-connectors-tests -run-correctness-connectors-tests: $(GOJUNIT) +run-correctness-connectors-tests: TESTS_DIR=correctnesstests/connectors GOJUNIT=$(GOJUNIT) ./runtests.sh