Skip to content

Commit

Permalink
InfluxDB: Support more than 10 series name segments when using alias …
Browse files Browse the repository at this point in the history
…patterns, Closes #1126
  • Loading branch information
torkelo committed Dec 17, 2014
1 parent 5a46c23 commit a58330f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Enhancements**
- [Issue #1028](https://github.com/grafana/grafana/issues/1028). Graph: New legend option ``hideEmtpy`` to hide series with only null values from legend
- [Issue #1242](https://github.com/grafana/grafana/issues/1242). OpenTSDB: Downsample query field now supports interval template variable
- [Issue #1126](https://github.com/grafana/grafana/issues/1126). InfluxDB: Support more than 10 series name segments when using alias ``$number`` patterns

**Fixes**
- [Issue #1199](https://github.com/grafana/grafana/issues/1199). Graph: fix for series tooltip when one series is hidden/disabled
Expand Down
26 changes: 14 additions & 12 deletions src/app/services/influxdb/influxSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,23 @@ function (_) {
};

p.createNameForSeries = function(seriesName, groupByColValue) {
var name = this.alias
.replace('$s', seriesName);

var regex = /\$(\w+)/g;
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 this.alias.replace(regex, function(match, group) {
if (group === 's') {
return seriesName;
}
else if (group === 'g') {
return groupByColValue;
}
var index = parseInt(group);
if (_.isNumber(index) && index < segments.length) {
return segments[index];
}
return match;
});

return name;
};

return InfluxSeries;
Expand Down
21 changes: 21 additions & 0 deletions src/test/specs/influxSeries-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ define([

});

describe('given an alias format and many segments', function() {
var series = new InfluxSeries({
seriesList: [
{
columns: ['time', 'mean', 'sequence_number'],
name: 'a0.a1.a2.a3.a4.a5.a6.a7.a8.a9.a10.a11.a12',
points: [[1402596000, 10, 1], [1402596001, 12, 2]]
}
],
alias: '$5.$11.mean'
});

var result = series.getTimeSeries();

it('should generate correct series name', function() {
expect(result[0].target).to.be('a5.a11.mean');
});

});


describe('given an alias format with group by field', function() {
var series = new InfluxSeries({
seriesList: [
Expand Down

0 comments on commit a58330f

Please sign in to comment.