]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Improve column spacing in alerts tab
authorAashish Sharma <aasharma@redhat.com>
Wed, 22 Jun 2022 11:47:24 +0000 (17:17 +0530)
committerAashish Sharma <aasharma@redhat.com>
Thu, 1 Sep 2022 05:29:48 +0000 (10:59 +0530)
This PR intends to fix the column spacing in the alert list in the alerts tab
Fixes:https://tracker.ceph.com/issues/56165

Resolves rhbz#2047629

Signed-off-by: Aashish Sharma <aasharma@redhat.com>
(cherry picked from commit d60ca04c965446cfde20a0b7bfdd76393815c1bb)
(cherry picked from commit 41788f0b611dae1934fb9678bcefcf7284f85004)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/prometheus-tabs/prometheus-tabs.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/prometheus-tabs/prometheus-tabs.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/prometheus-tabs/prometheus-tabs.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/rules-list/rules-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts

index 83888a5550c8144cbb2aad8e9802afe14120dc02..a319aeed6f338cf85b09377b09e4955e3d060382 100644 (file)
@@ -7,7 +7,6 @@ import { CdTableAction } from '~/app/shared/models/cd-table-action';
 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
 import { Permission } from '~/app/shared/models/permissions';
-import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
@@ -29,18 +28,12 @@ export class ActiveAlertListComponent extends PrometheusListHelper implements On
   permission: Permission;
   selection = new CdTableSelection();
   icons = Icons;
