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

This commit is contained in:
Sven Grossmann 2023-12-11 13:51:55 +01:00 committed by GitHub
parent 05dcc7a441
commit e3d14307ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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();

View File

@ -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 }));
}