Skip to content

Commit

Permalink
Merge pull request #1005 from n9e/refactor-0904
Browse files Browse the repository at this point in the history
fix: escape promQL ccfos/nightingale#2163
  • Loading branch information
jsers authored Sep 14, 2024
2 parents 4a4d577 + 0a0a99e commit 2ab3240
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/pages/metricsBuiltin/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default function index() {
} catch (e) {
console.error(e);
}
console.log('label_filter', label_filter, record.expression);
if (label_filter) {
buildLabelFilterAndExpression({
label_filter,
Expand Down
10 changes: 9 additions & 1 deletion src/pages/metricsBuiltin/components/Filters/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import { escapePromQLString } from '@/pages/dashboard/VariableConfig/utils';

export function filtersToStr(
filters: {
Expand All @@ -15,6 +16,13 @@ export function filtersToStr(
return '';
}),
);
const str = _.join(_.compact(arr), ',');
const str = _.join(
_.compact(
_.map(arr, (item) => {
return escapePromQLString(item);
}),
),
',',
);
return str ? `{${str}}` : '';
}
25 changes: 16 additions & 9 deletions src/pages/monitor/object/metricViews/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
*
*/
import _ from 'lodash';
import { escapePromQLString } from '@/pages/dashboard/VariableConfig/utils';
import { IMatch } from '../types';


export function getFiltersStr(filters: IMatch['filters']) {
const arr = _.compact(_.map(filters, (item) => {
if (item.label && item.value) {
return `${item.label}${item.oper}"${item.value}"`;
}
return '';
}));
const arr = _.compact(
_.map(filters, (item) => {
if (item.label && item.value) {
return `${item.label}${item.oper}"${item.value}"`;
}
return '';
}),
);
return _.join(_.compact(arr), ',');
}

Expand All @@ -41,10 +43,15 @@ export function getDynamicLabelsStr(dynamicLabels: IMatch['dynamicLabels']) {
export function getMatchStr(match: IMatch) {
const arr = _.map(match.dimensionLabels, (item) => {
if (!_.isEmpty(item.value)) {
return `${item.label}=~"${_.join(item.value, '|')}"`;
return `${item.label}=~"${_.join(
_.map(item.value, (item) => {
return escapePromQLString(item);
}),
'|',
)}"`;
}
return '';
});
const str = _.join(_.compact(arr), ',');
return str ? `{${str}}` : '';
}
}

0 comments on commit 2ab3240

Please sign in to comment.