-
-
Notifications
You must be signed in to change notification settings - Fork 149
Updates #1412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Updates #1412
Conversation
WalkthroughAdds UTC timestamp validation to reject past times in update_notification_state, expands the InvalidStateChange message to mention Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant H as AlertsHandler
participant DB as Storage
participant S as Scheduler
rect rgb(250,250,255)
C->>H: PUT /alerts/{id} with new state (maybe UTC ts)
H->>H: Parse new state, compute is_disabled
H->>DB: Update alert record
alt is_disabled == true
note right of H: Skip task deletion/restart
H-->>C: 200 OK
else is_disabled == false
H->>S: Delete existing scheduled task (if any)
H->>S: Restart/reschedule task
H-->>C: 200 OK
end
end
sequenceDiagram
autonumber
participant X as Caller
participant H as update_notification_state
X->>H: Request with state / optional UTC timestamp
alt UTC timestamp provided
H->>H: Check timestamp >= now (UTC)
alt timestamp < now
H-->>X: Error InvalidStateChange ("Provided time is < Now")
else timestamp >= now
H-->>X: Proceed
end
else No UTC timestamp
note right of H: Accept `notify` | human-time | UTC | `indefinite`
H-->>X: Proceed
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant H as AlertsHandler
participant DB as Storage
participant S as Scheduler
rect rgb(250,250,255)
C->>H: PUT /alerts/{id} with new state (maybe UTC ts)
H->>H: Parse new state, compute is_disabled
H->>DB: Update alert record
alt is_disabled == true
note right of H: Skip task deletion/restart
H-->>C: 200 OK
else is_disabled == false
H->>S: Delete existing scheduled task (if any)
H->>S: Restart/reschedule task
H-->>C: 200 OK
end
end
sequenceDiagram
autonumber
participant X as Caller
participant H as update_notification_state
X->>H: Request with state / optional UTC timestamp
alt UTC timestamp provided
H->>H: Check timestamp >= now (UTC)
alt timestamp < now
H-->>X: Error InvalidStateChange ("Provided time is < Now")
else timestamp >= now
H-->>X: Proceed
end
else No UTC timestamp
note right of H: Accept `notify` | human-time | UTC | `indefinite`
H-->>X: Proceed
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/handlers/http/alerts.rs (1)
443-451
: Mirror POST validations to prevent divide-by-zero and invalid schedules in modify_alert.Unlike POST, PUT lacks checks for eval_freq == 0, notif_freq == 0, and notif_freq > eval_freq. This can panic on division by zero and allow invalid schedules.
Apply this diff before computing
times
:let eval_freq = new_config.get_eval_frequency(); let notif_freq = new_config.notification_config.interval; + // Mirror POST validations to prevent invalid schedules + if eval_freq == 0 { + return Err(AlertError::ValidationFailure("Eval frequency cannot be 0".into())); + } + if notif_freq == 0 { + return Err(AlertError::ValidationFailure("Notification interval cannot be 0".into())); + } + if notif_freq > eval_freq { + return Err(AlertError::ValidationFailure( + "Notification interval cannot exceed evaluation frequency".into(), + )); + } let times = if (eval_freq / notif_freq) == 0 { 1 } else { (eval_freq / notif_freq) as usize };
🧹 Nitpick comments (1)
src/handlers/http/alerts.rs (1)
314-316
: Clarify the invalid-input message for snooze state.Minor copy improvement for readability and examples.
Apply this tweak (already included in the larger refactor above):
- "Invalid notification state change request. Expected `notify`, `indefinite` or human-time or UTC datetime. Got `{}`", - &new_notification_state.state + "Invalid notification state change request. Expected one of: `notify`, `indefinite`, human-time duration (e.g., \"15m\"), or UTC RFC3339 datetime. Got `{}`", + state_str
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/handlers/http/alerts.rs
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: coverage
- GitHub Check: Quest Smoke and Load Tests for Distributed deployments
- GitHub Check: Quest Smoke and Load Tests for Standalone deployments
- GitHub Check: Build Default aarch64-apple-darwin
- GitHub Check: Build Default x86_64-pc-windows-msvc
- GitHub Check: Build Kafka aarch64-apple-darwin
- GitHub Check: Build Default x86_64-apple-darwin
- GitHub Check: Build Default x86_64-unknown-linux-gnu
- GitHub Check: Build Default aarch64-unknown-linux-gnu
- GitHub Check: Build Kafka x86_64-unknown-linux-gnu
🔇 Additional comments (2)
src/handlers/http/alerts.rs (2)
493-495
: LGTM: restart is correctly gated by Disabled state.Only starting the task when not Disabled is correct and aligns with the PR objective.
295-320
: Apply stronger snooze-time validation in alerts handlerChrono v0.4.39 (your repo’s version) supports
chrono::Duration::from_std
, so this refactor is safe to apply.File:
src/handlers/http/alerts.rs
(lines 295–320)- let new_notification_state = match new_notification_state.state.as_str() { + let state_str = new_notification_state.state.trim(); + let now = Utc::now(); + let new_notification_state = match state_str { "notify" => NotificationState::Notify, - "indefinite" => NotificationState::Mute("indefinite".into()), + "indefinite" => NotificationState::Mute("indefinite".into()), _ => { // either human time or datetime in UTC - let till_time = if let Ok(duration) = - humantime::parse_duration(&new_notification_state.state) - { - (Utc::now() + duration).to_rfc3339() - } else if let Ok(timestamp) = DateTime::<Utc>::from_str(&new_notification_state.state) { + let till_time = if let Ok(std_dur) = humantime::parse_duration(state_str) { + if std_dur.is_zero() { + return Err(AlertError::InvalidStateChange( + "Invalid notification state change request. Duration must be > 0.".into(), + )); + } + let chrono_dur = chrono::Duration::from_std(std_dur).map_err(|_| { + AlertError::InvalidStateChange( + "Invalid notification state change request. Duration is out of range." + .into(), + ) + })?; + (now + chrono_dur).to_rfc3339() + } else if let Ok(timestamp) = DateTime::<Utc>::from_str(state_str) { // must be datetime UTC then - if timestamp < Utc::now() { + if timestamp <= now { return Err(AlertError::InvalidStateChange( - "Invalid notification state change request. Provided time is < Now".into(), + "Invalid notification state change request. Provided time must be in the future." + .into(), )); } timestamp.to_rfc3339() } else { return Err(AlertError::InvalidStateChange(format!( - "Invalid notification state change request. Expected `notify`, `indefinite` or human-time or UTC datetime. Got `{}`", - &new_notification_state.state + "Invalid notification state change request. Expected one of: `notify`, `indefinite`, human-time duration (e.g., \"15m\"), or UTC RFC3339 datetime. Got `{}`", + state_str ))); }; NotificationState::Mute(till_time) } };
3acc0da
to
cf439d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use proper PR header and commit message
Fixes #XXXX.
Description
This PR has:
Summary by CodeRabbit
Bug Fixes
Improvements