Commit f1905a84 by Torkel Ödegaard

fix(alerting): fixed issue with using nested queries in graphite query used in…

fix(alerting): fixed issue with using nested queries in graphite query used in alerting rule, fixes #5996
parent 446bde24
......@@ -57,8 +57,12 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
}
for _, query := range queries {
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
formData["target"] = []string{fullTarget}
} else {
formData["target"] = []string{query.Model.Get("target").MustString()}
}
}
if setting.Env == setting.DEV {
glog.Debug("Graphite request", "params", formData)
......
......@@ -209,17 +209,40 @@ export class GraphiteQueryCtrl extends QueryCtrl {
this.panelCtrl.refresh();
}
updateModelTarget() {
// render query
var metricPath = this.getSegmentPathUpTo(this.segments.length);
this.target.target = _.reduce(this.functions, this.wrapFunction, metricPath);
// render nested query
var targetsByRefId = _.keyBy(this.panelCtrl.panel.targets, 'refId');
var nestedSeriesRefRegex = /\#([A-Z])/g;
var targetWithNestedQueries = this.target.target.replace(nestedSeriesRefRegex, (match, g1) => {
var target = targetsByRefId[g1];
if (!target) {
return match;
}
return target.targetFull || target.target;
});
delete this.target.targetFull;
if (this.target.target !== targetWithNestedQueries) {
this.target.targetFull = targetWithNestedQueries;
}
}
targetChanged() {
if (this.error) {
return;
}
var oldTarget = this.target.target;
var target = this.getSegmentPathUpTo(this.segments.length);
this.target.target = _.reduce(this.functions, this.wrapFunction, target);
this.updateModelTarget();
if (this.target.target !== oldTarget) {
if (this.segments[this.segments.length - 1].value !== 'select metric') {
var lastSegment = this.segments.length > 0 ? this.segments[this.segments.length - 1] : {};
if (lastSegment.value !== 'select metric') {
this.panelCtrl.refresh();
}
}
......
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