Skip to content

Commit

Permalink
feat: Display alert count on deployments table
Browse files Browse the repository at this point in the history
  • Loading branch information
tiithansen committed Jun 13, 2024
1 parent d5cfc9f commit 29fb707
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/pages/Workloads/tabs/Deployments/DeploymentExpandedRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SceneFlexLayout } from "@grafana/scenes";
import { SceneFlexItem, SceneFlexLayout } from "@grafana/scenes";
import { getPodsScene } from "../Pods/Pods";
import { LabelFilters } from "common/queryHelpers";
import { TableRow } from "./types";
import { AlertsTable } from "components/AlertsTable";

export function buildExpandedRowScene(row: TableRow) {

Expand All @@ -21,10 +22,30 @@ export function buildExpandedRowScene(row: TableRow) {

return new SceneFlexLayout({
key: `${row.namespace}/${row.deployment}`,
direction: 'column',
width: '100%',
height: 500,
children: [
getPodsScene(staticLabelFilters, false, false)
new SceneFlexLayout({
direction: 'row',
height: 300,
children: [
getPodsScene(staticLabelFilters, false, false)
]
}),
new SceneFlexLayout({
direction: 'row',
children: [
new SceneFlexItem({
body: AlertsTable([
{
label: 'deployment',
op: '=',
value: row.deployment
}
], false, false)
})
]
}),
],
});
}
17 changes: 16 additions & 1 deletion src/pages/Workloads/tabs/Deployments/Deployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SceneVariableSet,
} from '@grafana/scenes';
import { ReplicasCell } from 'pages/Workloads/components/ReplicasCell';
import { getSeriesValue } from 'common/seriesHelpers';
import { getAllSeries, getSeriesValue } from 'common/seriesHelpers';
import { buildExpandedRowScene } from './DeploymentExpandedRow';
import { createNamespaceVariable } from 'common/variableHelpers';
import { TableRow } from './types';
Expand Down Expand Up @@ -52,6 +52,19 @@ const columns: Array<Column<TableRow>> = [
local: true,
}
},
{
id: 'alerts',
header: 'ALERTS',
sortingConfig: {
enabled: true,
local: false,
type: 'value'
},
accessor: (row: TableRow) => row.alerts ? row.alerts.length : 0,
cellProps: {
// color: determineAlertsColor
}
},
{
id: 'replicas',
header: 'REPLICAS',
Expand All @@ -78,6 +91,8 @@ function asyncRowMapper(row: TableRow, asyncRowData: any) {
total,
ready
}

row.alerts = getAllSeries(asyncRowData, 'alerts', serieMatcherPredicate(row))
}

function createRowId(row: TableRow) {
Expand Down
19 changes: 18 additions & 1 deletion src/pages/Workloads/tabs/Deployments/Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@ import { TableRow } from "./types";
import { QueryBuilder, ColumnSortingConfig } from "components/AsyncTable";
import { SortingState } from "common/sortingHelpers";

function createAlertsQuery(cluster?: string, deployments?: string) {
return `
ALERTS{
cluster="${cluster}",
${deployments ? `deployment=~"${deployments}",` : ''}
alertstate="firing",
}
* ignoring(alertstate) group_right(alertstate) ALERTS_FOR_STATE{
cluster="${cluster}",
${deployments ? `deployment=~"${deployments}",` : ''}
}
`
}

function createRowQueries(rows: TableRow[], sceneVariables: SceneVariables) {

const deployments = rows.map(row => row.deployment).join('|');
const cluster = resolveVariable(sceneVariables, 'cluster');

return [
{

refId: 'alerts',
expr: createAlertsQuery(cluster?.toString(), deployments),
instant: true,
format: 'table'
},
{
refId: 'replicas',
Expand Down
8 changes: 8 additions & 0 deletions src/pages/Workloads/tabs/Deployments/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

export interface DeploymentAlert {
deployment: string;
alertname: string;
severity: string;
}

export interface TableRow {
cluster: string;
deployment: string;
Expand All @@ -8,4 +15,5 @@ export interface TableRow {
ready: number;
total: number;
}
alerts: DeploymentAlert[];
}

0 comments on commit 29fb707

Please sign in to comment.