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/plugins/datasource/graphite/configuration/parseLokiLabelMappings.ts

31 lines
911 B

import { GraphiteLokiMapping } from '../types';
/**
* Converts a simple string used in LokiLogsMappings component (e.g. "servers.(name).*")
* to data model saved in data source configuration.
*/
export function fromString(text: string): GraphiteLokiMapping {
return {
matchers: text.split('.').map((metricNode) => {
if (metricNode.startsWith('(') && metricNode.endsWith(')')) {
return {
value: '*',
labelName: metricNode.slice(1, -1),
};
} else {
return { value: metricNode };
}
}),
};
}
/**
* Coverts configuration stored in data source configuration into a string displayed in LokiLogsMappings component.
*/
export function toString(mapping: GraphiteLokiMapping): string {
return mapping.matchers
.map((matcher) => {
return matcher.labelName ? `(${matcher.labelName})` : `${matcher.value}`;
})
.join('.');
}