]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
19b27a18edffe3c019d057331606e04f38a6be7b
[ceph.git] /
1 import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
2
3 import _ from 'lodash';
4 import { Subscription } from 'rxjs';
5
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';
14
15 @Component({
16   selector: 'cd-rules-list',
17   templateUrl: './rules-list.component.html',
18   styleUrls: ['./rules-list.component.scss']
19 })
20 export class RulesListComponent extends PrometheusListHelper implements OnInit, OnDestroy {
21   columns: CdTableColumn[];
22   declare expandedRow: PrometheusRule;
23   selection = new CdTableSelection();
24   rules: PrometheusRule[] = [];
25
26   /**
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'.
30    */
31   hideKeys = ['alerts', 'type'];
32   rulesSubscription: Subscription;
33
34   constructor(
35     public prometheusAlertService: PrometheusAlertService,
36     @Inject(PrometheusService) prometheusService: PrometheusService
37   ) {
38     super(prometheusService);
39   }
40
41   ngOnInit() {
42     super.ngOnInit();
43     this.prometheusAlertService.getRules();
44     this.rulesSubscription = this.prometheusAlertService.rules$.subscribe((rules) => {
45       this.rules = rules;
46     });
47     this.columns = [
48       { prop: 'name', name: $localize`Name`, cellClass: 'fw-bold', flexGrow: 2 },
49       {
50         prop: 'labels.severity',
51         name: $localize`Severity`,
52         flexGrow: 1,
53         cellTransformation: CellTemplate.badge,
54         customTemplateConfig: {
55           map: {
56             critical: { class: 'badge-danger' },
57             warning: { class: 'badge-warning' }
58           }
59         }
60       },
61       {
62         prop: 'group',
63         name: $localize`Group`,
64         flexGrow: 1,
65         cellTransformation: CellTemplate.badge
66       },
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 }
70     ];
71   }
72
73   updateSelection(selection: CdTableSelection) {
74     this.selection = selection;
75   }
76
77   ngOnDestroy() {
78     this.rulesSubscription.unsubscribe();
79   }
80 }