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 <nia@redhat.com>
This commit is contained in:
Nizamudeen A 2024-03-19 20:39:09 +05:30
parent 625e312e86
commit 93974820ce
2 changed files with 18 additions and 3 deletions

View File

@ -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(() => {

View File

@ -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);