Skip to content

Commit ef52f9c

Browse files
update notification message
1 parent 7a84874 commit ef52f9c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/alerts/alerts_utils.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,14 @@ async fn update_alert_state(
181181
) -> Result<(), AlertError> {
182182
if final_res {
183183
let message = format!(
184-
"Expected Value: {} {} {}\n Actual Value: {}\nEvaluation Window: {}\nEvaluation Frequency: {}m",
185-
alert.query,
184+
"Alert Triggered: {}\n\nThreshold: ({} {})\nCurrent Value: {}\nEvaluation Window: {} | Frequency: {}\n\nQuery:\n{}",
185+
alert.id,
186186
alert.threshold_config.operator,
187187
alert.threshold_config.value,
188-
actual_value,
188+
format_number(actual_value),
189189
alert.get_eval_window(),
190-
alert.get_eval_frequency()
190+
alert.get_eval_frequency(),
191+
alert.query
191192
);
192193
ALERTS
193194
.update_state(alert.id, AlertState::Triggered, Some(message))
@@ -203,6 +204,23 @@ async fn update_alert_state(
203204
}
204205
}
205206

207+
/// Format a number for better readability
208+
fn format_number(value: f64) -> String {
209+
if value.fract() == 0.0 {
210+
// Integer value
211+
format!("{:.0}", value)
212+
} else if value.abs() < 1.0 {
213+
// Small decimal, show more precision
214+
format!("{:.4}", value)
215+
.trim_end_matches('0')
216+
.trim_end_matches('.')
217+
.to_string()
218+
} else {
219+
// Regular decimal, show 2 decimal places
220+
format!("{:.2}", value)
221+
}
222+
}
223+
206224
fn get_final_value(records: Vec<RecordBatch>) -> f64 {
207225
trace!("records-\n{records:?}");
208226

0 commit comments

Comments
 (0)