diff --git a/public/app/plugins/datasource/loki/datasource.test.ts b/public/app/plugins/datasource/loki/datasource.test.ts index 743b1be7e31..73bc87ece4d 100644 --- a/public/app/plugins/datasource/loki/datasource.test.ts +++ b/public/app/plugins/datasource/loki/datasource.test.ts @@ -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(); diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index d76636f6b9f..f72d7b82dfa 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -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 })); }