From bca4720997a59f080e21e1dc7241124194cf79f5 Mon Sep 17 00:00:00 2001 From: Aashish Sharma Date: Fri, 29 Mar 2024 15:07:12 +0530 Subject: [PATCH] mgr/dashboard: filter alerts with cluster fsid and donot allow clusters with version less than hub cluster to be added in multi-cluster Signed-off-by: Aashish Sharma --- .../mgr/dashboard/controllers/multi_cluster.py | 10 ++++++++++ src/pybind/mgr/dashboard/controllers/prometheus.py | 8 +++++++- .../multi-cluster/multi-cluster.component.html | 12 +++++++++++- .../active-alert-list.component.spec.ts | 4 ++++ .../active-alert-list.component.ts | 1 + .../dashboard/dashboard-v3.component.spec.ts | 13 +++++-------- .../dashboard/dashboard-v3.component.ts | 1 + .../src/app/shared/api/prometheus.service.spec.ts | 2 +- .../src/app/shared/api/prometheus.service.ts | 3 ++- .../notifications-sidebar.component.ts | 2 +- .../app/shared/services/prometheus-alert.service.ts | 8 ++++---- src/pybind/mgr/dashboard/openapi.yaml | 7 ++++++- 12 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/multi_cluster.py b/src/pybind/mgr/dashboard/controllers/multi_cluster.py index 75095dcbd467..cc6a7e203d3b 100644 --- a/src/pybind/mgr/dashboard/controllers/multi_cluster.py +++ b/src/pybind/mgr/dashboard/controllers/multi_cluster.py @@ -128,6 +128,16 @@ class MultiCluster(RESTController): def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certificate): try: + hub_cluster_version = mgr.version.split('ceph version ')[1] + multi_cluster_content = self._proxy('GET', url, 'api/multi-cluster/get_config', + verify=ssl_verify, cert=ssl_certificate) + if 'status' in multi_cluster_content and multi_cluster_content['status'] == '404 Not Found': # noqa E501 #pylint: disable=line-too-long + raise DashboardException(msg=f'The ceph cluster you are attempting to connect \ + to does not support the multi-cluster feature. \ + Please ensure that the cluster you are connecting \ + to is upgraded to { hub_cluster_version } to enable the \ + multi-cluster functionality.', + code='invalid_version', component='multi-cluster') content = self._proxy('POST', url, 'api/auth', payload=payload, verify=ssl_verify, cert=ssl_certificate) if 'token' not in content: diff --git a/src/pybind/mgr/dashboard/controllers/prometheus.py b/src/pybind/mgr/dashboard/controllers/prometheus.py index ffc6407b4a9f..75a607d1e311 100644 --- a/src/pybind/mgr/dashboard/controllers/prometheus.py +++ b/src/pybind/mgr/dashboard/controllers/prometheus.py @@ -126,7 +126,13 @@ class PrometheusRESTController(RESTController): @APIRouter('/prometheus', Scope.PROMETHEUS) @APIDoc("Prometheus Management API", "Prometheus") class Prometheus(PrometheusRESTController): - def list(self, **params): + def list(self, cluster_filter=False, **params): + if cluster_filter: + try: + fsid = mgr.get('config')['fsid'] + except KeyError: + raise DashboardException("Cluster fsid not found", component='prometheus') + return self.alert_proxy('GET', f'/alerts?filter=cluster={fsid}', params) return self.alert_proxy('GET', '/alerts', params) @RESTController.Collection(method='GET') diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.html index 3e9e27c33bac..0b209abaa505 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.html @@ -86,7 +86,7 @@ [fullHeight]="true" *ngIf="queriesResults.CLUSTER_COUNT && queriesResults.CLUSTER_COUNT[0]"> -

{{ queriesResults.CLUSTER_COUNT[0][1] }}

+

{{ queriesResults.CLUSTER_COUNT[0][1] }}

@@ -97,6 +97,16 @@ {{ queriesResults.HEALTH_WARNING_COUNT[0][1] }}

+

+ + {{ queriesResults.HEALTH_ERROR_COUNT[0][1] }} +

+

+ + {{ queriesResults.HEALTH_OK_COUNT[0][1] }} +

