Skip to content

Commit 4ca0190

Browse files
authored
Merge pull request ceph#50214 from rhcs-dashboard/landing-page-prom-error-fix
mgr/dashboard: fix prometheus api issues on landing page v3 Reviewed-by: Pegonzal <NOT@FOUND> Reviewed-by: Ernesto Puerta <epuertat@redhat.com>
2 parents c2cedfb + 6cb0679 commit 4ca0190

File tree

8 files changed

+75
-64
lines changed

8 files changed

+75
-64
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { Component, Inject, OnInit, TemplateRef, ViewChild } from '@angular/core
33
import { PrometheusService } from '~/app/shared/api/prometheus.service';
44
import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
55
import { Icons } from '~/app/shared/enum/icons.enum';
6+
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
67
import { CdTableAction } from '~/app/shared/models/cd-table-action';
78
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
89
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
910
import { Permission } from '~/app/shared/models/permissions';
1011
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1112
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
1213
import { URLBuilderService } from '~/app/shared/services/url-builder.service';
13-
import { PrometheusListHelper } from '../prometheus-list-helper';
1414

1515
const BASE_URL = 'silences'; // as only silence actions can be used
1616

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import _ from 'lodash';
44

55
import { PrometheusService } from '~/app/shared/api/prometheus.service';
66
import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7+
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
78
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
89
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
910
import { PrometheusRule } from '~/app/shared/models/prometheus-alerts';
1011
import { DurationPipe } from '~/app/shared/pipes/duration.pipe';
1112
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
12-
import { PrometheusListHelper } from '../prometheus-list-helper';
1313

