1 import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
3 import _ from 'lodash';
4 import { Subscription } from 'rxjs';
6 import { PrometheusService } from '~/app/shared/api/prometheus.service';
7 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
8 import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
9 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
10 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
11 import { PrometheusRule } from '~/app/shared/models/prometheus-alerts';
12 import { DurationPipe } from '~/app/shared/pipes/duration.pipe';
13 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
16 selector: 'cd-rules-list',
17 templateUrl: './rules-list.component.html',
18 styleUrls: ['./rules-list.component.scss']
20 export class RulesListComponent extends PrometheusListHelper implements OnInit, OnDestroy {
21 columns: CdTableColumn[];
22 declare expandedRow: PrometheusRule;
23 selection = new CdTableSelection();
24 rules: PrometheusRule[] = [];
27 * Hide active alerts in details of alerting rules as they are already shown
28 * in the 'active alerts' table. Also hide the 'type' column as the type is
29 * always supposed to be 'alerting'.
31 hideKeys = ['alerts', 'type'];
32 rulesSubscription: Subscription;
35 public prometheusAlertService: PrometheusAlertService,
36 @Inject(PrometheusService) prometheusService: PrometheusService
38 super(prometheusService);
43 this.prometheusAlertService.getRules();
44 this.rulesSubscription = this.prometheusAlertService.rules$.subscribe((rules) => {
48 { prop: 'name', name: $localize`Name`, cellClass: 'fw-bold', flexGrow: 2 },
50 prop: 'labels.severity',
51 name: $localize`Severity`,
53 cellTransformation: CellTemplate.badge,
54 customTemplateConfig: {
56 critical: { class: 'badge-danger' },
57 warning: { class: 'badge-warning' }
63 name: $localize`Group`,
65 cellTransformation: CellTemplate.badge
67 { prop: 'duration', name: $localize`Duration`, pipe: new DurationPipe(), flexGrow: 1 },
68 { prop: 'query', name: $localize`Query`, isHidden: true, flexGrow: 1 },
69 { prop: 'annotations.summary', name: $localize`Summary`, flexGrow: 3 }
73 updateSelection(selection: CdTableSelection) {
74 this.selection = selection;
78 this.rulesSubscription.unsubscribe();