mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Fix values variable with unexisting label and stream selector (#79310)
This commit is contained in:
parent
05dcc7a441
commit
e3d14307ed
@ -484,6 +484,21 @@ describe('LokiDatasource', () => {
|
||||
return { ds };
|
||||
};
|
||||
|
||||
it('should return empty array if /series returns empty', async () => {
|
||||
const ds = createLokiDatasource(templateSrvStub);
|
||||
const spy = jest.spyOn(ds.languageProvider, 'fetchSeriesLabels').mockResolvedValue({});
|
||||
|
||||
const result = await ds.metricFindQuery({
|
||||
refId: 'test',
|
||||
type: LokiVariableQueryType.LabelValues,
|
||||
stream: '{label1="value1"}',
|
||||
label: 'label2',
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
spy.mockClear();
|
||||
});
|
||||
|
||||
it('should return label names for Loki', async () => {
|
||||
const { ds } = getTestContext();
|
||||
|
||||
|
@ -685,6 +685,9 @@ export class LokiDatasource
|
||||
// If we have stream selector, use /series endpoint
|
||||
if (query.stream) {
|
||||
const result = await this.languageProvider.fetchSeriesLabels(query.stream, { timeRange });
|
||||
if (!result[query.label]) {
|
||||
return [];
|
||||
}
|
||||
return result[query.label].map((value: string) => ({ text: value }));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user