1414
@Component({
1515
selector: 'cd-rules-list',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
44
import { SortDirection, SortPropDir } from '@swimlane/ngx-datatable';
55
import { Observable, Subscriber } from 'rxjs';
66

7-
import { PrometheusListHelper } from '~/app/ceph/cluster/prometheus/prometheus-list-helper';
7+
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
88
import { SilenceFormComponent } from '~/app/ceph/cluster/prometheus/silence-form/silence-form.component';
99
import { PrometheusService } from '~/app/shared/api/prometheus.service';
1010
import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
i18n>Cluster</span>
2828
</div>
2929
<section class="border-top mt-5"
30-
*ngIf="isAlertmanagerConfigured && (crticialActiveAlerts || warningActiveAlerts)">
30+
*ngIf="isAlertmanagerConfigured && (prometheusAlertService.activeCriticalAlerts || prometheusAlertService.activeWarningAlerts)">
3131
<div class="d-flex flex-wrap ms-4 me-4">
3232
<span class="pt-2"
3333
i18n>Alerts</span>
@@ -38,9 +38,9 @@
3838
(click)="toggleAlertsWindow('danger')"
3939
id="dangerAlerts"
4040
i18n-title
41-
*ngIf="crticialActiveAlerts">
41+
*ngIf="prometheusAlertService?.activeCriticalAlerts > 0">
4242
<i [ngClass]="[icons.danger]"></i>
43-
<span>{{ crticialActiveAlerts }}</span>
43+
<span>{{ prometheusAlertService.activeCriticalAlerts }}</span>
4444
</button>
4545

4646
<button class="btn btn-outline-warning rounded-pill ms-2"
@@ -49,9 +49,9 @@
4949
(click)="toggleAlertsWindow('warning')"
5050
id="warningAlerts"
5151
i18n-title
52-
*ngIf="warningActiveAlerts">
52+
*ngIf="prometheusAlertService?.activeWarningAlerts > 0">
5353
<i [ngClass]="[icons.infoCircle]"></i>
54-
<span>{{ warningActiveAlerts }}</span>
54+
<span>{{ prometheusAlertService.activeWarningAlerts }}</span>
5555
</button>
5656

5757
<div class="pt-0 position-right">

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PrometheusService } from '~/app/shared/api/prometheus.service';
1515
import { CssHelper } from '~/app/shared/classes/css-helper';
1616
import { AlertmanagerAlert } from '~/app/shared/models/prometheus-alerts';
1717
import { FeatureTogglesService } from '~/app/shared/services/feature-toggles.service';
18+
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
1819
import { SummaryService } from '~/app/shared/services/summary.service';
1920
import { SharedModule } from '~/app/shared/shared.module';
2021
import { configureTestBed } from '~/testing/unit-test-helper';
@@ -161,6 +162,13 @@ describe('Dashbord Component', () => {
161162
schemas: [NO_ERRORS_SCHEMA],
162163
providers: [
163164
{ provide: SummaryService, useClass: SummaryServiceMock },
165+
{
166+
provide: PrometheusAlertService,
167+
useValue: {
168+
activeCriticalAlerts: 2,
169+
activeWarningAlerts: 1
170+
}
171+
},
164172
CssHelper,
165173
PgCategoryService
166174
]
@@ -244,12 +252,12 @@ describe('Dashbord Component', () => {
244252
it('should show the actual alert count on each alerts pill', () => {
245253
fixture.detectChanges();
246254

247-
const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
255+
const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
248256

249-
const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
257+
const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
250258

251-
expect(successNotification.nativeElement.textContent).toBe('1');
252-
expect(dangerNotification.nativeElement.textContent).toBe('2');
259+
expect(warningAlerts.nativeElement.textContent).toBe('1');
260+
expect(dangerAlerts.nativeElement.textContent).toBe('2');
253261
});
254262

255263
it('should show the critical alerts window and its content', () => {
@@ -275,15 +283,16 @@ describe('Dashbord Component', () => {
275283
});
276284

277285
it('should only show the pills when the alerts are not empty', () => {
278-
getAlertsSpy.and.returnValue(of({}));
286+
spyOn(TestBed.inject(PrometheusAlertService), 'activeCriticalAlerts').and.returnValue(0);
287+
spyOn(TestBed.inject(PrometheusAlertService), 'activeWarningAlerts').and.returnValue(0);
279288
fixture.detectChanges();
280289

281-
const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
290+
const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
282291

283-
const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
292+
const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
284293

285-
expect(successNotification).toBe(null);
286-
expect(dangerNotification).toBe(null);
294+
expect(warningAlerts).toBe(null);
295+
expect(dangerAlerts).toBe(null);
287296
});
288297

289298
describe('features disabled', () => {

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

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import {
2323
} from '~/app/shared/services/feature-toggles.service';
2424
import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
2525
import { SummaryService } from '~/app/shared/services/summary.service';
26+
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
27+
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
2628

2729
@Component({
2830
selector: 'cd-dashboard',
2931
templateUrl: './dashboard.component.html',
3032
styleUrls: ['./dashboard.component.scss']
3133
})
32-
export class DashboardComponent implements OnInit, OnDestroy {
34+
export class DashboardComponent extends PrometheusListHelper implements OnInit, OnDestroy {
3335
detailsCardData: DashboardDetails = {};
3436
osdSettingsService: any;
3537
osdSettings: any;
@@ -42,7 +44,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
4244
healthData$: Observable<Object>;
4345
prometheusAlerts$: Observable<AlertmanagerAlert[]>;
4446

45-
isAlertmanagerConfigured = false;
4647
icons = Icons;
4748
showAlerts = false;
4849
flexHeight = true;
@@ -53,8 +54,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
5354
borderClass: string;
5455
alertType: string;
5556
alerts: AlertmanagerAlert[];
56-
crticialActiveAlerts: number;
57-
warningActiveAlerts: number;
5857
healthData: any;
5958
categoryPgAmount: Record<string, number> = {};
6059
totalPgs = 0;
@@ -86,16 +85,18 @@ export class DashboardComponent implements OnInit, OnDestroy {
8685
private featureToggles: FeatureTogglesService,
8786
private healthService: HealthService,
8887
public prometheusService: PrometheusService,
89-
private refreshIntervalService: RefreshIntervalService
88+
private refreshIntervalService: RefreshIntervalService,
89+
public prometheusAlertService: PrometheusAlertService
9090
) {
91+
super(prometheusService);
9192
this.permissions = this.authStorageService.getPermissions();
9293
this.enabledFeature$ = this.featureToggles.get();
9394
}
9495

9596
ngOnInit() {
97+
super.ngOnInit();
9698
this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
9799
this.getHealth();
98-
this.triggerPrometheusAlerts();
99100
this.getCapacityCardData();
100101
});
101102
this.getPrometheusData(this.lastHourDateObject);
@@ -113,6 +114,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
113114
}
114115

115116
toggleAlertsWindow(type: string, isToggleButton: boolean = false) {
117+
this.triggerPrometheusAlerts();
116118
if (isToggleButton) {
117119
this.showAlerts = !this.showAlerts;
118120
this.flexHeight = !this.flexHeight;
@@ -159,56 +161,48 @@ export class DashboardComponent implements OnInit, OnDestroy {
159161

160162
triggerPrometheusAlerts() {
161163
this.prometheusService.ifAlertmanagerConfigured(() => {
162-
this.isAlertmanagerConfigured = true;
163-
164164
this.prometheusService.getAlerts().subscribe((alerts) => {
165165
this.alerts = alerts;
166-
this.crticialActiveAlerts = alerts.filter(
167-
(alert: AlertmanagerAlert) =>
168-
alert.status.state === 'active' && alert.labels.severity === 'critical'
169-
).length;
170-
this.warningActiveAlerts = alerts.filter(
171-
(alert: AlertmanagerAlert) =>
172-
alert.status.state === 'active' && alert.labels.severity === 'warning'
173-
).length;
174166
});
175167
});
176168
}
177169

178170
getPrometheusData(selectedTime: any) {
179-
if (this.timerGetPrometheusDataSub) {
180-
this.timerGetPrometheusDataSub.unsubscribe();
181-
}
182-
this.timerGetPrometheusDataSub = timer(0, this.timerTime).subscribe(() => {
183-
selectedTime = this.updateTimeStamp(selectedTime);
184-
185-
for (const queryName in queries) {
186-
if (queries.hasOwnProperty(queryName)) {
187-
const query = queries[queryName];
188-
let interval = selectedTime.step;
189-
190-
if (query.includes('rate') && selectedTime.step < 20) {
191-
interval = 20;
192-
} else if (query.includes('rate')) {
193-
interval = selectedTime.step * 2;
171+
this.prometheusService.ifPrometheusConfigured(() => {
172+
if (this.timerGetPrometheusDataSub) {
173+
this.timerGetPrometheusDataSub.unsubscribe();
174+
}
175+
this.timerGetPrometheusDataSub = timer(0, this.timerTime).subscribe(() => {
176+
selectedTime = this.updateTimeStamp(selectedTime);
177+
178+
for (const queryName in queries) {
179+
if (queries.hasOwnProperty(queryName)) {
180+
const query = queries[queryName];
181+
let interval = selectedTime.step;
182+
183+
if (query.includes('rate') && selectedTime.step < 20) {
184+
interval = 20;
185+
} else if (query.includes('rate')) {
186+
interval = selectedTime.step * 2;
187+
}
188+
189+
const intervalAdjustedQuery = query.replace(/\[(.*?)\]/g, `[${interval}s]`);
190+
191+
this.prometheusService
192+
.getPrometheusData({
193+
params: intervalAdjustedQuery,
194+
start: selectedTime['start'],
195+
end: selectedTime['end'],
196+
step: selectedTime['step']
197+
})
198+
.subscribe((data: any) => {
199+
if (data.result.length) {
200+
this.queriesResults[queryName] = data.result[0].values;
201+
}
202+
});
194203
}
195-
196-
const intervalAdjustedQuery = query.replace(/\[(.*?)\]/g, `[${interval}s]`);
197-
198-
this.prometheusService
199-
.getPrometheusData({
200-
params: intervalAdjustedQuery,
201-
start: selectedTime['start'],
202-
end: selectedTime['end'],
203-
step: selectedTime['step']
204-
})
205-
.subscribe((data: any) => {
206-
if (data.result.length) {
207-
this.queriesResults[queryName] = data.result[0].values;
208-
}
209-
});
210204
}
211-
}
205+
});
212206
});
213207
}
214208

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@NgModule({
5+
declarations: [],
6+
imports: [CommonModule]
7+
})
8+
export class HelpersModule {}

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/prometheus-list-helper.ts renamed to src/pybind/mgr/dashboard/frontend/src/app/shared/helpers/prometheus-list-helper.ts

File renamed without changes.

0 commit comments

Comments
 (0)