Skip to content

fleet-server align structs#7264

Open
michel-laterman wants to merge 5 commits into
elastic:mainfrom
michel-laterman:enhancement/struct-align
Open

fleet-server align structs#7264
michel-laterman wants to merge 5 commits into
elastic:mainfrom
michel-laterman:enhancement/struct-align

Conversation

@michel-laterman

Copy link
Copy Markdown
Contributor

What is the problem this PR solves?

Structs in fleet-server codebase are padded. This results in more memory usage then required.

How does this PR solve the problem?

Use betteralign to automatically align go structs to get rid of padding.
Add check:align target to magefile and as a dependency of the check:ci target so changes to structs can be caught by the CI pipeline.

How to test this PR locally

mage check:align

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues

Use betteralign to automatically align go structs to get rid of padding.
Add check:align target to magefile so changes to structs can be caught
by the CI pipeline.
@michel-laterman michel-laterman added the enhancement New feature or request label Jun 22, 2026
@michel-laterman michel-laterman requested a review from a team as a code owner June 22, 2026 18:29
@michel-laterman michel-laterman added the backport-skip Skip notification from the automated backport with mergify label Jun 22, 2026
@michel-laterman michel-laterman requested a review from lorienhu June 22, 2026 18:29
@michel-laterman michel-laterman added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Jun 22, 2026
@michel-laterman michel-laterman requested a review from swiatekm June 22, 2026 18:29
@github-actions

Copy link
Copy Markdown
Contributor

TL;DR

Run check-ci is failing before tests run because goimports now resolves golang.org/x/tools@v0.46.0, but the PR's dev-tools module is missing the new golang.org/x/telemetry/counter dependency checksums. Refresh the dev-tools module after the golang.org/x/tools bump.

Remediation

  • Run go get -modfile dev-tools/go.mod golang.org/x/tools/cmd/goimports@v0.46.0 and commit the resulting dev-tools/go.mod / dev-tools/go.sum changes.
  • Re-run .buildkite/scripts/check_ci.sh or mage check:ci to confirm Check.Imports gets past the tool dependency resolution step.
Investigation details

Root Cause

This is a dependency/lockfile drift in the PR's tool module. The PR updates dev-tools/go.mod to use golang.org/x/tools v0.46.0 and magefile.go still runs goimports through that module at magefile.go:620-623:

return sh.Run("go", "tool", "-modfile", filepath.Join("dev-tools", "go.mod"), "golang.org/x/tools/cmd/goimports", "-w", ".")

With golang.org/x/tools@v0.46.0, goimports imports golang.org/x/telemetry/counter, but the PR's dev-tools/go.sum does not include golang.org/x/telemetry sums. That makes Check.Imports fail before the newly added Check.Align step is reached.

Evidence

../../../../go/pkg/mod/golang.org/x/tools@v0.46.0/cmd/goimports/goimports.go:23:2: missing go.sum entry for module providing package golang.org/x/telemetry/counter (imported by golang.org/x/tools/cmd/goimports); to add:
	go get golang.org/x/tools/cmd/goimports@v0.46.0
Error: running "go tool -modfile dev-tools/go.mod golang.org/x/tools/cmd/goimports -w ." failed with exit code 1

Verification

In a temporary worktree for PR commit cf646535b14d856a06ae4e1e365a4b6bedebab64, I reproduced the same missing-sum failure with:

go tool -modfile dev-tools/go.mod golang.org/x/tools/cmd/goimports -h

Then I ran the suggested command:

go get -modfile dev-tools/go.mod golang.org/x/tools/cmd/goimports@v0.46.0

After that, a non-mutating goimports invocation succeeded:

go tool -modfile dev-tools/go.mod golang.org/x/tools/cmd/goimports -l magefile.go

The remediation adds golang.org/x/telemetry and the missing golang.org/x/sys v0.46.0/go.mod checksum entries to the dev-tools module files.

Follow-up

No flaky-test issue matched this failure; this is deterministic module metadata drift rather than a flaky test.


What is this? | From workflow: PR Buildkite Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@michel-laterman michel-laterman left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some linter warnings for the policy and secrets pacakges which will be handled by #7260 and #7265

Comment on lines +191 to +192
for i, c := range []byte(key) { // convert string into []byte so any runes are properly handled
buf[i+1] = c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should prevent issues if a non ascii character is ever used as the key/val
cc: @pzl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-skip Skip notification from the automated backport with mergify enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fleet-server struct alignment

2 participants