mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
feat(influxdb): More alias options, can now use syntax to reference part of a measurement name (seperated by dots), closes #2599
This commit is contained in:
@@ -56,12 +56,15 @@ function (_) {
|
||||
|
||||
p._getSeriesName = function(series, index) {
|
||||
var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g;
|
||||
var segments = series.name.split('.');
|
||||
|
||||
return this.alias.replace(regex, function(match, g1, g2) {
|
||||
var group = g1 || g2;
|
||||
var segIndex = parseInt(group, 10)
|
||||
|
||||
if (group === 'm' || group === 'measurement') { return series.name; }
|
||||
if (group === 'col') { return series.columns[index]; }
|
||||
if (!isNaN(segIndex)) { return segments[segIndex]; }
|
||||
if (group.indexOf('tag_') !== 0) { return match; }
|
||||
|
||||
var tag = group.replace('tag_', '');
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<ul>
|
||||
<li>$m = replaced with measurement name</li>
|
||||
<li>$measurement = replaced with measurement name</li>
|
||||
<li>$1 - $9 = replaced with part of measurement name (if you seperate your measurement name with dots)</li>
|
||||
<li>$col = replaced with column name</li>
|
||||
<li>$tag_hostname = replaced with the value of the hostname tag</li>
|
||||
<li>You can also use [[tag_hostname]] pattern replacement syntax</li>
|
||||
|
||||
@@ -157,6 +157,24 @@ define([
|
||||
|
||||
});
|
||||
|
||||
describe('given measurement with dots', function() {
|
||||
var options = { series: [
|
||||
{
|
||||
name: 'app.prod.server1.count',
|
||||
tags: {},
|
||||
columns: ['time', 'mean'],
|
||||
values: [[1431946625000, 10], [1431946626000, 12]]
|
||||
}
|
||||
]};
|
||||
|
||||
it('should replace patterns', function() {
|
||||
options.alias = 'alias: $1 -> [[3]]';
|
||||
var series = new InfluxSeries(options);
|
||||
var result = series.getTimeSeries();
|
||||
|
||||
expect(result[0].target).to.be('alias: prod -> count');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user