i18n>Cluster</span>
</div>
<section class="border-top mt-5"
- *ngIf="isAlertmanagerConfigured && (crticialActiveAlerts || warningActiveAlerts)">
+ *ngIf="isAlertmanagerConfigured && (prometheusAlertService.activeCriticalAlerts || prometheusAlertService.activeWarningAlerts)">
<div class="d-flex flex-wrap ms-4 me-4">
<span class="pt-2"
i18n>Alerts</span>
(click)="toggleAlertsWindow('danger')"
id="dangerAlerts"
i18n-title
- *ngIf="crticialActiveAlerts">
+ *ngIf="prometheusAlertService?.activeCriticalAlerts > 0">
<i [ngClass]="[icons.danger]"></i>
- <span>{{ crticialActiveAlerts }}</span>
+ <span>{{ prometheusAlertService.activeCriticalAlerts }}</span>
</button>
<button class="btn btn-outline-warning rounded-pill ms-2"
(click)="toggleAlertsWindow('warning')"
id="warningAlerts"
i18n-title
- *ngIf="warningActiveAlerts">
+ *ngIf="prometheusAlertService?.activeWarningAlerts > 0">
<i [ngClass]="[icons.infoCircle]"></i>
- <span>{{ warningActiveAlerts }}</span>
+ <span>{{ prometheusAlertService.activeWarningAlerts }}</span>
</button>
<div class="pt-0 position-right">
import { CssHelper } from '~/app/shared/classes/css-helper';
import { AlertmanagerAlert } from '~/app/shared/models/prometheus-alerts';
import { FeatureTogglesService } from '~/app/shared/services/feature-toggles.service';
+import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
import { SummaryService } from '~/app/shared/services/summary.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
schemas: [NO_ERRORS_SCHEMA],
providers: [
{ provide: SummaryService, useClass: SummaryServiceMock },
+ {
+ provide: PrometheusAlertService,
+ useValue: {
+ activeCriticalAlerts: 2,
+ activeWarningAlerts: 1
+ }
+ },
CssHelper,
PgCategoryService
]
it('should show the actual alert count on each alerts pill', () => {
fixture.detectChanges();
- const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
+ const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
- const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
+ const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
- expect(successNotification.nativeElement.textContent).toBe('1');
- expect(dangerNotification.nativeElement.textContent).toBe('2');
+ expect(warningAlerts.nativeElement.textContent).toBe('1');
+ expect(dangerAlerts.nativeElement.textContent).toBe('2');
});
it('should show the critical alerts window and its content', () => {
});
it('should only show the pills when the alerts are not empty', () => {
- getAlertsSpy.and.returnValue(of({}));
+ spyOn(TestBed.inject(PrometheusAlertService), 'activeCriticalAlerts').and.returnValue(0);
+ spyOn(TestBed.inject(PrometheusAlertService), 'activeWarningAlerts').and.returnValue(0);
fixture.detectChanges();
- const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
+ const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
- const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
+ const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
- expect(successNotification).toBe(null);
- expect(dangerNotification).toBe(null);
+ expect(warningAlerts).toBe(null);
+ expect(dangerAlerts).toBe(null);
});
describe('features disabled', () => {
import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
import { SummaryService } from '~/app/shared/services/summary.service';
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
+import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
@Component({
selector: 'cd-dashboard',
borderClass: string;
alertType: string;
alerts: AlertmanagerAlert[];
- crticialActiveAlerts: number;
- warningActiveAlerts: number;
healthData: any;
categoryPgAmount: Record<string, number> = {};
totalPgs = 0;
private featureToggles: FeatureTogglesService,
private healthService: HealthService,
public prometheusService: PrometheusService,
- private refreshIntervalService: RefreshIntervalService
+ private refreshIntervalService: RefreshIntervalService,
+ public prometheusAlertService: PrometheusAlertService
) {
super(prometheusService);
this.permissions = this.authStorageService.getPermissions();
super.ngOnInit();
this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
this.getHealth();
- this.triggerPrometheusAlerts();
this.getCapacityCardData();
});
this.getPrometheusData(this.lastHourDateObject);
}
toggleAlertsWindow(type: string, isToggleButton: boolean = false) {
+ this.triggerPrometheusAlerts();
if (isToggleButton) {
this.showAlerts = !this.showAlerts;
this.flexHeight = !this.flexHeight;
this.prometheusService.ifAlertmanagerConfigured(() => {
this.prometheusService.getAlerts().subscribe((alerts) => {
this.alerts = alerts;
- this.crticialActiveAlerts = alerts.filter(
- (alert: AlertmanagerAlert) =>
- alert.status.state === 'active' && alert.labels.severity === 'critical'
- ).length;
- this.warningActiveAlerts = alerts.filter(
- (alert: AlertmanagerAlert) =>
- alert.status.state === 'active' && alert.labels.severity === 'warning'
- ).length;
});
});
}