diff --git a/public/app/plugins/datasource/prometheus/language_provider.test.ts b/public/app/plugins/datasource/prometheus/language_provider.test.ts index b751647be22..406d2db26ac 100644 --- a/public/app/plugins/datasource/prometheus/language_provider.test.ts +++ b/public/app/plugins/datasource/prometheus/language_provider.test.ts @@ -274,6 +274,27 @@ describe('Language completion provider', () => { undefined ); }); + + it('should call old series endpoint and should use match[] parameter and interpolate the template variables', () => { + const languageProvider = new LanguageProvider({ + ...defaultDatasource, + interpolateString: (string: string) => string.replace(/\$/, 'interpolated-'), + } as PrometheusDatasource); + const getSeriesValues = languageProvider.getSeriesValues; + const requestSpy = jest.spyOn(languageProvider, 'request'); + getSeriesValues('job', '{instance="$instance", job="grafana"}'); + expect(requestSpy).toHaveBeenCalled(); + expect(requestSpy).toHaveBeenCalledWith( + '/api/v1/series', + [], + { + end: toPrometheusTimeString, + 'match[]': '{instance="interpolated-instance", job="grafana"}', + start: fromPrometheusTimeString, + }, + undefined + ); + }); }); describe('fetchSeries', () => { diff --git a/public/app/plugins/datasource/prometheus/language_provider.ts b/public/app/plugins/datasource/prometheus/language_provider.ts index 6067cfba8d7..a1397517365 100644 --- a/public/app/plugins/datasource/prometheus/language_provider.ts +++ b/public/app/plugins/datasource/prometheus/language_provider.ts @@ -567,10 +567,11 @@ export default class PromQlLanguageProvider extends LanguageProvider { */ fetchSeriesValuesWithMatch = async (name: string, match?: string): Promise => { const interpolatedName = name ? this.datasource.interpolateString(name) : null; + const interpolatedMatch = match ? this.datasource.interpolateString(match) : null; const range = this.datasource.getAdjustedInterval(); const urlParams = { ...range, - ...(match && { 'match[]': match }), + ...(interpolatedMatch && { 'match[]': interpolatedMatch }), }; // @todo clean up prometheusResourceBrowserCache feature flag