Skip to content

Commit 7bc15ec

Browse files
utkarshcmutorkelo
authored andcommitted
[Bug Fix] Opentsdb Alias issue (grafana#4910)
* Fixed Opentsdb Alias issue * Fixed Opentsdb query editor
1 parent e502115 commit 7bc15ec

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

public/app/plugins/datasource/opentsdb/config_ctrl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class OpenTsConfigCtrl {
1616

1717
tsdbVersions = [
1818
{name: '<=2.1', value: 1},
19-
{name: '>=2.2', value: 2},
19+
{name: '==2.2', value: 2},
20+
{name: '==2.3', value: 3},
2021
];
2122

2223
tsdbResolutions = [

public/app/plugins/datasource/opentsdb/datasource.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ function (angular, _, dateMath) {
5454
});
5555

5656
return this.performTimeSeriesQuery(queries, start, end).then(function(response) {
57-
var metricToTargetMapping = mapMetricsToTargets(response.data, options);
57+
var metricToTargetMapping = mapMetricsToTargets(response.data, options, this.tsdbVersion);
5858
var result = _.map(response.data, function(metricData, index) {
5959
index = metricToTargetMapping[index];
6060
if (index === -1) {
6161
index = 0;
6262
}
63-
6463
this._saveTagKeys(metricData);
6564

6665
return transformMetricData(metricData, groupByTags, options.targets[index], options, this.tsdbResolution);
@@ -114,6 +113,9 @@ function (angular, _, dateMath) {
114113
msResolution: msResolution,
115114
globalAnnotations: true
116115
};
116+
if (this.tsdbVersion === 3) {
117+
reqBody.showQuery = true;
118+
}
117119

118120
// Relative queries (e.g. last hour) don't include an end time
119121
if (end) {
@@ -393,23 +395,27 @@ function (angular, _, dateMath) {
393395
return query;
394396
}
395397

396-
function mapMetricsToTargets(metrics, options) {
398+
function mapMetricsToTargets(metrics, options, tsdbVersion) {
397399
var interpolatedTagValue;
398400
return _.map(metrics, function(metricData) {
399-
return _.findIndex(options.targets, function(target) {
400-
if (target.filters && target.filters.length > 0) {
401-
return target.metric === metricData.metric &&
402-
_.all(target.filters, function(filter) {
403-
return filter.tagk === interpolatedTagValue === "*";
404-
});
405-
} else {
406-
return target.metric === metricData.metric &&
407-
_.all(target.tags, function(tagV, tagK) {
408-
interpolatedTagValue = templateSrv.replace(tagV, options.scopedVars, 'pipe');
409-
return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*";
410-
});
411-
}
412-
});
401+
if (tsdbVersion === 3) {
402+
return metricData.query.index;
403+
} else {
404+
return _.findIndex(options.targets, function(target) {
405+
if (target.filters && target.filters.length > 0) {
406+
return target.metric === metricData.metric &&
407+
_.all(target.filters, function(filter) {
408+
return filter.tagk === interpolatedTagValue === "*";
409+
});
410+
} else {
411+
return target.metric === metricData.metric &&
412+
_.all(target.tags, function(tagV, tagK) {
413+
interpolatedTagValue = templateSrv.replace(tagV, options.scopedVars, 'pipe');
414+
return metricData.tags[tagK] === interpolatedTagValue || interpolatedTagValue === "*";
415+
});
416+
}
417+
});
418+
}
413419
});
414420
}
415421

public/app/plugins/datasource/opentsdb/partials/query.editor.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</div>
7070
</div>
7171

72-
<div class="gf-form" ng-if="ctrl.tsdbVersion == 2">
72+
<div class="gf-form" ng-if="ctrl.tsdbVersion >= 2">
7373
<label class="gf-form-label query-keyword width-6">Fill</label>
7474
<div class="gf-form-select-wrapper">
7575
<select ng-model="ctrl.target.downsampleFillPolicy" class="gf-form-input"
@@ -91,7 +91,7 @@
9191
</div>
9292
</div>
9393

94-
<div class="gf-form-inline" ng-if="ctrl.tsdbVersion == 2">
94+
<div class="gf-form-inline" ng-if="ctrl.tsdbVersion >= 2">
9595
<div class="gf-form">
9696

9797
<label class="gf-form-label query-keyword width-8">
@@ -170,7 +170,7 @@
170170
<div class="gf-form">
171171
<label class="gf-form-label query-keyword width-8">
172172
Tags
173-
<info-popover mode="right-normal" ng-if="ctrl.tsdbVersion == 2">
173+
<info-popover mode="right-normal" ng-if="ctrl.tsdbVersion >= 2">
174174
Please use filters, tags are deprecated in opentsdb 2.2
175175
</info-popover>
176176
</label>

0 commit comments

Comments
 (0)