Skip to content

fix(pushgateway): keep Content-Encoding for pushes after delete() - #870

Open
sarankumar1325 wants to merge 1 commit into
prometheus:mainfrom
sarankumar1325:fix/pushgateway-delete-keeps-gzip-header
Open

sarankumar1325 wants to merge 1 commit into
prometheus:mainfrom
sarankumar1325:fix/pushgateway-delete-keeps-gzip-header

Conversation

@sarankumar1325

Copy link
Copy Markdown

useGateway() builds options as a shallow copy of this.requestOptions, and for DELETE requests it runs delete options.headers['Content-Encoding']. options.headers is still the same object the Pushgateway was constructed with, so one delete() call removes the header for the life of the instance (and from the caller's own headers object). After that, push() and pushAdd() send plain-text bodies and no Content-Encoding: gzip, so a gateway configured for gzip silently stops compressing.

const gw = new Pushgateway(url, { headers: { 'Content-Encoding': 'gzip' } });
await gw.delete({ jobName: 'job' });
await gw.pushAdd({ jobName: 'job' }); // no longer gzipped

The fix drops the header from a copy of the headers for DELETE only.

Tests:

  • New should keep the gzip header for pushes after a delete case in test/pushgatewayTest.js (runs for both registry types and both global/instance registries). It checks the DELETE has no Content-Encoding, the following pushAdd() is gzipped with the header, and the caller's headers object is unchanged. It fails on main (4 failures) and passes with this change.
  • npm run lint, prettier --check, tsc --project . and the full jest suite (655 tests) pass.
  • CHANGELOG entry under Unreleased.

delete() removed Content-Encoding from options.headers, but options is a
shallow copy, so this deleted the header from the instance's (and the
caller's) headers object. Every later push()/pushAdd() then sent an
uncompressed body without the gzip header. Drop the header from a copy
instead.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant