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/grafana-azure-monitor-datas.../utils/common.ts

62 lines
1.8 KiB

import { map } from 'lodash';
import { rangeUtil } from '@grafana/data';
import TimegrainConverter from '../time_grain_converter';
import { AzureMonitorOption } from '../types';
export const hasOption = (options: AzureMonitorOption[], value: string): boolean =>
options.some((v) => (v.options ? hasOption(v.options, value) : v.value === value));
export const findOptions = (options: AzureMonitorOption[], values: string[] = []) => {
if (values.length === 0) {
return [];
}
const set = values.reduce((accum, item) => {
accum.add(item);
return accum;
}, new Set());
return options.filter((option) => set.has(option.value));
};
export const toOption = (v: { text: string; value: string }) => ({ value: v.value, label: v.text });
export function convertTimeGrainsToMs<T extends { value: string }>(timeGrains: T[]) {
const allowedTimeGrainsMs: number[] = [];
timeGrains.forEach((tg: any) => {
if (tg.value !== 'auto') {
allowedTimeGrainsMs.push(rangeUtil.intervalToMs(TimegrainConverter.createKbnUnitFromISO8601Duration(tg.value)));
}
});
return allowedTimeGrainsMs;
}
// Route definitions shared with the backend.
// Check: /pkg/tsdb/azuremonitor/azuremonitor-resource-handler.go <registerRoutes>
export const routeNames = {
azureMonitor: 'azuremonitor',
logAnalytics: 'loganalytics',
appInsights: 'appinsights',
resourceGraph: 'resourcegraph',
};
export function interpolateVariable(value: any, variable: { multi: any; includeAll: any }) {
if (typeof value === 'string') {
if (variable.multi || variable.includeAll) {
return "'" + value + "'";
} else {
return value;
}
}
if (typeof value === 'number') {
return value;
}
const quotedValues = map(value, (val) => {
if (typeof value === 'number') {
return value;
}
return "'" + val + "'";
});
return quotedValues.join(',');
}