import { inject, Injectable } from '@angular/core';
import { PrometheusService } from './prometheus.service';
-import { PerformanceData, StorageType } from '../models/performance-data';
+import { PerformanceData } from '../models/performance-data';
import { AllStoragetypesQueries } from '../enum/dashboard-promqls.enum';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
export class PerformanceCardService {
private prometheusService = inject(PrometheusService);
- getChartData(
- time: { start: number; end: number; step: number },
- selectedStorageType: StorageType
- ): Observable<PerformanceData> {
- const queries = this.buildQueriesForStorageType(selectedStorageType);
-
- return this.prometheusService.getRangeQueriesData(time, queries, true).pipe(
+ getChartData(time: { start: number; end: number; step: number }): Observable<PerformanceData> {
+ return this.prometheusService.getRangeQueriesData(time, AllStoragetypesQueries, true).pipe(
map((raw) => {
const chartData = this.convertPerformanceData(raw);
);
}
- private buildQueriesForStorageType(storageType: StorageType) {
- const queries: any = {};
-
- const applicationFilter =
- storageType === StorageType.All ? '' : `{application="${storageType}"}`;
-
- Object.entries(AllStoragetypesQueries).forEach(([key, query]) => {
- queries[key] = query.replace('{{applicationFilter}}', applicationFilter);
- });
-
- return queries;
- }
-
convertPerformanceData(raw: any): PerformanceData {
return {
iops: this.mergeSeries(
i18n>Performance</h2>
<div cdsStack="horizontal"
gap="2">
- <cds-dropdown
- [placeholder]="selectedStorageType"
- (selected)="onStorageTypeSelection($event)"
- [label]="'Storage Type'"
- class="overview-storage-card-dropdown"
- [inline]="true"
- size="sm"
- i18n>
- <cds-dropdown-list
- [items]="storageTypes"
- size="sm"></cds-dropdown-list>
- </cds-dropdown>
-
<cd-time-picker
[dropdwonSize]="'sm'"
[label]="'Time Span'"
import { PrometheusService } from '../../api/prometheus.service';
import { PerformanceCardService } from '../../api/performance-card.service';
import { MgrModuleService } from '../../api/mgr-module.service';
-import { StorageType, PerformanceData } from '../../models/performance-data';
+import { PerformanceData } from '../../models/performance-data';
import { DatePipe } from '@angular/common';
import { NumberFormatterService } from '../../services/number-formatter.service';
component.loadCharts(time);
expect(component.time).toEqual(time);
- expect(performanceCardService.getChartData).toHaveBeenCalledWith(
- time,
- component.selectedStorageType
- );
+ expect(performanceCardService.getChartData).toHaveBeenCalledWith(time);
tick();
expect(component.chartDataSignal()).toEqual(mockChartData);
expect(component.emptyStateKey()).toBe('prometheusNotAvailable');
}));
- it('should update selectedStorageType and reload charts on storage type selection', () => {
- const loadChartsSpy = jest.spyOn(component, 'loadCharts');
- const event = { item: { value: StorageType.Filesystem } };
-
- component.onStorageTypeSelection(event);
-
- expect(component.selectedStorageType).toBe(StorageType.Filesystem);
- expect(loadChartsSpy).toHaveBeenCalledWith(component.time);
- });
-
it('should cleanup subscriptions on ngOnDestroy', () => {
const destroyNextSpy = jest.spyOn(component['destroy$'], 'next');
const destroyCompleteSpy = jest.spyOn(component['destroy$'], 'complete');
}
];
- selectedStorageType = StorageType.All;
-
private prometheusService = inject(PrometheusService);
private performanceCardService = inject(PerformanceCardService);
private mgrModuleService = inject(MgrModuleService);
this.chartSub?.unsubscribe();
this.chartSub = this.performanceCardService
- .getChartData(time, this.selectedStorageType)
+ .getChartData(time)
.pipe(takeUntil(this.destroy$))
.subscribe((data) => {
this.chartDataSignal.set(data);
});
}
- onStorageTypeSelection(event: any) {
- this.selectedStorageType = event.item.value;
- this.loadCharts(this.time);
- }
-
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
export const AllStoragetypesQueries = {
- READIOPS: `
- sum(
- rate(ceph_pool_rd[1m])
- * on (pool_id, cluster)
- group_left(application)
- ceph_pool_metadata{{applicationFilter}}
- ) OR vector(0)
- `,
+ READIOPS: `sum(rate(ceph_osd_op_r[1m]))`,
- WRITEIOPS: `
- sum(
- rate(ceph_pool_wr[1m])
- * on (pool_id, cluster)
- group_left(application)
- ceph_pool_metadata{{applicationFilter}}
- ) OR vector(0)
- `,
+ WRITEIOPS: `sum(rate(ceph_osd_op_w[1m]))`,
- READCLIENTTHROUGHPUT: `
- sum(
- rate(ceph_pool_rd_bytes[1m])
- * on (pool_id, cluster)
- group_left(application)
- ceph_pool_metadata{{applicationFilter}}
- ) OR vector(0)
- `,
+ READCLIENTTHROUGHPUT: `sum(rate(ceph_osd_op_r_out_bytes[1m]))`,
- WRITECLIENTTHROUGHPUT: `
- sum(
- rate(ceph_pool_wr_bytes[1m])
- * on (pool_id, cluster)
- group_left(application)
- ceph_pool_metadata{{applicationFilter}}
- ) OR vector(0)
- `,
+ WRITECLIENTTHROUGHPUT: `sum(rate(ceph_osd_op_w_in_bytes[1m]))`,
READLATENCY: 'avg_over_time(ceph_osd_apply_latency_ms[1m])',