Annotations does not support templating variables (Prometheus datasource does)
dg-nvm opened this issue · comments
When using dynamic datasource for annotation like "${datasource}" the Datasource won't be found and query will fail
Also when query itself has templating like my_counter{db="$db"}
the value is sent raw so it's not functional
The source of these problems are two:
- Datasource is always taken raw, I tested fix by adding to datasource.tsx:705:
if (datasource?.uid?.startsWith("$") === true){
datasource.uid = this.templateSrv.replace(datasource.uid, {});
};
- Variables templating is discarded in this section:
if (request.targets.every(t => t.refId === "Anno")) {
const query = request.targets[0] as PromQueryRequest
return this.performAnnotationQuery({ ...query, start, end })
}
this discards all query preparation done by prepareTargets / createQuery which has query.expr = this.templateSrv.replace(expr, scopedVars, this.interpolateQueryExpr);
and takes raw input from target instead, fixed by:
if (request.targets.every(t => t.refId === "Anno")) {
- const query = request.targets[0] as PromQueryRequest
+ const query = {...request.targets[0], expr: queries[0].expr} as PromQueryRequest
return this.performAnnotationQuery({ ...query, start, end })
}
I am not javascript expert so these fixes can be raw, but generally after adding these both Datasource and Expression templating works as intended.