{ let component: ActiveAlertListComponent; @@ -37,6 +39,8 @@ describe('ActiveAlertListComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ActiveAlertListComponent); component = fixture.componentInstance; + let prometheusAlertService = TestBed.inject(PrometheusAlertService); + spyOn(prometheusAlertService, 'getAlerts').and.callFake(() => of([])); }); it('should create', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts index de027bfec507..e3892f0a6794 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts @@ -105,6 +105,7 @@ export class ActiveAlertListComponent extends PrometheusListHelper implements On cellTemplate: this.externalLinkTpl } ]; + this.prometheusAlertService.getAlerts(true); } updateSelection(selection: CdTableSelection) { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts index 60a30456ef71..b87888f4f4a0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts @@ -141,13 +141,7 @@ describe('Dashbord Component', () => { schemas: [NO_ERRORS_SCHEMA], providers: [ { provide: SummaryService, useClass: SummaryServiceMock }, - { - provide: PrometheusAlertService, - useValue: { - activeCriticalAlerts: 2, - activeWarningAlerts: 1 - } - }, + PrometheusAlertService, CssHelper, PgCategoryService ] @@ -169,11 +163,14 @@ describe('Dashbord Component', () => { orchestratorService = TestBed.inject(OrchestratorService); getHealthSpy = spyOn(TestBed.inject(HealthService), 'getMinimalHealth'); getHealthSpy.and.returnValue(of(healthPayload)); - spyOn(TestBed.inject(PrometheusService), 'ifAlertmanagerConfigured').and.callFake((fn) => fn()); getAlertsSpy = spyOn(TestBed.inject(PrometheusService), 'getAlerts'); getAlertsSpy.and.returnValue(of(alertsPayload)); component.prometheusAlertService.alerts = alertsPayload; component.isAlertmanagerConfigured = true; + let prometheusAlertService = TestBed.inject(PrometheusAlertService); + spyOn(prometheusAlertService, 'getAlerts').and.callFake(() => of([])); + prometheusAlertService.activeCriticalAlerts = 2; + prometheusAlertService.activeWarningAlerts = 1; }); it('should create', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts index d8528f6cff85..9b3c050064f9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts @@ -120,6 +120,7 @@ export class DashboardV3Component extends PrometheusListHelper implements OnInit this.getDetailsCardData(); this.getTelemetryReport(); this.managedByConfig$ = this.settingsService.getValues('MANAGED_BY_CLUSTERS'); + this.prometheusAlertService.getAlerts(true); } getTelemetryText(): string { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts index 65fc174b92e3..969408455951 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts @@ -30,7 +30,7 @@ describe('PrometheusService', () => { it('should get alerts', () => { service.getAlerts().subscribe(); - const req = httpTesting.expectOne('api/prometheus'); + const req = httpTesting.expectOne('api/prometheus?cluster_filter=false'); expect(req.request.method).toBe('GET'); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts index 2b469e837d22..1a241361f7f2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts @@ -58,7 +58,8 @@ export class PrometheusService { this.disableSetting(this.settingsKey.prometheus); } - getAlerts(params = {}): Observable { + getAlerts(clusterFilteredAlerts = false, params = {}): Observable { + params['cluster_filter'] = clusterFilteredAlerts; return this.http.get(this.baseURL, { params }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts index 3868f55ba53e..a662a898b163 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts @@ -154,7 +154,7 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy { } private triggerPrometheusAlerts() { - this.prometheusAlertService.refresh(); + this.prometheusAlertService.refresh(true); this.prometheusNotificationService.refresh(); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts index 2830fd00c242..6c9ab25cbc23 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts @@ -26,9 +26,9 @@ export class PrometheusAlertService { private prometheusService: PrometheusService ) {} - getAlerts() { + getAlerts(clusterFilteredAlerts?: boolean) { this.prometheusService.ifAlertmanagerConfigured(() => { - this.prometheusService.getAlerts().subscribe( + this.prometheusService.getAlerts(clusterFilteredAlerts).subscribe( (alerts) => this.handleAlerts(alerts), (resp) => { if ([404, 504].includes(resp.status)) { @@ -54,8 +54,8 @@ export class PrometheusAlertService { }); } - refresh() { - this.getAlerts(); + refresh(clusterFilteredAlerts?: boolean) { + this.getAlerts(clusterFilteredAlerts); this.getRules(); } diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index d43f48fcbf70..1c004bd8b3c7 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -10300,7 +10300,12 @@ paths: - Pool /api/prometheus: get: - parameters: [] + parameters: + - default: false + in: query + name: cluster_filter + schema: + type: boolean responses: '200': content: -- 2.47.3