mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
28 lines
737 B
TypeScript
28 lines
737 B
TypeScript
import { DataSourceApi } from '@grafana/ui';
|
|
|
|
export function makeMockLokiDatasource(labelsAndValues: { [label: string]: string[] }): DataSourceApi {
|
|
const labels = Object.keys(labelsAndValues);
|
|
return {
|
|
metadataRequest: (url: string) => {
|
|
let responseData;
|
|
if (url === '/api/prom/label') {
|
|
responseData = labels;
|
|
} else {
|
|
const match = url.match(/^\/api\/prom\/label\/(\w*)\/values/);
|
|
if (match) {
|
|
responseData = labelsAndValues[match[1]];
|
|
}
|
|
}
|
|
if (responseData) {
|
|
return {
|
|
data: {
|
|
data: responseData,
|
|
},
|
|
};
|
|
} else {
|
|
throw new Error(`Unexpected url error, ${url}`);
|
|
}
|
|
},
|
|
} as any;
|
|
}
|