Skip to content

Fix checkin endpoint gzip handling#6491

Merged
michel-laterman merged 6 commits intoelastic:mainfrom
michel-laterman:fix/checkin-gzip-handling
Mar 6, 2026
Merged

Fix checkin endpoint gzip handling#6491
michel-laterman merged 6 commits intoelastic:mainfrom
michel-laterman:fix/checkin-gzip-handling

Conversation

@michel-laterman
Copy link
Contributor

@michel-laterman michel-laterman commented Mar 3, 2026

What is the problem this PR solves?

Checkin requests did not support "Content-Encoding: gzip" correctly.

How does this PR solve the problem?

Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

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

@michel-laterman michel-laterman requested a review from cmacknz March 3, 2026 22:35
@michel-laterman michel-laterman requested a review from a team as a code owner March 3, 2026 22:35
@michel-laterman michel-laterman added bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-active-all Automated backport with mergify to all the active branches labels Mar 3, 2026
@michel-laterman michel-laterman force-pushed the fix/checkin-gzip-handling branch from 85a4289 to b7ea7e5 Compare March 3, 2026 22:36
@michel-laterman michel-laterman force-pushed the fix/checkin-gzip-handling branch from b7ea7e5 to de0e252 Compare March 3, 2026 22:36
@michel-laterman
Copy link
Contributor Author

Some findings for validation of this:

  • stdlib clients automatically add an Accept-Encoding: gzip header by default
  • stdlib clients automatically handle responses that have a Content-Encoding: gzip
  • the current behaviour of the server will server compress the checkin response if they are over 1kb uncompressed

Gathering data from the first couple of checkin an agent with the default policy (monitoring + systems integration) makes with a custom fleet-server build we can see the compressed resp savings, and estimate the request size savings to be:

checkin number req body size resp body size req compressed resp compressed notes
1 1409 14783 780 (-44.6%) 3571 (-75.8%) contains POLICY_CHANGE action
2 4588 35 1155 (-74.8%) 35 (no compression) no returned actions

Note that these numbers are for agents running today, without effective_config as a part of the checkin request body.

@michel-laterman michel-laterman requested a review from cmacknz March 5, 2026 23:14
@michel-laterman michel-laterman merged commit 122fac1 into elastic:main Mar 6, 2026
10 checks passed
@michel-laterman michel-laterman deleted the fix/checkin-gzip-handling branch March 6, 2026 17:21
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

@Mergifyio backport 8.19 9.2 9.3

@mergify
Copy link
Contributor

mergify bot commented Mar 6, 2026

backport 8.19 9.2 9.3

✅ Backports have been created

Details

Cherry-pick of 122fac1 has failed:

On branch mergify/bp/8.19/pr-6491
Your branch is up to date with 'origin/8.19'.

You are currently cherry-picking commit 122fac1.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1772577135-Fix-checkin-compression-support.yaml
	modified:   internal/pkg/api/handleCheckin.go
	modified:   internal/pkg/api/openapi.gen.go
	modified:   internal/pkg/server/fleet_integration_test.go
	modified:   model/openapi.yml
	modified:   pkg/api/client.gen.go
	modified:   pkg/api/types.gen.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/api/handleCheckin_test.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

mergify bot pushed a commit that referenced this pull request Mar 6, 2026
Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)

# Conflicts:
#	internal/pkg/api/handleCheckin_test.go
mergify bot pushed a commit that referenced this pull request Mar 6, 2026
Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)
mergify bot pushed a commit that referenced this pull request Mar 6, 2026
Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)
ebeahan pushed a commit that referenced this pull request Mar 6, 2026
Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
ebeahan pushed a commit that referenced this pull request Mar 6, 2026
* Fix checkin endpoint gzip handling (#6491)

Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)

* Fix backport test

---------

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <michel.laterman@elastic.co>
michel-laterman added a commit that referenced this pull request Mar 6, 2026
* Fix checkin endpoint gzip handling (#6491)

Detect Content-Encoding: gzip header when validating checkin bodies and uncompress the body if detected.

(cherry picked from commit 122fac1)

# Conflicts:
#	internal/pkg/api/handleCheckin_test.go

* Fix backport

* Fix backport test

* Fix panic

---------

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <michel.laterman@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bug Something isn't working 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.

3 participants