Fix: Timeseries migration regex override (#49629)

This commit is contained in:
Zoltán Bedi 2022-05-30 16:27:53 +02:00 committed by GitHub
parent 6554bbd70f
commit 3d3cf74038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View File

@ -141,6 +141,21 @@ Object {
},
],
},
Object {
"matcher": Object {
"id": "byName",
"options": "B-series",
},
"properties": Array [
Object {
"id": "color",
"value": Object {
"fixedColor": "rgba(16, 72, 170, 0.77)",
"mode": "fixed",
},
},
],
},
],
},
"options": Object {
@ -197,6 +212,21 @@ Object {
},
],
},
Object {
"matcher": Object {
"id": "byRegexp",
"options": "/.*Status: 2[0-9]+.*/i",
},
"properties": Array [
Object {
"id": "color",
"value": Object {
"fixedColor": "rgba(16, 72, 170, 0.77)",
"mode": "fixed",
},
},
],
},
],
},
"options": Object {

View File

@ -1,6 +1,6 @@
import { cloneDeep } from 'lodash';
import { PanelModel, FieldConfigSource } from '@grafana/data';
import { PanelModel, FieldConfigSource, FieldMatcherID } from '@grafana/data';
import { TooltipDisplayMode, SortOrder } from '@grafana/schema';
import { graphPanelChangedHandler } from './migrations';
@ -78,6 +78,8 @@ describe('Graph Migrations', () => {
const panel = {} as PanelModel;
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
expect(panel).toMatchSnapshot();
expect(panel.fieldConfig.overrides[0].matcher.id).toBe(FieldMatcherID.byRegexp);
expect(panel.fieldConfig.overrides[1].matcher.id).toBe(FieldMatcherID.byRegexp);
});
describe('legend', () => {
@ -479,6 +481,11 @@ const customColor = {
alias: 'A-series',
color: 'rgba(165, 72, 170, 0.77)',
},
{
$$hashKey: 'object:13',
alias: 'B-series',
color: 'rgba(16, 72, 170, 0.77)',
},
],
spaceLength: 10,
steppedLine: true,
@ -536,6 +543,7 @@ const customColor = {
const customColorRegex = cloneDeep(customColor);
customColorRegex.seriesOverrides[0].alias = '/^A-/';
customColorRegex.seriesOverrides[1].alias = '/.*Status: 2[0-9]+.*/i';
const stairscase = {
aliasColors: {},

View File

@ -119,7 +119,7 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
if (!seriesOverride.alias) {
continue; // the matcher config
}
const aliasIsRegex = seriesOverride.alias.startsWith('/') && seriesOverride.alias.endsWith('/');
const aliasIsRegex = /^([/~@;%#'])(.*?)\1([gimsuy]*)$/.test(seriesOverride.alias);
const rule: ConfigOverrideRule = {
matcher: {
id: aliasIsRegex ? FieldMatcherID.byRegexp : FieldMatcherID.byName,