Skip to content

Commit e67bece

Browse files
authored
Merge pull request ceph#56579 from rhcs-dashboard/fix-alerts-verison-compatability-multi-cluster
mgr/dashboard: Filter alerts based on cluster fsid and do not allow to connect clusters with version less than hub cluster in multi-cluster Reviewed-by: Nizamudeen A <[email protected]>
2 parents bf48674 + bca4720 commit e67bece

File tree

12 files changed

+53
-18
lines changed

12 files changed

+53
-18
lines changed

src/pybind/mgr/dashboard/controllers/multi_cluster.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ def get_cors_endpoints_string(self, hub_url):
128128

129129
def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certificate):
130130
try:
131+
hub_cluster_version = mgr.version.split('ceph version ')[1]
132+
multi_cluster_content = self._proxy('GET', url, 'api/multi-cluster/get_config',
133+
verify=ssl_verify, cert=ssl_certificate)
134+
if 'status' in multi_cluster_content and multi_cluster_content['status'] == '404 Not Found': # noqa E501 #pylint: disable=line-too-long
135+
raise DashboardException(msg=f'The ceph cluster you are attempting to connect \
136+
to does not support the multi-cluster feature. \
137+
Please ensure that the cluster you are connecting \
138+
to is upgraded to { hub_cluster_version } to enable the \
139+
multi-cluster functionality.',
140+
code='invalid_version', component='multi-cluster')
131141
content = self._proxy('POST', url, 'api/auth', payload=payload,
132142
verify=ssl_verify, cert=ssl_certificate)
133143
if 'token' not in content:

