prometheus: metadata: simplify the metrics-metadata format (#39411)

* prometheus: metadata: simplify the metrics-metadata format

* fixed unit test

* fixed tests
This commit is contained in:
Gábor Farkas
2021-09-21 15:19:52 +02:00
committed by GitHub
parent f1edd0ea08
commit 346a53145c
8 changed files with 66 additions and 66 deletions

View File

@ -73,23 +73,25 @@ describe('parseSelector()', () => {
describe('fixSummariesMetadata', () => {
const synthetics = {
ALERTS: [
{
type: 'counter',
help:
'Time series showing pending and firing alerts. The sample value is set to 1 as long as the alert is in the indicated active (pending or firing) state.',
},
],
ALERTS: {
type: 'counter',
help:
'Time series showing pending and firing alerts. The sample value is set to 1 as long as the alert is in the indicated active (pending or firing) state.',
},
};
it('returns only synthetics on empty metadata', () => {
expect(fixSummariesMetadata({})).toEqual({ ...synthetics });
});
it('returns unchanged metadata if no summary is present', () => {
const metadata = {
const metadataRaw = {
foo: [{ type: 'not_a_summary', help: 'foo help' }],
};
expect(fixSummariesMetadata(metadata)).toEqual({ ...metadata, ...synthetics });
const metadata = {
foo: { type: 'not_a_summary', help: 'foo help' },
};
expect(fixSummariesMetadata(metadataRaw)).toEqual({ ...metadata, ...synthetics });
});
it('returns metadata with added count and sum for a summary', () => {
@ -98,10 +100,10 @@ describe('fixSummariesMetadata', () => {
bar: [{ type: 'summary', help: 'bar help' }],
};
const expected = {
foo: [{ type: 'not_a_summary', help: 'foo help' }],
bar: [{ type: 'summary', help: 'bar help' }],
bar_count: [{ type: 'counter', help: 'Count of events that have been observed for the base metric (bar help)' }],
bar_sum: [{ type: 'counter', help: 'Total sum of all observed values for the base metric (bar help)' }],
foo: { type: 'not_a_summary', help: 'foo help' },
bar: { type: 'summary', help: 'bar help' },
bar_count: { type: 'counter', help: 'Count of events that have been observed for the base metric (bar help)' },
bar_sum: { type: 'counter', help: 'Total sum of all observed values for the base metric (bar help)' },
};
expect(fixSummariesMetadata(metadata)).toEqual({ ...expected, ...synthetics });
});
@ -112,13 +114,14 @@ describe('fixSummariesMetadata', () => {
bar: [{ type: 'histogram', help: 'bar help' }],
};
const expected = {
foo: [{ type: 'not_a_histogram', help: 'foo help' }],
bar: [{ type: 'histogram', help: 'bar help' }],
bar_bucket: [{ type: 'counter', help: 'Cumulative counters for the observation buckets (bar help)' }],
bar_count: [
{ type: 'counter', help: 'Count of events that have been observed for the histogram metric (bar help)' },
],
bar_sum: [{ type: 'counter', help: 'Total sum of all observed values for the histogram metric (bar help)' }],
foo: { type: 'not_a_histogram', help: 'foo help' },
bar: { type: 'histogram', help: 'bar help' },
bar_bucket: { type: 'counter', help: 'Cumulative counters for the observation buckets (bar help)' },
bar_count: {
type: 'counter',
help: 'Count of events that have been observed for the histogram metric (bar help)',
},
bar_sum: { type: 'counter', help: 'Total sum of all observed values for the histogram metric (bar help)' },
};
expect(fixSummariesMetadata(metadata)).toEqual({ ...expected, ...synthetics });
});