Skip to content

Commit dc796e5

Browse files
remove default created
1 parent e080b0f commit dc796e5

File tree

3 files changed

+3
-64
lines changed

3 files changed

+3
-64
lines changed

src/alerts/alert_structs.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use std::{collections::HashMap, time::Duration};
2020

2121
use chrono::{DateTime, Utc};
22-
use serde::{Deserialize, Deserializer, Serialize};
22+
use serde::{Deserialize, Serialize};
2323
use serde_json::Value;
2424
use tokio::sync::{RwLock, mpsc};
2525
use ulid::Ulid;
@@ -39,52 +39,6 @@ use crate::{
3939
storage::object_storage::{alert_json_path, alert_state_json_path},
4040
};
4141

42-
/// Custom deserializer for DateTime<Utc> that handles legacy empty strings
43-
///
44-
/// This is a compatibility layer for migrating old alerts that stored empty strings
45-
/// instead of valid timestamps. In production, this should log warnings to help
46-
/// identify data quality issues.
47-
///
48-
/// # Migration Path
49-
/// - Empty strings → Default to current time with a warning
50-
/// - Missing fields → Default to current time
51-
/// - Valid timestamps → Parse normally
52-
pub fn deserialize_datetime_with_empty_string_fallback<'de, D>(
53-
deserializer: D,
54-
) -> Result<DateTime<Utc>, D::Error>
55-
where
56-
D: Deserializer<'de>,
57-
{
58-
#[derive(Deserialize)]
59-
#[serde(untagged)]
60-
enum DateTimeOrString {
61-
DateTime(DateTime<Utc>),
62-
String(String),
63-
}
64-
65-
match DateTimeOrString::deserialize(deserializer)? {
66-
DateTimeOrString::DateTime(dt) => Ok(dt),
67-
DateTimeOrString::String(s) => {
68-
if s.is_empty() {
69-
// Log warning about data quality issue
70-
tracing::warn!(
71-
"Alert has empty 'created' field - this indicates a data quality issue. \
72-
Defaulting to current timestamp. Please investigate and fix the data source."
73-
);
74-
Ok(Utc::now())
75-
} else {
76-
s.parse::<DateTime<Utc>>().map_err(serde::de::Error::custom)
77-
}
78-
}
79-
}
80-
}
81-
82-
/// Default function for created timestamp - returns current time
83-
/// This handles the case where created field is missing in deserialization
84-
pub fn default_created_time() -> DateTime<Utc> {
85-
Utc::now()
86-
}
87-
8842
/// Helper struct for basic alert fields during migration
8943
pub struct BasicAlertFields {
9044
pub id: Ulid,
@@ -394,10 +348,6 @@ pub struct AlertConfig {
394348
pub state: AlertState,
395349
pub notification_state: NotificationState,
396350
pub notification_config: NotificationConfig,
397-
#[serde(
398-
default = "default_created_time",
399-
deserialize_with = "deserialize_datetime_with_empty_string_fallback"
400-
)]
401351
pub created: DateTime<Utc>,
402352
pub tags: Option<Vec<String>>,
403353
pub last_triggered_at: Option<DateTime<Utc>>,
@@ -426,10 +376,6 @@ pub struct AlertConfigResponse {
426376
pub state: AlertState,
427377
pub notification_state: NotificationState,
428378
pub notification_config: NotificationConfig,
429-
#[serde(
430-
default = "default_created_time",
431-
deserialize_with = "deserialize_datetime_with_empty_string_fallback"
432-
)]
433379
pub created: DateTime<Utc>,
434380
pub tags: Option<Vec<String>>,
435381
pub last_triggered_at: Option<DateTime<Utc>>,

src/alerts/alert_types.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ use crate::{
2929
AlertConfig, AlertError, AlertState, AlertType, AlertVersion, EvalConfig, Severity,
3030
ThresholdConfig,
3131
alert_enums::NotificationState,
32-
alert_structs::{
33-
AlertStateEntry, GroupResult, default_created_time,
34-
deserialize_datetime_with_empty_string_fallback,
35-
},
32+
alert_structs::{AlertStateEntry, GroupResult},
3633
alert_traits::{AlertTrait, MessageCreation},
3734
alerts_utils::{evaluate_condition, execute_alert_query, extract_time_range},
3835
get_number_of_agg_exprs,
@@ -65,10 +62,6 @@ pub struct ThresholdAlert {
6562
pub state: AlertState,
6663
pub notification_state: NotificationState,
6764
pub notification_config: NotificationConfig,
68-
#[serde(
69-
default = "default_created_time",
70-
deserialize_with = "deserialize_datetime_with_empty_string_fallback"
71-
)]
7265
pub created: DateTime<Utc>,
7366
pub tags: Option<Vec<String>>,
7467
pub datasets: Vec<String>,

src/alerts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub use crate::alerts::alert_enums::{
5151
pub use crate::alerts::alert_structs::{
5252
AlertConfig, AlertInfo, AlertRequest, AlertStateEntry, Alerts, AlertsInfo, AlertsInfoByState,
5353
AlertsSummary, BasicAlertFields, Context, DeploymentInfo, RollingWindow, StateTransition,
54-
ThresholdConfig, default_created_time, deserialize_datetime_with_empty_string_fallback,
54+
ThresholdConfig,
5555
};
5656
use crate::alerts::alert_traits::{AlertManagerTrait, AlertTrait};
5757
use crate::alerts::alert_types::ThresholdAlert;

0 commit comments

Comments
 (0)