Skip to content

Commit 7017c28

Browse files
chore: simplify alert creation and evaluation (#1388)
removed stream name, condition config, aggregate config from alert request add query as parameter rename aggregateConfig to thresholdConfig new payload ``` { "severity": "high", "title": "error count", "alertType": "threshold", "query": "SELECT COUNT(`body`) AS `COUNT_body` FROM `test1` WHERE `severity_text` = 'ERROR' LIMIT 500", "thresholdConfig": { "operator": ">", "value": 1000 }, "evalConfig": { "rollingWindow": { "evalStart": "5h", "evalEnd": "now", "evalFrequency": 1 } }, "targets": [ "01K0XDNX76DXGHQ1T32XG63K27" ] } ```
1 parent 30ee3d4 commit 7017c28

File tree

8 files changed

+1018
-528
lines changed

8 files changed

+1018
-528
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ulid = { version = "1.0", features = ["serde"] }
132132
xxhash-rust = { version = "0.8", features = ["xxh3"] }
133133
futures-core = "0.3.31"
134134
tempfile = "3.20.0"
135+
lazy_static = "1.4.0"
135136

136137
[build-dependencies]
137138
cargo_toml = "0.21"

resources/ingest_demo_data.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ create_alerts() {
415415
echo "Creating alerts with target ID: $target_id"
416416

417417
# Alert 1: Error Count (severity_number = 18)
418-
alert1_json="{\"severity\":\"high\",\"title\":\"error count\",\"stream\":\"$P_STREAM\",\"alertType\":\"threshold\",\"aggregates\":{\"aggregateConfig\":[{\"aggregateFunction\":\"count\",\"conditions\":{\"operator\":null,\"conditionConfig\":[{\"column\":\"severity_number\",\"operator\":\"=\",\"value\":\"18\"}]},\"column\":\"severity_number\",\"operator\":\">\",\"value\":1000}]},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
419-
418+
alert1_json="{\"severity\":\"high\",\"title\":\"error count\",\"alertType\":\"threshold\",\"query\": \"select count(severity_number) as count_severity_number from demodata where severity_number=18\",\"thresholdConfig\":{\"operator\":\">\",\"value\":1000},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
419+
420420
response1=$(curl_with_retry "$P_URL/api/v1/alerts" "POST" "$alert1_json" "application/json" 3)
421421
if [[ $? -eq 0 ]]; then
422422
echo "Alert 1 (Error Count) created successfully"
@@ -426,8 +426,8 @@ create_alerts() {
426426
fi
427427

428428
# Alert 2: 400 Errors
429-
alert2_json="{\"severity\":\"critical\",\"title\":\"400 Errors\",\"stream\":\"$P_STREAM\",\"alertType\":\"threshold\",\"aggregates\":{\"aggregateConfig\":[{\"aggregateFunction\":\"count\",\"conditions\":{\"operator\":null,\"conditionConfig\":[{\"column\":\"body\",\"operator\":\"contains\",\"value\":\"400\"}]},\"column\":\"body\",\"operator\":\">\",\"value\":10}]},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
430-
429+
alert2_json="{\"severity\":\"critical\",\"title\":\"400 Errors\",\"alertType\":\"threshold\",\"query\": \"select count(body) as count_body from demodata where body like '%400%'\",\"thresholdConfig\":{\"operator\":\">\",\"value\":10},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
430+
431431
response2=$(curl_with_retry "$P_URL/api/v1/alerts" "POST" "$alert2_json" "application/json" 3)
432432
if [[ $? -eq 0 ]]; then
433433
echo "Alert 2 (400 Errors) created successfully"
@@ -437,7 +437,7 @@ create_alerts() {
437437
fi
438438

439439
# Alert 3: Trace ID null
440-
alert3_json="{\"severity\":\"high\",\"title\":\"Trace ID null\",\"stream\":\"$P_STREAM\",\"alertType\":\"threshold\",\"aggregates\":{\"aggregateConfig\":[{\"aggregateFunction\":\"count\",\"conditions\":{\"operator\":null,\"conditionConfig\":[{\"column\":\"trace_id\",\"operator\":\"is null\",\"value\":null}]},\"column\":\"trace_id\",\"operator\":\">\",\"value\":0}]},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
440+
alert3_json="{\"severity\":\"high\",\"title\":\"Trace ID null\",\"alertType\":\"threshold\",\"query\": \"select count(trace_id) as count_trace_id from demodata where trace_id is null\",\"thresholdConfig\":{\"operator\":\">\",\"value\":0},\"evalConfig\":{\"rollingWindow\":{\"evalStart\":\"5h\",\"evalEnd\":\"now\",\"evalFrequency\":1}},\"targets\":[\"$target_id\"]}"
441441
response3=$(curl_with_retry "$P_URL/api/v1/alerts" "POST" "$alert3_json" "application/json" 3)
442442
if [[ $? -eq 0 ]]; then
443443
echo "Alert 3 (Trace ID null) created successfully"

0 commit comments

Comments
 (0)