src/pybind/mgr/dashboard/controllers/prometheus.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ def _proxy(self, base_url, method, path, api_name, params=None, payload=None, ve
126126
@APIRouter('/prometheus', Scope.PROMETHEUS)
127127
@APIDoc("Prometheus Management API", "Prometheus")
128128
class Prometheus(PrometheusRESTController):
129-
def list(self, **params):
129+
def list(self, cluster_filter=False, **params):
130+
if cluster_filter:
131+
try:
132+
fsid = mgr.get('config')['fsid']
133+
except KeyError:
134+
raise DashboardException("Cluster fsid not found", component='prometheus')
135+
return self.alert_proxy('GET', f'/alerts?filter=cluster={fsid}', params)
130136
return self.alert_proxy('GET', '/alerts', params)
131137

132138
@RESTController.Collection(method='GET')

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h4 class="mt-3">This cluster is already managed by cluster -
8686
[fullHeight]="true"
8787
*ngIf="queriesResults.CLUSTER_COUNT && queriesResults.CLUSTER_COUNT[0]">
8888
<span class="text-center">
89-
<h3 *ngIf="queriesResults['HEALTH_ERROR_COUNT'][0][1] === '0' && queriesResults['HEALTH_WARNING_COUNT'][0][1] === '0'">{{ queriesResults.CLUSTER_COUNT[0][1] }}</h3>
89+
<h3 *ngIf="queriesResults['HEALTH_ERROR_COUNT'][0][1] === '0' && queriesResults['HEALTH_OK_COUNT'][0][1] === '0' && queriesResults['HEALTH_WARNING_COUNT'][0][1] === '0'">{{ queriesResults.CLUSTER_COUNT[0][1] }}</h3>
9090
<h3 class="text-danger"
9191
*ngIf="queriesResults.HEALTH_ERROR_COUNT[0][1] !== '0'">
9292
<i [ngClass]="icons.danger"></i>
@@ -97,6 +97,16 @@ <h3 *ngIf="queriesResults['HEALTH_ERROR_COUNT'][0][1] === '0' && queriesResults[
9797
<i [ngClass]="icons.warning"></i>
9898
{{ queriesResults.HEALTH_WARNING_COUNT[0][1] }}
9999
</h3>
100+
<h3 class="text-danger"
101+
*ngIf="queriesResults.HEALTH_ERROR_COUNT[0][1] !== '0'">
102+
<i [ngClass]="icons.danger"></i>
103+
{{ queriesResults.HEALTH_ERROR_COUNT[0][1] }}
104+
</h3>
105+
<h3 class="text-success"
106+
*ngIf="queriesResults.HEALTH_OK_COUNT[0][1] !== '0'">
107+
<i [ngClass]="icons.success"></i>
108+
{{ queriesResults.HEALTH_OK_COUNT[0][1] }}
109+
</h3>
100110
</span>
101111
</cd-card>
102112
<cd-card cardTitle="Alerts"

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { TableActionsComponent } from '~/app/shared/datatable/table-actions/tabl
1414
import { SharedModule } from '~/app/shared/shared.module';
1515
import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
1616
import { ActiveAlertListComponent } from './active-alert-list.component';
17+
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
18+
import { of } from 'rxjs';
1719

1820
describe('ActiveAlertListComponent', () => {
1921
let component: ActiveAlertListComponent;
@@ -37,6 +39,8 @@ describe('ActiveAlertListComponent', () => {
3739
beforeEach(() => {
3840
fixture = TestBed.createComponent(ActiveAlertListComponent);
3941
component = fixture.componentInstance;
42+
let prometheusAlertService = TestBed.inject(PrometheusAlertService);
43+
spyOn(prometheusAlertService, 'getAlerts').and.callFake(() => of([]));
4044
});
4145

4246
it('should create', () => {

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class ActiveAlertListComponent extends PrometheusListHelper implements On
105105
cellTemplate: this.externalLinkTpl
106106
}
107107
];
108+
this.prometheusAlertService.getAlerts(true);
108109
}
109110

110111
updateSelection(selection: CdTableSelection) {

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ describe('Dashbord Component', () => {
141141
schemas: [NO_ERRORS_SCHEMA],
142142
providers: [
143143
{ provide: SummaryService, useClass: SummaryServiceMock },
144-
{
145-
provide: PrometheusAlertService,
146-
useValue: {
147-
activeCriticalAlerts: 2,
148-
activeWarningAlerts: 1
149-
}
150-
},
144+
PrometheusAlertService,
151145
CssHelper,
152146
PgCategoryService
153147
]
@@ -169,11 +163,14 @@ describe('Dashbord Component', () => {
169163
orchestratorService = TestBed.inject(OrchestratorService);
170164
getHealthSpy = spyOn(TestBed.inject(HealthService), 'getMinimalHealth');
171165
getHealthSpy.and.returnValue(of(healthPayload));
172-
spyOn(TestBed.inject(PrometheusService), 'ifAlertmanagerConfigured').and.callFake((fn) => fn());
173166
getAlertsSpy = spyOn(TestBed.inject(PrometheusService), 'getAlerts');
174167
getAlertsSpy.and.returnValue(of(alertsPayload));
175168
component.prometheusAlertService.alerts = alertsPayload;
176169
component.isAlertmanagerConfigured = true;
170+
let prometheusAlertService = TestBed.inject(PrometheusAlertService);
171+
spyOn(prometheusAlertService, 'getAlerts').and.callFake(() => of([]));
172+
prometheusAlertService.activeCriticalAlerts = 2;
173+
prometheusAlertService.activeWarningAlerts = 1;
177174
});
178175

179176
it('should create', () => {

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export class DashboardV3Component extends PrometheusListHelper implements OnInit
120120
this.getDetailsCardData();
121121
this.getTelemetryReport();
122122
this.managedByConfig$ = this.settingsService.getValues('MANAGED_BY_CLUSTERS');
123+
this.prometheusAlertService.getAlerts(true);
123124
}
124125

125126
getTelemetryText(): string {

src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('PrometheusService', () => {
3030

3131
it('should get alerts', () => {
3232
service.getAlerts().subscribe();
33-
const req = httpTesting.expectOne('api/prometheus');
33+
const req = httpTesting.expectOne('api/prometheus?cluster_filter=false');
3434
expect(req.request.method).toBe('GET');
3535
});
3636

src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export class PrometheusService {
5858
this.disableSetting(this.settingsKey.prometheus);
5959
}
6060

61-
getAlerts(params = {}): Observable<AlertmanagerAlert[]> {
61+
getAlerts(clusterFilteredAlerts = false, params = {}): Observable<AlertmanagerAlert[]> {
62+
params['cluster_filter'] = clusterFilteredAlerts;
6263
return this.http.get<AlertmanagerAlert[]>(this.baseURL, { params });
6364
}
6465

src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy {
154154
}
155155

156156
private triggerPrometheusAlerts() {
157-
this.prometheusAlertService.refresh();
157+
this.prometheusAlertService.refresh(true);
158158
this.prometheusNotificationService.refresh();
159159
}
160160

0 commit comments

Comments
 (0)