From 4e98ade2af1e54017d31ed3e2de33202346a215d Mon Sep 17 00:00:00 2001 From: Uchechukwu Obasi Date: Fri, 13 Aug 2021 14:38:57 +0100 Subject: [PATCH] Annotations: fixes variable values not displaying in annotations. (#37883) * Fixes wrong annotation when opening dashboard with URL encoded variable Co-authored-by: Ashley Harrison, Hugo Haggmark, and Tobias Skarhed. * added a more descriptive comment --- public/app/features/dashboard/state/initDashboard.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard/state/initDashboard.ts b/public/app/features/dashboard/state/initDashboard.ts index 4d144fe81e1..44263c8a17b 100644 --- a/public/app/features/dashboard/state/initDashboard.ts +++ b/public/app/features/dashboard/state/initDashboard.ts @@ -155,8 +155,6 @@ export function initDashboard(args: InitDashboardArgs): ThunkResult { dashboardSrv.setCurrent(dashboard); timeSrv.init(dashboard); - const runner = createDashboardQueryRunner({ dashboard, timeSrv }); - runner.run({ dashboard, range: timeSrv.timeRange() }); if (storeState.dashboard.modifiedQueries) { const { panelId, queries } = storeState.dashboard.modifiedQueries; @@ -166,6 +164,11 @@ export function initDashboard(args: InitDashboardArgs): ThunkResult { // template values service needs to initialize completely before the rest of the dashboard can load await dispatch(initVariablesTransaction(args.urlUid!, dashboard)); + // DashboardQueryRunner needs to run after all variables have been resolved so that any annotation query including a variable + // will be correctly resolved + const runner = createDashboardQueryRunner({ dashboard, timeSrv }); + runner.run({ dashboard, range: timeSrv.timeRange() }); + if (getState().templating.transaction.uid !== args.urlUid) { // if a previous dashboard has slow running variable queries the batch uid will be the new one // but the args.urlUid will be the same as before initVariablesTransaction was called so then we can't continue initializing