Alerting: unified alerting frontend (#32708)

This commit is contained in:
Domas
2021-04-07 08:42:43 +03:00
committed by GitHub
parent 6082a9360e
commit a56293142a
79 changed files with 3857 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ import { ThunkAction, ThunkDispatch as GenericThunkDispatch } from 'redux-thunk'
import { PayloadAction } from '@reduxjs/toolkit';
import { NavIndex } from '@grafana/data';
import { AlertDefinitionState, AlertRulesState, NotificationChannelState } from './alerting';
import { UnifiedAlertingState } from '../features/alerting/unified/state/reducers';
import { TeamsState, TeamState } from './teams';
import { FolderState } from './folders';
import { DashboardState } from './dashboard';
@@ -43,6 +44,7 @@ export interface StoreState {
importDashboard: ImportDashboardState;
notificationChannel: NotificationChannelState;
alertDefinition: AlertDefinitionState;
unifiedAlerting: UnifiedAlertingState;
}
/*

View File

@@ -0,0 +1,96 @@
// Prometheus API DTOs, possibly to be autogenerated from openapi spec in the near future
export type Labels = Record<string, string>;
export type Annotations = Record<string, string>;
export enum PromAlertingRuleState {
Firing = 'firing',
Inactive = 'inactive',
Pending = 'pending',
}
export enum PromRuleType {
Alerting = 'alerting',
Recording = 'recording',
}
interface PromRuleDTOBase {
health: string;
name: string;
query: string; // expr
evaluationTime?: number;
lastEvaluation?: string;
lastError?: string;
}
export interface PromAlertingRuleDTO extends PromRuleDTOBase {
alerts: Array<{
labels: Labels;
annotations: Annotations;
state: Exclude<PromAlertingRuleState, PromAlertingRuleState.Inactive>;
activeAt: string;
value: string;
}>;
labels: Labels;
annotations: Annotations;
duration?: number; // for
state: PromAlertingRuleState;
type: PromRuleType.Alerting;
}
export interface PromRecordingRuleDTO extends PromRuleDTOBase {
health: string;
name: string;
query: string; // expr
type: PromRuleType.Recording;
labels?: Labels;
}
export type PromRuleDTO = PromAlertingRuleDTO | PromRecordingRuleDTO;
export interface PromRuleGroupDTO {
name: string;
file: string;
rules: PromRuleDTO[];
interval: number;
evaluationTime?: number; // these 2 are not in older prometheus payloads
lastEvaluation?: string;
}
export interface PromResponse<T> {
status: 'success' | 'error' | ''; // mocks return empty string
data: T;
errorType?: string;
error?: string;
warnings?: string[];
}
export type PromRulesResponse = PromResponse<{ groups: PromRuleGroupDTO[] }>;
// Ruler rule DTOs
interface RulerRuleBaseDTO {
expr: string;
labels?: Labels;
}
export interface RulerRecordingRuleDTO extends RulerRuleBaseDTO {
record: string;
}
export interface RulerAlertingRuleDTO extends RulerRuleBaseDTO {
alert: string;
for?: string;
annotations?: Annotations;
}
export type RulerRuleDTO = RulerAlertingRuleDTO | RulerRecordingRuleDTO;
export type RulerRuleGroupDTO = {
name: string;
interval?: string;
rules: RulerRuleDTO[];
};
export type RulerRulesConfigDTO = { [namespace: string]: RulerRuleGroupDTO[] };

View File

@@ -0,0 +1,93 @@
/* Prometheus internal models */
import { DataSourceInstanceSettings } from '@grafana/data';
import { PromAlertingRuleState, PromRuleType, RulerRuleDTO, Labels, Annotations } from './unified-alerting-dto';
export type Alert = {
activeAt: string;
annotations: { [key: string]: string };
labels: { [key: string]: string };
state: PromAlertingRuleState;
value: string;
};
interface RuleBase {
health: string;
name: string;
query: string;
lastEvaluation?: string;
evaluationTime?: number;
lastError?: string;
}
export interface AlertingRule extends RuleBase {
alerts: Alert[];
labels: {
[key: string]: string;
};
annotations?: {
[key: string]: string;
};
state: PromAlertingRuleState;
type: PromRuleType.Alerting;
}
export interface RecordingRule extends RuleBase {
type: PromRuleType.Recording;
labels?: {
[key: string]: string;
};
}
export type Rule = AlertingRule | RecordingRule;
export type BaseRuleGroup = { name: string };
export interface RuleGroup {
name: string;
interval: number;
rules: Rule[];
}
export interface RuleNamespace {
dataSourceName: string;
name: string;
groups: RuleGroup[];
}
export interface RulesSourceResult {
dataSourceName: string;
error?: unknown;
namespaces?: RuleNamespace[];
}
export type RulesSource = DataSourceInstanceSettings | 'grafana';
// combined prom and ruler result
export interface CombinedRule {
name: string;
query: string;
labels: Labels;
annotations: Annotations;
promRule?: Rule;
rulerRule?: RulerRuleDTO;
}
export interface CombinedRuleGroup {
name: string;
rules: CombinedRule[];
}
export interface CombinedRuleNamespace {
rulesSource: RulesSource;
name: string;
groups: CombinedRuleGroup[];
}
export interface RuleLocation {
ruleSourceName: string;
namespace: string;
groupName: string;
ruleHash: number;
}