mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
fix(alerting): fixed issue with using nested queries in graphite query used in alerting rule, fixes #5996
This commit is contained in:
parent
446bde2421
commit
f1905a8485
@ -57,7 +57,11 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
|
||||
}
|
||||
|
||||
for _, query := range queries {
|
||||
formData["target"] = []string{query.Model.Get("target").MustString()}
|
||||
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 {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user