Commit 921d672a by Torkel Ödegaard

Worked on alias pattern for InfluxDB 0.9 editor, #1525

parent 5f004f95
...@@ -29,7 +29,7 @@ function (_) { ...@@ -29,7 +29,7 @@ function (_) {
var seriesName = series.name; var seriesName = series.name;
if (self.alias) { if (self.alias) {
seriesName = self.alias; seriesName = self._getSeriesName(series);
} else if (series.tags) { } else if (series.tags) {
var tags = _.map(series.tags, function(value, key) { var tags = _.map(series.tags, function(value, key) {
return key + ': ' + value; return key + ': ' + value;
...@@ -44,6 +44,21 @@ function (_) { ...@@ -44,6 +44,21 @@ function (_) {
return output; return output;
}; };
p._getSeriesName = function(series) {
var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g;
return this.alias.replace(regex, function(match, g1, g2) {
var group = g1 || g2;
if (group === 'm' || group === 'measurement') { return series.name; }
if (group.indexOf('tag_') !== 0) { return match; }
var tag = group.replace('tag_', '');
if (!series.tags) { return match; }
return series.tags[tag];
});
};
p.getAnnotations = function () { p.getAnnotations = function () {
var list = []; var list = [];
var self = this; var self = this;
......
...@@ -9,13 +9,13 @@ define([ ...@@ -9,13 +9,13 @@ define([
var options = { series: [ var options = { series: [
{ {
name: 'cpu', name: 'cpu',
tags: {app: 'test'}, tags: {app: 'test', server: 'server1'},
columns: ['time', 'mean'], columns: ['time', 'mean'],
values: [["2015-05-18T10:57:05Z", 10], ["2015-05-18T10:57:06Z", 12]] values: [["2015-05-18T10:57:05Z", 10], ["2015-05-18T10:57:06Z", 12]]
}, },
{ {
name: 'cpu', name: 'cpu',
tags: {app: 'test2'}, tags: {app: 'test2', server: 'server2'},
columns: ['time', 'mean'], columns: ['time', 'mean'],
values: [["2015-05-18T10:57:05Z", 15], ["2015-05-18T10:57:06Z", 16]] values: [["2015-05-18T10:57:05Z", 15], ["2015-05-18T10:57:06Z", 16]]
} }
...@@ -28,13 +28,13 @@ define([ ...@@ -28,13 +28,13 @@ define([
var result = series.getTimeSeries(); var result = series.getTimeSeries();
expect(result.length).to.be(2); expect(result.length).to.be(2);
expect(result[0].target).to.be('cpu {app: test}'); expect(result[0].target).to.be('cpu {app: test, server: server1}');
expect(result[0].datapoints[0][0]).to.be(10); expect(result[0].datapoints[0][0]).to.be(10);
expect(result[0].datapoints[0][1]).to.be(1431946625000); expect(result[0].datapoints[0][1]).to.be(1431946625000);
expect(result[0].datapoints[1][0]).to.be(12); expect(result[0].datapoints[1][0]).to.be(12);
expect(result[0].datapoints[1][1]).to.be(1431946626000); expect(result[0].datapoints[1][1]).to.be(1431946626000);
expect(result[1].target).to.be('cpu {app: test2}'); expect(result[1].target).to.be('cpu {app: test2, server: server2}');
expect(result[1].datapoints[0][0]).to.be(15); expect(result[1].datapoints[0][0]).to.be(15);
expect(result[1].datapoints[0][1]).to.be(1431946625000); expect(result[1].datapoints[0][1]).to.be(1431946625000);
expect(result[1].datapoints[1][0]).to.be(16); expect(result[1].datapoints[1][0]).to.be(16);
...@@ -52,6 +52,19 @@ define([ ...@@ -52,6 +52,19 @@ define([
}); });
}); });
describe('and alias patterns', function() {
it('should replace patterns', function() {
options.alias = 'alias: $m -> $tag_server ([[measurement]])';
var series = new InfluxSeries(options);
var result = series.getTimeSeries();
expect(result[0].target).to.be('alias: cpu -> server1 (cpu)');
expect(result[1].target).to.be('alias: cpu -> server2 (cpu)');
});
});
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment