mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
(cherry picked from commit 9cbc872f22
)
Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
This commit is contained in:
parent
03f54577a5
commit
4044cc9aeb
@ -1,4 +1,4 @@
|
|||||||
import { chunk, flatten, isString } from 'lodash';
|
import { chunk, flatten, isString, isArray } from 'lodash';
|
||||||
import { from, lastValueFrom, Observable, of } from 'rxjs';
|
import { from, lastValueFrom, Observable, of } from 'rxjs';
|
||||||
import { map, mergeMap } from 'rxjs/operators';
|
import { map, mergeMap } from 'rxjs/operators';
|
||||||
import {
|
import {
|
||||||
@ -296,7 +296,9 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
|
|||||||
completeFilter.map(({ key, operator, value, condition }: Filter) => [
|
completeFilter.map(({ key, operator, value, condition }: Filter) => [
|
||||||
this.templateSrv.replace(key, scopedVars || {}),
|
this.templateSrv.replace(key, scopedVars || {}),
|
||||||
operator,
|
operator,
|
||||||
this.templateSrv.replace(value, scopedVars || {}, 'regex'),
|
this.templateSrv.replace(value, scopedVars || {}, (value: string | string[]) => {
|
||||||
|
return isArray(value) && value.length ? `(${value.join('|')})` : value;
|
||||||
|
}),
|
||||||
...(condition ? [condition] : []),
|
...(condition ? [condition] : []),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
@ -113,6 +113,22 @@ describe('CloudMonitoringDataSource', () => {
|
|||||||
|
|
||||||
expect(interpolated[2]).toBe('(filtervalue1|filtervalue2)');
|
expect(interpolated[2]).toBe('(filtervalue1|filtervalue2)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not escape a regex', () => {
|
||||||
|
const templateSrv = initTemplateSrv('/[a-Z]*.html', true);
|
||||||
|
const { ds } = getTestcontext({ templateSrv });
|
||||||
|
const interpolated = ds.interpolateFilters(['resource.label.zone', '=~', '[[test]]'], {});
|
||||||
|
|
||||||
|
expect(interpolated[2]).toBe('/[a-Z]*.html');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not escape an array of regexes but join them as a regex', () => {
|
||||||
|
const templateSrv = initTemplateSrv(['/[a-Z]*.html', '/foo.html'], true);
|
||||||
|
const { ds } = getTestcontext({ templateSrv });
|
||||||
|
const interpolated = ds.interpolateFilters(['resource.label.zone', '=~', '[[test]]'], {});
|
||||||
|
|
||||||
|
expect(interpolated[2]).toBe('(/[a-Z]*.html|/foo.html)');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user