implement replaceAlias() function, #287
This commit is contained in:
@@ -168,6 +168,19 @@ function setAlias(alias, timeseries) {
|
||||
return timeseries;
|
||||
}
|
||||
|
||||
function replaceAlias(regexp, newAlias, timeseries) {
|
||||
let pattern;
|
||||
if (utils.isRegex(regexp)) {
|
||||
pattern = utils.buildRegex(regexp);
|
||||
} else {
|
||||
pattern = regexp;
|
||||
}
|
||||
|
||||
let alias = timeseries.target.replace(pattern, newAlias);
|
||||
timeseries.target = alias;
|
||||
return timeseries;
|
||||
}
|
||||
|
||||
function setAliasByRegex(alias, timeseries) {
|
||||
timeseries.target = extractText(timeseries.target, alias);
|
||||
return timeseries;
|
||||
@@ -308,7 +321,8 @@ let metricFunctions = {
|
||||
bottom: _.partial(limit, 'bottom'),
|
||||
timeShift: timeShift,
|
||||
setAlias: setAlias,
|
||||
setAliasByRegex: setAliasByRegex
|
||||
setAliasByRegex: setAliasByRegex,
|
||||
replaceAlias: replaceAlias
|
||||
};
|
||||
|
||||
let aggregationFunctions = {
|
||||
@@ -338,4 +352,4 @@ export default {
|
||||
get metricFunctions() {
|
||||
return metricFunctions;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -187,6 +187,16 @@ addFuncDef({
|
||||
defaultParams: []
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'replaceAlias',
|
||||
category: 'Alias',
|
||||
params: [
|
||||
{ name: 'regexp', type: 'string' },
|
||||
{ name: 'newAlias', type: 'string' }
|
||||
],
|
||||
defaultParams: ['/(.*)/', '$1']
|
||||
});
|
||||
|
||||
_.each(categories, function(funcList, catName) {
|
||||
categories[catName] = _.sortBy(funcList, 'name');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user