Skip to content

Commit 286aecf

Browse files
committed
[FEATURE] add alerts and silences data type definitions for alert manager plugin
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
1 parent b04221f commit 286aecf

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
export interface AlertStatus {
15+
state: 'active' | 'suppressed' | 'unprocessed';
16+
silencedBy: string[];
17+
inhibitedBy: string[];
18+
mutedBy: string[];
19+
}
20+
21+
export interface Receiver {
22+
name: string;
23+
}
24+
25+
export interface Alert {
26+
labels: Record<string, string>;
27+
annotations: Record<string, string>;
28+
receivers: Receiver[];
29+
status: AlertStatus;
30+
startsAt: string;
31+
endsAt: string;
32+
updatedAt: string;
33+
generatorURL?: string;
34+
fingerprint: string;
35+
}
36+
37+
export interface AlertsData {
38+
alerts: Alert[];
39+
}

ts/src/dashboard/query-type/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
export * from './alerts-data';
1415
export * from './profile-data';
1516
export * from './query';
1617
export * from './base-metadata';
18+
export * from './silences-data';
1719
export * from './time-series-queries';
1820
export * from './time-series-data';
1921
export * from './trace-data';

ts/src/dashboard/query-type/query.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { TimeSeriesData } from './time-series-data';
1616
import { TraceData } from './trace-data';
1717
import { LogData } from './log-data';
1818
import { ProfileData } from './profile-data';
19+
import { AlertsData } from './alerts-data';
20+
import { SilencesData } from './silences-data';
1921

2022
interface QuerySpec<PluginSpec> {
2123
name?: string;
@@ -39,16 +41,18 @@ export interface QueryType {
3941
TraceQuery: TraceData;
4042
ProfileQuery: ProfileData;
4143
LogQuery: LogData;
42-
// in the future we can add other query plugin and data types
43-
// for example: we can add something like `LogsQuery: LogsData;`
44+
AlertsQuery: AlertsData;
45+
SilencesQuery: SilencesData;
4446
}
4547

4648
/**
4749
* Check if the given type is a valid {@link QueryPluginType} with compile time safety
4850
* @param type
4951
*/
5052
export function isValidQueryPluginType(type: string): type is QueryPluginType {
51-
return ['TimeSeriesQuery', 'TraceQuery', 'ProfileQuery'].includes(type as QueryPluginType);
53+
return ['TimeSeriesQuery', 'TraceQuery', 'ProfileQuery', 'LogQuery', 'AlertsQuery', 'SilencesQuery'].includes(
54+
type as QueryPluginType
55+
);
5256
}
5357

5458
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
export interface Matcher {
15+
name: string;
16+
value: string;
17+
isEqual?: boolean;
18+
isRegex: boolean;
19+
}
20+
21+
export interface SilenceStatus {
22+
state: 'active' | 'expired' | 'pending';
23+
}
24+
25+
export interface Silence {
26+
id: string;
27+
matchers: Matcher[];
28+
startsAt: string;
29+
endsAt: string;
30+
createdBy: string;
31+
comment: string;
32+
status: SilenceStatus;
33+
updatedAt: string;
34+
annotations: Record<string, string>;
35+
}
36+
37+
export interface SilencesData {
38+
silences: Silence[];
39+
}

0 commit comments

Comments
 (0)