1/* Prometheus internal models */
2
3import { AlertState, DataSourceInstanceSettings } from '@grafana/data';
4import {
5  PromAlertingRuleState,
6  PromRuleType,
7  RulerRuleDTO,
8  Labels,
9  Annotations,
10  RulerRuleGroupDTO,
11  GrafanaAlertState,
12} from './unified-alerting-dto';
13
14export type Alert = {
15  activeAt: string;
16  annotations: { [key: string]: string };
17  labels: { [key: string]: string };
18  state: PromAlertingRuleState | GrafanaAlertState;
19  value: string;
20};
21interface RuleBase {
22  health: string;
23  name: string;
24  query: string;
25  lastEvaluation?: string;
26  evaluationTime?: number;
27  lastError?: string;
28}
29
30export interface AlertingRule extends RuleBase {
31  alerts: Alert[];
32  labels: {
33    [key: string]: string;
34  };
35  annotations?: {
36    [key: string]: string;
37  };
38  state: PromAlertingRuleState;
39  type: PromRuleType.Alerting;
40}
41
42export interface RecordingRule extends RuleBase {
43  type: PromRuleType.Recording;
44
45  labels?: {
46    [key: string]: string;
47  };
48}
49
50export type Rule = AlertingRule | RecordingRule;
51
52export type BaseRuleGroup = { name: string };
53
54export interface RuleGroup {
55  name: string;
56  interval: number;
57  rules: Rule[];
58}
59
60export interface RuleNamespace {
61  dataSourceName: string;
62  name: string;
63  groups: RuleGroup[];
64}
65
66export interface RulesSourceResult {
67  dataSourceName: string;
68  error?: unknown;
69  namespaces?: RuleNamespace[];
70}
71
72export type RulesSource = DataSourceInstanceSettings | 'grafana';
73
74// combined prom and ruler result
75export interface CombinedRule {
76  name: string;
77  query: string;
78  labels: Labels;
79  annotations: Annotations;
80  promRule?: Rule;
81  rulerRule?: RulerRuleDTO;
82  group: CombinedRuleGroup;
83  namespace: CombinedRuleNamespace;
84}
85
86export interface CombinedRuleGroup {
87  name: string;
88  interval?: string;
89  rules: CombinedRule[];
90}
91
92export interface CombinedRuleNamespace {
93  rulesSource: RulesSource;
94  name: string;
95  groups: CombinedRuleGroup[];
96}
97
98export interface RuleWithLocation {
99  ruleSourceName: string;
100  namespace: string;
101  group: RulerRuleGroupDTO;
102  rule: RulerRuleDTO;
103}
104
105export interface PromRuleWithLocation {
106  rule: AlertingRule;
107  dataSourceName: string;
108  namespaceName: string;
109  groupName: string;
110}
111
112export interface CloudRuleIdentifier {
113  ruleSourceName: string;
114  namespace: string;
115  groupName: string;
116  rulerRuleHash: number;
117}
118export interface GrafanaRuleIdentifier {
119  uid: string;
120}
121
122// Rule read directly from Prometheus without existing in the ruler API
123export interface PrometheusRuleIdentifier {
124  ruleSourceName: string;
125  namespace: string;
126  groupName: string;
127  ruleHash: number;
128}
129
130export type RuleIdentifier = CloudRuleIdentifier | GrafanaRuleIdentifier | PrometheusRuleIdentifier;
131export interface FilterState {
132  queryString?: string;
133  dataSource?: string;
134  alertState?: string;
135  groupBy?: string[];
136  ruleType?: string;
137}
138
139export interface SilenceFilterState {
140  queryString?: string;
141  silenceState?: string;
142}
143
144interface EvalMatch {
145  metric: string;
146  tags?: any;
147  value: number;
148}
149
150export interface StateHistoryItemData {
151  noData: boolean;
152  evalMatches?: EvalMatch[];
153}
154
155export interface StateHistoryItem {
156  id: number;
157  alertId: number;
158  alertName: string;
159  dashboardId: number;
160  panelId: number;
161  userId: number;
162  newState: AlertState;
163  prevState: AlertState;
164  created: number;
165  updated: number;
166  time: number;
167  timeEnd: number;
168  text: string;
169  tags: any[];
170  login: string;
171  email: string;
172  avatarUrl: string;
173  data: StateHistoryItemData;
174}
175