Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- fix: Non-nullish, non-string label values are coerced to strings when a combination is first stored, so exposition escapes them; the store also keeps its own copy, so mutating the caller's object after recording no longer changes the stored series
- fix: Label-less summaries report `labels: {}` in `getMetricsAsJSON()`, like other metrics (Fixes [#838](https://github.com/prometheus/client_js/issues/838))
- chore: update benchmark baseline to v0.16.1
- fix: `Pushgateway#delete()` no longer removes `Content-Encoding` from the shared request headers, so gzip stays on for later `push()`/`pushAdd()` calls

### Added

Expand Down
10 changes: 7 additions & 3 deletions lib/pushgateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ async function useGateway(method, job, groupings) {

const httpModule = requestParams.protocol === 'https:' ? https : http;
const options = { ...this.requestOptions, method };
if (method === 'DELETE' && options.headers) {
// DELETE has no body, so drop Content-Encoding from a copy of the
// headers. Deleting it from the shared object would stop later
// push()/pushAdd() calls from sending it.
options.headers = { ...options.headers };
delete options.headers['Content-Encoding'];
}

return new Promise((resolve, reject) => {
if (method === 'DELETE' && options.headers) {
delete options.headers['Content-Encoding'];
}
const req = httpModule.request(requestParams, options, resp => {
let body = '';
resp.setEncoding('utf8');
Expand Down
29 changes: 29 additions & 0 deletions test/pushgatewayTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,35 @@ describe.each([
expect(mockHttp.isDone());
});
});

it('should keep the gzip header for pushes after a delete', async () => {
const headers = { 'Content-Encoding': 'gzip' };
const deleteMock = nock('http://192.168.99.100:9091', {
badheaders: ['Content-Encoding'],
})
.delete('/metrics/job/testJob')
.reply(200);
const pushMock = nock('http://192.168.99.100:9091', {
reqheaders: {
'Content-Encoding': 'gzip',
},
})
.post('/metrics/job/testJob', gzipSync(body))
.reply(200);

instance = new Pushgateway(
'http://192.168.99.100:9091',
{ headers },
registry,
);

await instance.delete({ jobName: 'testJob' });
await instance.pushAdd({ jobName: 'testJob' });

expect(deleteMock.isDone()).toBe(true);
expect(pushMock.isDone()).toBe(true);
expect(headers).toEqual({ 'Content-Encoding': 'gzip' });
});
};

describe('global registry', () => {
Expand Down