mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -1,4 +1,4 @@
|
||||
import { PromMetricsMetadata } from './types';
|
||||
import { PromMetricsMetadata, PromMetricsMetadataItem } from './types';
|
||||
import { addLabelToQuery } from './add_label_to_query';
|
||||
import { SUGGESTIONS_LIMIT } from './language_provider';
|
||||
|
||||
@@ -169,59 +169,56 @@ function addLabelsToExpression(expr: string, invalidLabelsRegexp: RegExp) {
|
||||
*
|
||||
* @param metadata HELP and TYPE metadata from /api/v1/metadata
|
||||
*/
|
||||
export function fixSummariesMetadata(metadata: PromMetricsMetadata): PromMetricsMetadata {
|
||||
export function fixSummariesMetadata(metadata: { [metric: string]: PromMetricsMetadataItem[] }): PromMetricsMetadata {
|
||||
if (!metadata) {
|
||||
return metadata;
|
||||
}
|
||||
const baseMetadata: PromMetricsMetadata = {};
|
||||
const summaryMetadata: PromMetricsMetadata = {};
|
||||
for (const metric in metadata) {
|
||||
// NOTE: based on prometheus-documentation, we can receive
|
||||
// multiple metadata-entries for the given metric, it seems
|
||||
// it happens when the same metric is on multiple targets
|
||||
// and their help-text differs
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata)
|
||||
// for now we just use the first entry.
|
||||
const item = metadata[metric][0];
|
||||
baseMetadata[metric] = item;
|
||||
|
||||
if (item.type === 'histogram') {
|
||||
summaryMetadata[`${metric}_bucket`] = [
|
||||
{
|
||||
type: 'counter',
|
||||
help: `Cumulative counters for the observation buckets (${item.help})`,
|
||||
},
|
||||
];
|
||||
summaryMetadata[`${metric}_count`] = [
|
||||
{
|
||||
type: 'counter',
|
||||
help: `Count of events that have been observed for the histogram metric (${item.help})`,
|
||||
},
|
||||
];
|
||||
summaryMetadata[`${metric}_sum`] = [
|
||||
{
|
||||
type: 'counter',
|
||||
help: `Total sum of all observed values for the histogram metric (${item.help})`,
|
||||
},
|
||||
];
|
||||
summaryMetadata[`${metric}_bucket`] = {
|
||||
type: 'counter',
|
||||
help: `Cumulative counters for the observation buckets (${item.help})`,
|
||||
};
|
||||
summaryMetadata[`${metric}_count`] = {
|
||||
type: 'counter',
|
||||
help: `Count of events that have been observed for the histogram metric (${item.help})`,
|
||||
};
|
||||
summaryMetadata[`${metric}_sum`] = {
|
||||
type: 'counter',
|
||||
help: `Total sum of all observed values for the histogram metric (${item.help})`,
|
||||
};
|
||||
}
|
||||
if (item.type === 'summary') {
|
||||
summaryMetadata[`${metric}_count`] = [
|
||||
{
|
||||
type: 'counter',
|
||||
help: `Count of events that have been observed for the base metric (${item.help})`,
|
||||
},
|
||||
];
|
||||
summaryMetadata[`${metric}_sum`] = [
|
||||
{
|
||||
type: 'counter',
|
||||
help: `Total sum of all observed values for the base metric (${item.help})`,
|
||||
},
|
||||
];
|
||||
summaryMetadata[`${metric}_count`] = {
|
||||
type: 'counter',
|
||||
help: `Count of events that have been observed for the base metric (${item.help})`,
|
||||
};
|
||||
summaryMetadata[`${metric}_sum`] = {
|
||||
type: 'counter',
|
||||
help: `Total sum of all observed values for the base metric (${item.help})`,
|
||||
};
|
||||
}
|
||||
}
|
||||
// Synthetic series
|
||||
const syntheticMetadata: PromMetricsMetadata = {};
|
||||
syntheticMetadata['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.',
|
||||
},
|
||||
];
|
||||
syntheticMetadata['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.',
|
||||
};
|
||||
|
||||
return { ...metadata, ...summaryMetadata, ...syntheticMetadata };
|
||||
return { ...baseMetadata, ...summaryMetadata, ...syntheticMetadata };
|
||||
}
|
||||
|
||||
export function roundMsToMin(milliseconds: number): number {
|
||||
|
||||
Reference in New Issue
Block a user