The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/unified/utils/labels.ts

34 lines
888 B

import { Labels } from '../../../../types/unified-alerting-dto';
import { Label } from '../components/rules/state-history/common';
export function labelsToTags(labels: Labels) {
return Object.entries(labels)
.map(([label, value]) => `${label}=${value}`)
.sort();
}
export function objectLabelsToArray(labels: Labels): Label[] {
return Object.entries(labels).map(([label, value]) => [label, value]);
}
export function arrayLabelsToObject(labels: Label[]): Labels {
const labelsObject: Labels = {};
labels.forEach((label: Label) => {
labelsObject[label[0]] = label[1];
});
return labelsObject;
}
export function arrayKeyValuesToObject(
labels: Array<{
key: string;
value: string;
}>
): Labels {
const labelsObject: Labels = {};
labels.forEach((label) => {
label.key && (labelsObject[label.key] = label.value);
});
return labelsObject;
}