feat: respect pruneAgedBuckets, update README

This commit is contained in:
Timm Stelzer
2024-01-06 11:31:26 +01:00
committed by Konstantin Pogorelov
parent edfb9992ed
commit fd5ff1cfe0
4 changed files with 60 additions and 13 deletions

View File

@@ -20,6 +20,10 @@ function extractBucket (instance, key) {
}
}
function getMetricCount (s) {
return s.replace(/^#.*$\n|^$\n/gm, '').trim().split('\n').length;
}
describe('index', () => {
beforeEach(() => {
promClient.register.clear();
@@ -342,7 +346,7 @@ describe('index', () => {
describe('usage of normalizePath()', () => {
it('normalizePath can be replaced gloablly', done => {
it('normalizePath can be replaced globally', done => {
const app = express();
const original = bundle.normalizePath;
bundle.normalizePath = () => 'dummy';
@@ -366,6 +370,40 @@ describe('index', () => {
});
});
it('respects pruneAgedBuckets', done => {
const app = express();
const metricsApp = express();
const bundled = bundle({
metricsApp,
metricType: 'summary',
includePath: true,
maxAgeSeconds: 1,
percentiles: [0.5],
ageBuckets: 1,
pruneAgedBuckets: true,
});
app.use(bundled);
const agent = supertest(app);
const metricsAgent = supertest(metricsApp);
agent.get('/foo')
.then(() => metricsAgent.get('/metrics'))
.then(response => {
expect(response.status).toBe(200);
// up + bucket, sum, count
expect(getMetricCount(response.text)).toBe(4);
})
.then(() => new Promise(r => setTimeout(r, 1010)))
.then(() => metricsAgent.get('/metrics'))
.then(response => {
expect(response.status).toBe(200);
// only up
expect(getMetricCount(response.text)).toBe(1);
})
.finally(done);
});
it('normalizePath function can be overridden', done => {
const app = express();
const instance = bundle({