From: Nizamudeen A Date: Tue, 19 Mar 2024 15:09:09 +0000 (+0530) Subject: mgr/dashboard: update grafana api url when switching cluster X-Git-Tag: testing/wip-batrick-testing-20240411.154038~140^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=93974820ceb58bdde12074f2b9ab750696f51a51;p=ceph-ci.git mgr/dashboard: update grafana api url when switching cluster do a force refresh on the settings service so it picks up the new api url of grafana Fixes: https://tracker.ceph.com/issues/65052 Signed-off-by: Nizamudeen A --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts index 8973843872b..de8b0a267db 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts @@ -4,6 +4,7 @@ import { Router } from '@angular/router'; import * as _ from 'lodash'; import { Subscription } from 'rxjs'; import { MultiClusterService } from '~/app/shared/api/multi-cluster.service'; +import { SettingsService } from '~/app/shared/api/settings.service'; import { Icons } from '~/app/shared/enum/icons.enum'; import { MultiCluster } from '~/app/shared/models/multi-cluster'; @@ -58,7 +59,8 @@ export class NavigationComponent implements OnInit, OnDestroy { private telemetryNotificationService: TelemetryNotificationService, public prometheusAlertService: PrometheusAlertService, private motdNotificationService: MotdNotificationService, - private cookieService: CookiesService + private cookieService: CookiesService, + private settingsService: SettingsService ) { this.permissions = this.authStorageService.getPermissions(); this.enabledFeature$ = this.featureToggles.get(); @@ -212,6 +214,14 @@ export class NavigationComponent implements OnInit, OnDestroy { () => { this.multiClusterService.refresh(); this.summaryService.refresh(); + + // force refresh grafana api url to get the correct url for the selected cluster + this.settingsService.ifSettingConfigured( + 'api/grafana/url', + () => {}, + () => {}, + true + ); const currentRoute = this.router.url.split('?')[0]; if (currentRoute.includes('dashboard')) { this.router.navigateByUrl('/pool', { skipLocationChange: true }).then(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/settings.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/settings.service.ts index 1e53fa06493..9aeb79906c9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/settings.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/settings.service.ts @@ -35,9 +35,14 @@ export class SettingsService { ); } - ifSettingConfigured(url: string, fn: (value?: string) => void, elseFn?: () => void): void { + ifSettingConfigured( + url: string, + fn: (value?: string) => void, + elseFn?: () => void, + forceRefresh = false + ): void { const setting = this.settings[url]; - if (setting === undefined) { + if (forceRefresh || setting === undefined) { this.http.get(url).subscribe( (data: any) => { this.settings[url] = this.getSettingsValue(data);