Skip to content

chore: Run "go mod tidy" as part of generate-otel-collector to avoid invalid go.mod state#5240

Merged
blewis12 merged 1 commit intomainfrom
blewis12/run-go-mod-tidy-for-collector-before-generating
Jan 13, 2026
Merged

chore: Run "go mod tidy" as part of generate-otel-collector to avoid invalid go.mod state#5240
blewis12 merged 1 commit intomainfrom
blewis12/run-go-mod-tidy-for-collector-before-generating

Conversation

@blewis12
Copy link
Member

@blewis12 blewis12 commented Jan 12, 2026

This PR addresses an edge case in the collector generation:

It could be that a dependency in the collector that has been brought in transitively through either alloy or alloyengine has been updated in alloy/alloyengine go mod file. This leads us to the state where:

  • We attempt to build the collector via the generator.go file
  • That file belongs in the collector directory, and therefore go will attempt to understand the state of its go.mod and download any missing dependencies
  • The go.mod file is out of date, since the transitive dependencies have been updated and go mod tidy needs to be run

As a real-life example, if you run:

go get cloud.google.com/go/auth@v0.18.0

in the alloyengine module, and then attempt to build/generate the collector. You will run into the following error

➜  alloy git:(blewis12/run-go-mod-tidy-for-collector-before-generating) ✗ make generate-otel-collector-distro 
cd ./collector && GOOS= GOARCH= BUILDER_VERSION=v0.139.0 go generate
go: updates to go.mod needed; to update it:
        go mod tidy
make: *** [generate-otel-collector-distro] Error 1

This is sort of a chicken and egg situation, since the generator is what outputs the go.mod file, but the go.mod file needs to be tidy in order for the generation script to even run.

To get around this for now, we can check for the existence of a go.mod file in the collector directory, and if it exists then run go mod tidy as a pre-step to the generation step. I have added the check for the go.mod file, since technically it should be possible to generate the code completely from scratch (ie no existing go.mod file), and if we run go mod tidy when there is no go.mod file present, we get an error.

@blewis12 blewis12 requested a review from a team as a code owner January 12, 2026 17:12
@blewis12 blewis12 added the backport/v1.12 Backport to release/v1.12 label Jan 12, 2026
@blewis12 blewis12 merged commit f1dfcb9 into main Jan 13, 2026
55 checks passed
@blewis12 blewis12 deleted the blewis12/run-go-mod-tidy-for-collector-before-generating branch January 13, 2026 06:49
@grafana-alloybot
Copy link
Contributor

⚠️ Automatic backport to release/v1.12 failed

The automatic backport for this PR failed, likely due to merge conflicts. Perform the backport manually:

git fetch origin main release/v1.12
git checkout release/v1.12
git pull
git checkout -b backport/pr-5240-to-v1.12
git cherry-pick -x f1dfcb9c4ee48bbc15b0f8d4f38475e4b5bceb3a
# If conflicts exist, fix them, then:
git add .
git commit
# If no [more] conflicts, then:
git push -u origin backport/pr-5240-to-v1.12

Then create a PR from backport/pr-5240-to-v1.12 to release/v1.12 with the title:

chore: Run "go mod tidy" as part of generate-otel-collector to avoid invalid go.mod state [backport]

@blewis12
Copy link
Member Author

blewis12 commented Jan 13, 2026

Actually yeah, the backport would fail because this PR wasn't back ported. I actually think that PR should be back ported since we'll start getting some merge conflicts if not, and it's not actually exposing any features but includes internal build changes (looking at the guide here)

Gonna create a PR for that first

edit: meh, can't really backport the otel engine build changes because they're dependent on the prometheus upgrade. maybe this can wait until the next release, but gonna talk to Joe later today to make sure i'm not missing something

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v1.12 Backport to release/v1.12 frozen-due-to-age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants