Enhanced InfluxDB series aliasing (legend names) with pattern replacements (Issue #525)
This commit is contained in:
@@ -3,6 +3,7 @@ vNext
|
|||||||
**New features or improvements**
|
**New features or improvements**
|
||||||
- Allow [[..]] filter notation in all text panels (markdown/html/text) (Issue #511)
|
- Allow [[..]] filter notation in all text panels (markdown/html/text) (Issue #511)
|
||||||
- New legend display option "Align as table" (Issue #136)
|
- New legend display option "Align as table" (Issue #136)
|
||||||
|
- Enhanced InfluxDB series aliasing (legend names) with pattern replacements (Issue #525)
|
||||||
|
|
||||||
**Changes**
|
**Changes**
|
||||||
- Use unix epoch for Graphite from/to for absolute time ranges (Closes #536)
|
- Use unix epoch for Graphite from/to for absolute time ranges (Closes #536)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ function (_) {
|
|||||||
p.getTimeSeries = function() {
|
p.getTimeSeries = function() {
|
||||||
var output = [];
|
var output = [];
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var i;
|
||||||
|
|
||||||
_.each(self.seriesList, function(series) {
|
_.each(self.seriesList, function(series) {
|
||||||
var seriesName;
|
var seriesName;
|
||||||
@@ -46,16 +47,15 @@ function (_) {
|
|||||||
|
|
||||||
_.each(groups, function(groupPoints, key) {
|
_.each(groups, function(groupPoints, key) {
|
||||||
var datapoints = [];
|
var datapoints = [];
|
||||||
for (var i = 0; i < groupPoints.length; i++) {
|
for (i = 0; i < groupPoints.length; i++) {
|
||||||
var metricValue = isNaN(groupPoints[i][valueCol]) ? null : groupPoints[i][valueCol];
|
var metricValue = isNaN(groupPoints[i][valueCol]) ? null : groupPoints[i][valueCol];
|
||||||
datapoints[i] = [metricValue, groupPoints[i][timeCol]];
|
datapoints[i] = [metricValue, groupPoints[i][timeCol]];
|
||||||
}
|
}
|
||||||
|
|
||||||
seriesName = self.alias ? self.alias : (series.name + '.' + key);
|
seriesName = series.name + '.' + key;
|
||||||
|
|
||||||
// if mulitple groups append key to alias
|
if (self.alias) {
|
||||||
if (self.alias && self.groupByField) {
|
seriesName = self.createNameForSeries(series.name, series.columns[valueCol], key);
|
||||||
seriesName += key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.push({ target: seriesName, datapoints: datapoints });
|
output.push({ target: seriesName, datapoints: datapoints });
|
||||||
@@ -65,5 +65,24 @@ function (_) {
|
|||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
p.createNameForSeries = function(seriesName, columnName, groupByColValue) {
|
||||||
|
var name = this.alias
|
||||||
|
.replace('$s', seriesName)
|
||||||
|
.replace('$c', columnName);
|
||||||
|
|
||||||
|
var segments = seriesName.split('.');
|
||||||
|
for (var i = 0; i < segments.length; i++) {
|
||||||
|
if (segments[i].length > 0) {
|
||||||
|
name = name.replace('$' + i, segments[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.groupByField) {
|
||||||
|
name = name.replace('$g', groupByColValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
return InfluxSeries;
|
return InfluxSeries;
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
define([
|
||||||
|
'services/influxdb/influxSeries'
|
||||||
|
], function(InfluxSeries) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('when generating timeseries from influxdb response', function() {
|
||||||
|
|
||||||
|
describe('given two series', function() {
|
||||||
|
var series = new InfluxSeries({
|
||||||
|
seriesList: [
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'sequence_number'],
|
||||||
|
name: 'prod.server1.cpu',
|
||||||
|
points: [[1402596000, 10, 1], [1402596001, 12, 2]]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'sequence_number'],
|
||||||
|
name: 'prod.server2.cpu',
|
||||||
|
points: [[1402596000, 15, 1], [1402596001, 16, 2]]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = series.getTimeSeries();
|
||||||
|
|
||||||
|
it('should generate two time series', function() {
|
||||||
|
expect(result.length).to.be(2);
|
||||||
|
expect(result[0].target).to.be('prod.server1.cpu.mean');
|
||||||
|
expect(result[0].datapoints[0][0]).to.be(10);
|
||||||
|
expect(result[0].datapoints[0][1]).to.be(1402596000);
|
||||||
|
expect(result[0].datapoints[1][0]).to.be(12);
|
||||||
|
expect(result[0].datapoints[1][1]).to.be(1402596001);
|
||||||
|
|
||||||
|
expect(result[1].target).to.be('prod.server2.cpu.mean');
|
||||||
|
expect(result[1].datapoints[0][0]).to.be(15);
|
||||||
|
expect(result[1].datapoints[0][1]).to.be(1402596000);
|
||||||
|
expect(result[1].datapoints[1][0]).to.be(16);
|
||||||
|
expect(result[1].datapoints[1][1]).to.be(1402596001);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given an alias format', function() {
|
||||||
|
var series = new InfluxSeries({
|
||||||
|
seriesList: [
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'sequence_number'],
|
||||||
|
name: 'prod.server1.cpu',
|
||||||
|
points: [[1402596000, 10, 1], [1402596001, 12, 2]]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
alias: '$s.$c'
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = series.getTimeSeries();
|
||||||
|
|
||||||
|
it('should generate correct series name', function() {
|
||||||
|
expect(result[0].target).to.be('prod.server1.cpu.mean');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given an alias format with segment numbers', function() {
|
||||||
|
var series = new InfluxSeries({
|
||||||
|
seriesList: [
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'sequence_number'],
|
||||||
|
name: 'prod.server1.cpu',
|
||||||
|
points: [[1402596000, 10, 1], [1402596001, 12, 2]]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
alias: '$1'
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = series.getTimeSeries();
|
||||||
|
|
||||||
|
it('should generate correct series name', function() {
|
||||||
|
expect(result[0].target).to.be('server1');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given an alias format with group by field', function() {
|
||||||
|
var series = new InfluxSeries({
|
||||||
|
seriesList: [
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'host'],
|
||||||
|
name: 'prod.cpu',
|
||||||
|
points: [[1402596000, 10, 'A']]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
groupByField: 'host',
|
||||||
|
alias: '$g.$1'
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = series.getTimeSeries();
|
||||||
|
|
||||||
|
it('should generate correct series name', function() {
|
||||||
|
expect(result[0].target).to.be('A.cpu');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given group by column', function() {
|
||||||
|
var series = new InfluxSeries({
|
||||||
|
seriesList: [
|
||||||
|
{
|
||||||
|
columns: ['time', 'mean', 'host'],
|
||||||
|
name: 'prod.cpu',
|
||||||
|
points: [
|
||||||
|
[1402596000, 10, 'A'],
|
||||||
|
[1402596001, 11, 'A'],
|
||||||
|
[1402596000, 5, 'B'],
|
||||||
|
[1402596001, 6, 'B'],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
groupByField: 'host'
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = series.getTimeSeries();
|
||||||
|
|
||||||
|
it('should generate two time series', function() {
|
||||||
|
expect(result.length).to.be(2);
|
||||||
|
expect(result[0].target).to.be('prod.cpu.A');
|
||||||
|
expect(result[0].datapoints[0][0]).to.be(10);
|
||||||
|
expect(result[0].datapoints[0][1]).to.be(1402596000);
|
||||||
|
expect(result[0].datapoints[1][0]).to.be(11);
|
||||||
|
expect(result[0].datapoints[1][1]).to.be(1402596001);
|
||||||
|
|
||||||
|
expect(result[1].target).to.be('prod.cpu.B');
|
||||||
|
expect(result[1].datapoints[0][0]).to.be(5);
|
||||||
|
expect(result[1].datapoints[0][1]).to.be(1402596000);
|
||||||
|
expect(result[1].datapoints[1][0]).to.be(6);
|
||||||
|
expect(result[1].datapoints[1][1]).to.be(1402596001);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@@ -128,8 +128,10 @@ require([
|
|||||||
'specs/gfunc-specs',
|
'specs/gfunc-specs',
|
||||||
'specs/filterSrv-specs',
|
'specs/filterSrv-specs',
|
||||||
'specs/kbn-format-specs',
|
'specs/kbn-format-specs',
|
||||||
|
'specs/influxSeries-specs'
|
||||||
], function () {
|
], function () {
|
||||||
window.__karma__.start();
|
window.__karma__.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user