mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix fetching label values when datasource has no labels match api support (#72960)
* interpolate match string * provide unit test * add the third parameter back to fix the unit test
This commit is contained in:
parent
6ac3348021
commit
29906847e1
@ -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', () => {
|
||||
|
@ -567,10 +567,11 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
||||
*/
|
||||
fetchSeriesValuesWithMatch = async (name: string, match?: string): Promise<string[]> => {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user