mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Add metadata for summary metrics (#24201)
* Prometheus: Add metadata for summary metrics - summary metrics don't have metadata available from the metadata API, so Grafana can help and just add it - given a summary metric `foo`, we add metadata info for `foo_sum` and `foo_count` - with tests * Update public/app/plugins/datasource/prometheus/language_utils.ts Co-authored-by: gotjosh <josue@grafana.com> Co-authored-by: gotjosh <josue@grafana.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { expandRecordingRules, parseSelector } from './language_utils';
|
||||
import { expandRecordingRules, fixSummariesMetadata, parseSelector } from './language_utils';
|
||||
|
||||
describe('parseSelector()', () => {
|
||||
let parsed;
|
||||
@@ -70,6 +70,33 @@ describe('parseSelector()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fixSummariesMetadata', () => {
|
||||
it('returns empty metadata', () => {
|
||||
expect(fixSummariesMetadata({})).toEqual({});
|
||||
});
|
||||
|
||||
it('returns unchanged metadata if no summary is present', () => {
|
||||
const metadata = {
|
||||
foo: [{ type: 'not_a_summary', help: 'foo help' }],
|
||||
};
|
||||
expect(fixSummariesMetadata(metadata)).toEqual(metadata);
|
||||
});
|
||||
|
||||
it('returns metadata with added count and sum for a summary', () => {
|
||||
const metadata = {
|
||||
foo: [{ type: 'not_a_summary', help: 'foo help' }],
|
||||
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)' }],
|
||||
};
|
||||
expect(fixSummariesMetadata(metadata)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('expandRecordingRules()', () => {
|
||||
it('returns query w/o recording rules as is', () => {
|
||||
expect(expandRecordingRules('metric', {})).toBe('metric');
|
||||
|
||||
Reference in New Issue
Block a user