Loki: Fix values variable with unexisting label and stream selector (#79310)

This commit is contained in:
Sven Grossmann
2023-12-11 14:51:55 +02:00
committed by GitHub
parent 05dcc7a441
commit e3d14307ed
2 changed files with 18 additions and 0 deletions
@@ -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 }));
}