-  customCss = {
-    'badge badge-danger': 'active',
-    'badge badge-warning': 'unprocessed',
-    'badge badge-info': 'suppressed'
-  };
 
   constructor(
     // NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
     private authStorageService: AuthStorageService,
     public prometheusAlertService: PrometheusAlertService,
     private urlBuilder: URLBuilderService,
-    private cdDatePipe: CdDatePipe,
     @Inject(PrometheusService) prometheusService: PrometheusService
   ) {
     super(prometheusService);
@@ -65,30 +58,49 @@ export class ActiveAlertListComponent extends PrometheusListHelper implements On
       {
         name: $localize`Name`,
         prop: 'labels.alertname',
+        cellClass: 'font-weight-bold',
         flexGrow: 2
       },
       {
-        name: $localize`Job`,
-        prop: 'labels.job',
-        flexGrow: 2
+        name: $localize`Summary`,
+        prop: 'annotations.summary',
+        flexGrow: 3
       },
       {
         name: $localize`Severity`,
-        prop: 'labels.severity'
+        prop: 'labels.severity',
+        flexGrow: 1,
+        cellTransformation: CellTemplate.badge,
+        customTemplateConfig: {
+          map: {
+            critical: { class: 'badge-danger' },
+            warning: { class: 'badge-warning' }
+          }
+        }
       },
       {
         name: $localize`State`,
         prop: 'status.state',
-        cellTransformation: CellTemplate.classAdding
+        flexGrow: 1,
+        cellTransformation: CellTemplate.badge,
+        customTemplateConfig: {
+          map: {
+            active: { class: 'badge-info' },
+            unprocessed: { class: 'badge-warning' },
+            suppressed: { class: 'badge-dark' }
+          }
+        }
       },
       {
         name: $localize`Started`,
         prop: 'startsAt',
-        pipe: this.cdDatePipe
+        cellTransformation: CellTemplate.timeAgo,
+        flexGrow: 1
       },
       {
         name: $localize`URL`,
         prop: 'generatorURL',
+        flexGrow: 1,
         sortable: false,
         cellTemplate: this.externalLinkTpl
       }
index fd3967ce6939c3172901011da9151ba9835cfffd..3be6091a584c3d849a49c789a574a3fc1720c6df 100644 (file)
@@ -5,7 +5,11 @@
     class="nav-tabs">
   <li ngbNavItem="/monitoring/active-alerts">
     <a ngbNavLink
-       i18n>Active Alerts</a>
+       i18n>Active Alerts
+    <small *ngIf="prometheusAlertService.activeCriticalAlerts > 0"
+        class="badge badge-danger ml-1">{{ prometheusAlertService.activeCriticalAlerts }}</small>
+    <small *ngIf="prometheusAlertService.activeWarningAlerts > 0"
+        class="badge badge-warning ml-1">{{ prometheusAlertService.activeWarningAlerts }}</small></a>
   </li>
   <li ngbNavItem="/monitoring/alerts">
     <a ngbNavLink
index 675063413adc15c97f39a8b1b4e2d4ec31b2bc04..3272ae32fd0be06791c74eb4c8f28c6ec4b319ff 100644 (file)
@@ -3,6 +3,7 @@ import { RouterTestingModule } from '@angular/router/testing';
 
 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
 
+import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
 import { configureTestBed } from '~/testing/unit-test-helper';
 import { PrometheusTabsComponent } from './prometheus-tabs.component';
 
@@ -12,7 +13,8 @@ describe('PrometheusTabsComponent', () => {
 
   configureTestBed({
     imports: [RouterTestingModule, NgbNavModule],
-    declarations: [PrometheusTabsComponent]
+    declarations: [PrometheusTabsComponent],
+    providers: [{ provide: PrometheusAlertService, useValue: { alerts: [] } }]
   });
 
   beforeEach(() => {
index 4011770d4173ae7dd219aaeeac5bc190c302092c..cccce1d92e33c9b3cbcdc8814f0036a95ab9aa31 100644 (file)
@@ -1,11 +1,13 @@
 import { Component } from '@angular/core';
 import { Router } from '@angular/router';
 
+import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
+
 @Component({
   selector: 'cd-prometheus-tabs',
   templateUrl: './prometheus-tabs.component.html',
   styleUrls: ['./prometheus-tabs.component.scss']
 })
 export class PrometheusTabsComponent {
-  constructor(public router: Router) {}
+  constructor(public router: Router, public prometheusAlertService: PrometheusAlertService) {}
 }
index 325520d110ec984af4d6ce69372c0e0fbbc466ec..cc4ee511156d648978c6e3ab90416f93c785ca2b 100644 (file)
@@ -1,7 +1,11 @@
 import { Component, Inject, OnInit } from '@angular/core';
 
+import _ from 'lodash';
+
 import { PrometheusService } from '~/app/shared/api/prometheus.service';
+import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
+import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
 import { PrometheusRule } from '~/app/shared/models/prometheus-alerts';
 import { DurationPipe } from '~/app/shared/pipes/duration.pipe';
 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
@@ -15,6 +19,7 @@ import { PrometheusListHelper } from '../prometheus-list-helper';
 export class RulesListComponent extends PrometheusListHelper implements OnInit {
   columns: CdTableColumn[];
   expandedRow: PrometheusRule;
+  selection = new CdTableSelection();
 
   /**
    * Hide active alerts in details of alerting rules as they are already shown
@@ -33,12 +38,32 @@ export class RulesListComponent extends PrometheusListHelper implements OnInit {
   ngOnInit() {
     super.ngOnInit();
     this.columns = [
-      { prop: 'name', name: $localize`Name` },
-      { prop: 'labels.severity', name: $localize`Severity` },
-      { prop: 'group', name: $localize`Group` },
-      { prop: 'duration', name: $localize`Duration`, pipe: new DurationPipe() },
-      { prop: 'query', name: $localize`Query`, isHidden: true },
-      { prop: 'annotations.description', name: $localize`Description` }
+      { prop: 'name', name: $localize`Name`, cellClass: 'font-weight-bold', flexGrow: 2 },
+      {
+        prop: 'labels.severity',
+        name: $localize`Severity`,
+        flexGrow: 1,
+        cellTransformation: CellTemplate.badge,
+        customTemplateConfig: {
+          map: {
+            critical: { class: 'badge-danger' },
+            warning: { class: 'badge-warning' }
+          }
+        }
+      },
+      {
+        prop: 'group',
+        name: $localize`Group`,
+        flexGrow: 1,
+        cellTransformation: CellTemplate.badge
+      },
+      { prop: 'duration', name: $localize`Duration`, pipe: new DurationPipe(), flexGrow: 1 },
+      { prop: 'query', name: $localize`Query`, isHidden: true, flexGrow: 1 },
+      { prop: 'annotations.summary', name: $localize`Summary`, flexGrow: 3 }
     ];
   }
+
+  updateSelection(selection: CdTableSelection) {
+    this.selection = selection;
+  }
 }
index bdb35a610d973036def487cee01a53bbfc5acf63..39bcb5b6a0dc312fa873b21c6d0e3db9d808b265 100644 (file)
               *ngIf="permissions.prometheus.read">
             <a routerLink="/monitoring">
               <ng-container i18n>Monitoring</ng-container>
-              <small *ngIf="prometheusAlertService.activeAlerts > 0"
-                     class="badge badge-danger">{{ prometheusAlertService.activeAlerts }}</small>
+              <small *ngIf="prometheusAlertService.activeCriticalAlerts > 0"
+                     class="badge badge-danger ml-1">{{ prometheusAlertService.activeCriticalAlerts }}</small>
+              <small *ngIf="prometheusAlertService.activeWarningAlerts > 0"
+                     class="badge badge-warning ml-1">{{ prometheusAlertService.activeWarningAlerts }}</small>
             </a>
           </li>
         </ul>
index 71ba156cf3f607cb108325d0a1565a4b015a2e9c..b38477c813733430dc8733df46ffb4899455c500 100644 (file)
      (click)="toggleExpandRow(row, isExpanded, $event)">
   </a>
 </ng-template>
+
+<ng-template #timeAgoTpl
+             let-value="value">
+  <span data-toggle="tooltip"
+        [title]="value | cdDate">{{ value | relativeDate }}</span>
+</ng-template>
index 96bf2336e92d354a80bb91ffa730b9fb5c40a8ba..19ad5bc4e4e467bc2fbdeba0d4c3cac7ac44cf46 100644 (file)
@@ -65,6 +65,8 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
   mapTpl: TemplateRef<any>;
   @ViewChild('truncateTpl', { static: true })
   truncateTpl: TemplateRef<any>;
+  @ViewChild('timeAgoTpl', { static: true })
+  timeAgoTpl: TemplateRef<any>;
   @ViewChild('rowDetailsTpl', { static: true })
   rowDetailsTpl: TemplateRef<any>;
 
@@ -579,6 +581,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
     this.cellTemplates.badge = this.badgeTpl;
     this.cellTemplates.map = this.mapTpl;
     this.cellTemplates.truncate = this.truncateTpl;
+    this.cellTemplates.timeAgo = this.timeAgoTpl;
   }
 
   useCustomClass(value: any): string {
index 73ce1f23919f78f7a0a0f65dbe1dcad3a5c3ca38..066cc9930adce977811161e45d708f33c84bad14 100644 (file)
@@ -50,5 +50,10 @@ export enum CellTemplate {
   //     omission?: string; // Defaults to empty string.
   //   }
   // }
-  truncate = 'truncate'
+  truncate = 'truncate',
+  /*
+  This templace replaces a time, datetime or timestamp with a user-friendly "X {seconds,minutes,hours,days,...} ago",
+  but the tooltip still displays the absolute timestamp
+  */
+  timeAgo = 'timeAgo'
 }
index 6223808fb0122e3bd5cd3a3a62c1580a138fd8d0..f26b80629b9206f61496dc4bcf513ef6eaa90e94 100644 (file)
@@ -18,6 +18,8 @@ export class PrometheusAlertService {
   alerts: AlertmanagerAlert[] = [];
   rules: PrometheusRule[] = [];
   activeAlerts: number;
+  activeCriticalAlerts: number;
+  activeWarningAlerts: number;
 
   constructor(
     private alertFormatter: PrometheusAlertFormatter,
@@ -66,6 +68,18 @@ export class PrometheusAlertService {
       (result, alert) => (alert.status.state === 'active' ? ++result : result),
       0
     );
+    this.activeCriticalAlerts = _.reduce<AlertmanagerAlert, number>(
+      this.alerts,
+      (result, alert) =>
+        alert.status.state === 'active' && alert.labels.severity === 'critical' ? ++result : result,
+      0
+    );
+    this.activeWarningAlerts = _.reduce<AlertmanagerAlert, number>(
+      this.alerts,
+      (result, alert) =>
+        alert.status.state === 'active' && alert.labels.severity === 'warning' ? ++result : result,
+      0
+    );
     this.alerts = alerts;
     this.canAlertsBeNotified = true;
   }