mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Loki: Label browser - replaces stream cascader widget which made it hard to find relevant streams - multi-step selection allows for selecting a couple of labels first, then find the relevant values - supports facetting which makes impossible label combinations hard to choose * Remove unused label hook * Remove unused label styles * Use global time range for metadata requests * Preselect labels if not many exist * Status and error messages * Status fixes * Remove unused import * Added logs rate button * Close popup when clicked outside (not working for timepicker :( ) * Change button label * Get rid of popup and render browser inline * Review feedback * Wrap label values and prevent empty lists Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { LokiDatasource, LOKI_ENDPOINT } from './datasource';
|
|
import { AbsoluteTimeRange, DataSourceSettings } from '@grafana/data';
|
|
import { LokiOptions } from './types';
|
|
import { createDatasourceSettings } from '../../../features/datasources/mocks';
|
|
|
|
interface Labels {
|
|
[label: string]: string[];
|
|
}
|
|
|
|
interface Series {
|
|
[label: string]: string;
|
|
}
|
|
|
|
interface SeriesForSelector {
|
|
[selector: string]: Series[];
|
|
}
|
|
|
|
export function makeMockLokiDatasource(labelsAndValues: Labels, series?: SeriesForSelector): LokiDatasource {
|
|
const lokiLabelsAndValuesEndpointRegex = /^\/loki\/api\/v1\/label\/(\w*)\/values/;
|
|
const lokiSeriesEndpointRegex = /^\/loki\/api\/v1\/series/;
|
|
|
|
const lokiLabelsEndpoint = `${LOKI_ENDPOINT}/label`;
|
|
const rangeMock: AbsoluteTimeRange = {
|
|
from: 1560153109000,
|
|
to: 1560163909000,
|
|
};
|
|
|
|
const labels = Object.keys(labelsAndValues);
|
|
return {
|
|
getTimeRangeParams: () => rangeMock,
|
|
metadataRequest: (url: string, params?: { [key: string]: string }) => {
|
|
if (url === lokiLabelsEndpoint) {
|
|
return labels;
|
|
} else {
|
|
const labelsMatch = url.match(lokiLabelsAndValuesEndpointRegex);
|
|
const seriesMatch = url.match(lokiSeriesEndpointRegex);
|
|
if (labelsMatch) {
|
|
return labelsAndValues[labelsMatch[1]] || [];
|
|
} else if (seriesMatch && series && params) {
|
|
return series[params.match] || [];
|
|
} else {
|
|
throw new Error(`Unexpected url error, ${url}`);
|
|
}
|
|
}
|
|
},
|
|
} as any;
|
|
}
|
|
|
|
export function createDefaultConfigOptions(): DataSourceSettings<LokiOptions> {
|
|
return createDatasourceSettings<LokiOptions>({
|
|
maxLines: '531',
|
|
});
|
|
}
|