2024-03-04 10:15:43 +05:30
import { ENTITY_VERSION_V4 } from 'constants/app' ;
2023-05-10 19:40:27 +03:00
import {
2023-06-16 13:38:39 +03:00
initialQueryBuilderFormValuesMap ,
2023-06-01 20:17:09 +03:00
initialQueryPromQLData ,
2023-05-10 19:40:27 +03:00
PANEL_TYPES ,
} from 'constants/queryBuilder' ;
2022-11-24 13:21:46 +05:30
import { AlertTypes } from 'types/api/alerts/alertTypes' ;
import {
AlertDef ,
defaultCompareOp ,
defaultEvalWindow ,
defaultMatchType ,
} from 'types/api/alerts/def' ;
2023-05-10 19:40:27 +03:00
import { EQueryType } from 'types/common/dashboard' ;
2022-11-24 13:21:46 +05:30
2023-02-10 23:53:45 +05:30
const defaultAlertDescription =
'This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})' ;
const defaultAlertSummary =
'The rule threshold is set to {{$threshold}}, and the observed metric value is {{$value}}' ;
const defaultAnnotations = {
description : defaultAlertDescription ,
summary : defaultAlertSummary ,
} ;
2022-11-24 13:21:46 +05:30
export const alertDefaults : AlertDef = {
alertType : AlertTypes.METRICS_BASED_ALERT ,
2024-03-04 10:15:43 +05:30
version : ENTITY_VERSION_V4 ,
2022-11-24 13:21:46 +05:30
condition : {
2023-05-10 19:40:27 +03:00
compositeQuery : {
2022-11-24 13:21:46 +05:30
builderQueries : {
2023-06-16 13:38:39 +03:00
A : initialQueryBuilderFormValuesMap.metrics ,
2022-11-24 13:21:46 +05:30
} ,
2023-06-01 20:17:09 +03:00
promQueries : { A : initialQueryPromQLData } ,
2023-05-19 12:19:42 +05:30
chQueries : {
A : {
name : 'A' ,
query : ` ` ,
legend : '' ,
disabled : false ,
} ,
} ,
2023-06-23 11:22:34 +05:30
queryType : EQueryType.QUERY_BUILDER ,
2023-05-10 19:40:27 +03:00
panelType : PANEL_TYPES.TIME_SERIES ,
2023-08-15 06:37:26 +05:30
unit : undefined ,
2022-11-24 13:21:46 +05:30
} ,
op : defaultCompareOp ,
matchType : defaultMatchType ,
} ,
labels : {
severity : 'warning' ,
} ,
2023-02-10 23:53:45 +05:30
annotations : defaultAnnotations ,
2022-11-24 13:21:46 +05:30
evalWindow : defaultEvalWindow ,
} ;
export const logAlertDefaults : AlertDef = {
alertType : AlertTypes.LOGS_BASED_ALERT ,
condition : {
2023-05-10 19:40:27 +03:00
compositeQuery : {
2022-11-24 13:21:46 +05:30
builderQueries : {
2023-06-16 13:38:39 +03:00
A : initialQueryBuilderFormValuesMap.logs ,
2022-11-24 13:21:46 +05:30
} ,
2023-06-01 20:17:09 +03:00
promQueries : { A : initialQueryPromQLData } ,
2022-11-24 13:21:46 +05:30
chQueries : {
A : {
name : 'A' ,
2022-12-09 21:54:51 +05:30
query : ` select \ ntoStartOfInterval(fromUnixTimestamp64Nano(timestamp), INTERVAL 30 MINUTE) AS interval, \ ntoFloat64(count()) as value \ nFROM signoz_logs.distributed_logs \ nWHERE timestamp BETWEEN {{.start_timestamp_nano}} AND {{.end_timestamp_nano}} \ nGROUP BY interval; \ n \ n-- available variables: \ n-- \ t{{.start_timestamp_nano}} \ n-- \ t{{.end_timestamp_nano}} \ n \ n-- required columns (or alias): \ n-- \ tvalue \ n-- \ tinterval ` ,
2022-11-24 13:21:46 +05:30
legend : '' ,
disabled : false ,
} ,
} ,
2023-06-23 11:22:34 +05:30
queryType : EQueryType.QUERY_BUILDER ,
2023-05-10 19:40:27 +03:00
panelType : PANEL_TYPES.TIME_SERIES ,
2023-08-15 06:37:26 +05:30
unit : undefined ,
2022-11-24 13:21:46 +05:30
} ,
op : defaultCompareOp ,
matchType : '4' ,
} ,
labels : {
severity : 'warning' ,
} ,
2023-02-10 23:53:45 +05:30
annotations : defaultAnnotations ,
2022-11-24 13:21:46 +05:30
evalWindow : defaultEvalWindow ,
} ;
export const traceAlertDefaults : AlertDef = {
alertType : AlertTypes.TRACES_BASED_ALERT ,
condition : {
2023-05-10 19:40:27 +03:00
compositeQuery : {
2022-11-24 13:21:46 +05:30
builderQueries : {
2023-06-16 13:38:39 +03:00
A : initialQueryBuilderFormValuesMap.traces ,
2022-11-24 13:21:46 +05:30
} ,
2023-06-01 20:17:09 +03:00
promQueries : { A : initialQueryPromQLData } ,
2022-11-24 13:21:46 +05:30
chQueries : {
A : {
name : 'A' ,
2022-12-09 21:54:51 +05:30
query : ` SELECT \ n \ ttoStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval, \ n \ ttagMap['peer.service'] AS op_name, \ n \ ttoFloat64(avg(durationNano)) AS value \ nFROM signoz_traces.distributed_signoz_index_v2 \ nWHERE tagMap['peer.service']!='' \ nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}} \ nGROUP BY (op_name, interval); \ n \ n-- available variables: \ n-- \ t{{.start_datetime}} \ n-- \ t{{.end_datetime}} \ n \ n-- required column alias: \ n-- \ tvalue \ n-- \ tinterval ` ,
2022-11-24 13:21:46 +05:30
legend : '' ,
disabled : false ,
} ,
} ,
2023-06-23 11:22:34 +05:30
queryType : EQueryType.QUERY_BUILDER ,
2023-05-10 19:40:27 +03:00
panelType : PANEL_TYPES.TIME_SERIES ,
2023-08-15 06:37:26 +05:30
unit : undefined ,
2022-11-24 13:21:46 +05:30
} ,
op : defaultCompareOp ,
matchType : '4' ,
} ,
labels : {
severity : 'warning' ,
} ,
2023-02-10 23:53:45 +05:30
annotations : defaultAnnotations ,
2022-11-24 13:21:46 +05:30
evalWindow : defaultEvalWindow ,
} ;
2022-11-24 18:00:02 +05:30
export const exceptionAlertDefaults : AlertDef = {
alertType : AlertTypes.EXCEPTIONS_BASED_ALERT ,
condition : {
2023-05-10 19:40:27 +03:00
compositeQuery : {
2022-11-24 18:00:02 +05:30
builderQueries : {
2023-06-16 13:38:39 +03:00
A : initialQueryBuilderFormValuesMap.traces ,
2022-11-24 18:00:02 +05:30
} ,
2023-06-01 20:17:09 +03:00
promQueries : { A : initialQueryPromQLData } ,
2022-11-24 18:00:02 +05:30
chQueries : {
A : {
name : 'A' ,
2022-12-09 21:54:51 +05:30
query : ` SELECT \ n \ tcount() as value, \ n \ ttoStartOfInterval(timestamp, toIntervalMinute(1)) AS interval, \ n \ tserviceName \ nFROM signoz_traces.distributed_signoz_error_index_v2 \ nWHERE exceptionType !='OSError' \ nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}} \ nGROUP BY serviceName, interval; \ n \ n-- available variables: \ n-- \ t{{.start_datetime}} \ n-- \ t{{.end_datetime}} \ n \ n-- required column alias: \ n-- \ tvalue \ n-- \ tinterval ` ,
2022-11-24 18:00:02 +05:30
legend : '' ,
disabled : false ,
} ,
} ,
2024-06-13 22:16:39 +05:30
queryType : EQueryType.CLICKHOUSE ,
2023-05-10 19:40:27 +03:00
panelType : PANEL_TYPES.TIME_SERIES ,
2023-08-15 06:37:26 +05:30
unit : undefined ,
2022-11-24 18:00:02 +05:30
} ,
op : defaultCompareOp ,
matchType : '4' ,
} ,
labels : {
severity : 'warning' ,
} ,
2023-02-10 23:53:45 +05:30
annotations : defaultAnnotations ,
2022-11-24 18:00:02 +05:30
evalWindow : defaultEvalWindow ,
} ;
2023-06-01 20:17:09 +03:00
export const ALERTS_VALUES_MAP : Record < AlertTypes , AlertDef > = {
[ AlertTypes . METRICS_BASED_ALERT ] : alertDefaults ,
[ AlertTypes . LOGS_BASED_ALERT ] : logAlertDefaults ,
[ AlertTypes . TRACES_BASED_ALERT ] : traceAlertDefaults ,
[ AlertTypes . EXCEPTIONS_BASED_ALERT ] : exceptionAlertDefaults ,
} ;