Transformation: Add variable support for filter by value regex matcher (#90926)

* add support for template vars in filter by value transformation for regex matcher

* less code is more code

* add test to confirm interpolation works for regex

* suggestions input for regex editor

---------

Co-authored-by: Adela Almasan <adela.almasan@grafana.com>
This commit is contained in:
Nathan Marrs
2024-07-30 17:15:44 -06:00
committed by GitHub
parent 537f1fb857
commit 0a34b51055
3 changed files with 78 additions and 4 deletions

View File

@@ -305,6 +305,51 @@ describe('FilterByValue transformer', () => {
});
});
it('should interpolate dashboard variables for regex matcher', async () => {
mockTransformationsVariableSupport.mockReturnValue(true);
const regex: MatcherConfig<BasicValueMatcherOptions<string | number>> = {
id: ValueMatcherID.regex,
options: { value: '.*thiswillinterpolateto6' },
};
const cfg: DataTransformerConfig<FilterByValueTransformerOptions> = {
id: DataTransformerID.filterByValue,
options: {
type: FilterByValueType.include,
match: FilterByValueMatch.all,
filters: [
{
fieldName: 'numbers',
config: regex,
},
],
},
};
const ctxmock = { interpolate: jest.fn(() => '6') };
await expect(transformDataFrame([cfg], [seriesAWithSingleField], ctxmock)).toEmitValuesWith((received) => {
const processed = received[0];
expect(processed.length).toEqual(1);
expect(processed[0].fields).toEqual([
{
name: 'time',
type: FieldType.time,
values: [6000],
state: {},
},
{
name: 'numbers',
type: FieldType.number,
values: [6],
state: {},
},
]);
});
});
it('should not interpolate dashboard variables when feature toggle is off', async () => {
mockTransformationsVariableSupport.mockReturnValue(false);

View File

@@ -77,9 +77,6 @@ export const filterByValueTransformer: DataTransformerInfo<FilterByValueTransfor
},
},
};
} else if (filter.config.id === ValueMatcherID.regex) {
// Due to colliding syntaxes, interpolating regex filters will cause issues.
return filter;
} else if (filter.config.options.value) {
let value = filter.config.options.value;
if (typeof filter.config.options.value === 'string') {