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:
Torkel Ödegaard 2015-09-04 07:40:28 +02:00
parent 97d42991a7
commit ead451a979
4 changed files with 24 additions and 1 deletions

View File

@ -14,6 +14,7 @@ it allows you to add queries of differnet data source types & instances to the s
- [Issue #2577](https://github.com/grafana/grafana/issues/2577). Panel: Resize handles in panel bottom right corners for easy width and height change
- [Issue #2457](https://github.com/grafana/grafana/issues/2457). Admin: admin page for all grafana organizations (list / edit view)
- [Issue #1186](https://github.com/grafana/grafana/issues/1186). Time Picker: New option `today`, will set time range from midnight to now
- [Issue #1186](https://github.com/grafana/grafana/issues/1186). Time Picker: New option `today`, will set time range from midnight to now
**Fixes**
- [Issue #2413](https://github.com/grafana/grafana/issues/2413). InfluxDB 0.9: Fix for handling empty series object in response from influxdb
@ -25,7 +26,7 @@ it allows you to add queries of differnet data source types & instances to the s
- [Issue #2564](https://github.com/grafana/grafana/issues/2564). Templating: Another atempt at fixing #2534 (Init multi value template var used in repeat panel from url)
- [Issue #2620](https://github.com/grafana/grafana/issues/2620). Graph: multi series tooltip did no highlight correct point when stacking was enabled and series were of different resolution
- [Issue #2636](https://github.com/grafana/grafana/issues/2636). InfluxDB: Do no show template vars in dropdown for tag keys and group by keys
- [Issue #2651](https://github.com/grafana/grafana/issues/2651). InfluxDB: Fixed issue when using the eye to disable queries in the query editor and when applying aliases
- [Issue #2599](https://github.com/grafana/grafana/issues/2599). InfluxDB: More alias options, can now use `$[0-9]` syntax to reference part of a measurement name (seperated by dots)
**Breaking Changes**
- Notice to makers/users of custom data sources, there is a minor breaking change in 2.2 that

View File

@ -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_', '');

View File

@ -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>

View File

@ -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');
});
});
});
});