Add mute intervals feature to suppress notifications during date ranges#2024
Add mute intervals feature to suppress notifications during date ranges#2024
Conversation
Adds a new `mute_intervals` field parallel to `activity` in sink config. Users can specify date/time ranges (MM-DD HH:MM format, no year) during which all notifications to a sink are muted. Supports timezone config and year-boundary wrapping (e.g. Dec 24 to Jan 2). https://claude.ai/code/session_01FGiv1N3QcFMWAPT4e1pu93
Switches from MM-DD HH:MM (yearless) to YYYY-MM-DD HH:MM format. This simplifies the logic (no year-boundary wrapping needed) and gives users precise control over mute windows. https://claude.ai/code/session_01FGiv1N3QcFMWAPT4e1pu93
…ch interval mute_intervals is now a direct list of intervals instead of a nested object with timezone + intervals. Each interval carries its own timezone. https://claude.ai/code/session_01FGiv1N3QcFMWAPT4e1pu93
WalkthroughIntroduces a mute intervals feature for sinks, allowing notifications to be suppressed during specified date/time ranges. Adds configuration models, date/time validation with timezone support, a timing utility class to check mute status, and integrates mute checks into sink acceptance logic. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
|
✅ Docker image ready for
Use this tag to pull the image for testing. 📋 Copy commandsgcloud auth configure-docker us-central1-docker.pkg.dev
docker pull us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:6b5fee6
docker tag us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:6b5fee6 me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:6b5fee6
docker push me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:6b5fee6Patch Helm values in one line: helm upgrade --install robusta robusta/robusta \
--reuse-values \
--set runner.image=me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:6b5fee6 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/test_sink_timing.py (1)
85-87: Return an empty list from the test stub to keep SinkBase contract explicit.Using
passreturnsNone; returning[]keeps test setup safer if a future test forgets to assignsink.mute_date_intervalsmanually.Proposed test-stub adjustment
def _build_mute_intervals_from_params(self, params): # We'll construct mute_date_intervals explicitly below - pass + return []🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_sink_timing.py` around lines 85 - 87, The test stub _build_mute_intervals_from_params currently uses pass which returns None and can violate the SinkBase contract; change it to explicitly return an empty list ([]) so tests that rely on sink.mute_date_intervals get a safe default; update the function _build_mute_intervals_from_params to return [] rather than using pass to make the test setup explicit and robust.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/robusta/core/sinks/sink_base_params.py`:
- Around line 63-78: The function check_date_time_format currently uses
DATE_TIME_RE and manual numeric bounds checks that allow invalid calendar dates;
replace the manual parsing with a strict parse using datetime.strptime(value,
"%Y-%m-%d %H:%M") after the regex check (or remove the regex if you prefer) to
validate real calendar dates, catch and rethrow a ValueError with a clear
message if strptime fails, and return the original value on success; update
references to DATE_TIME_RE and the check_date_time_format function accordingly.
- Around line 81-94: MuteInterval currently validates formats for start_date and
end_date but does not check their relative order, so intervals where start_date
is after end_date silently disable muting; add a cross-field validator (e.g., a
`@root_validator` on the MuteInterval class) that parses start_date and end_date
(using the same check_date_time_format logic or datetime parsing with the
provided timezone) and raises ValueError if start >= end, referencing the
existing fields start_date, end_date and the MuteInterval class so the model
enforces correct interval ordering at instantiation.
---
Nitpick comments:
In `@tests/test_sink_timing.py`:
- Around line 85-87: The test stub _build_mute_intervals_from_params currently
uses pass which returns None and can violate the SinkBase contract; change it to
explicitly return an empty list ([]) so tests that rely on
sink.mute_date_intervals get a safe default; update the function
_build_mute_intervals_from_params to return [] rather than using pass to make
the test setup explicit and robust.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 550bedb7-c6c1-4b0f-a98b-d18e2f2909a5
📒 Files selected for processing (6)
docs/notification-routing/routing-by-time.rsthelm/robusta/values.yamlsrc/robusta/core/sinks/sink_base.pysrc/robusta/core/sinks/sink_base_params.pysrc/robusta/core/sinks/timing.pytests/test_sink_timing.py
Summary
This PR adds a new mute intervals feature that allows users to suppress all notifications from a sink during specified date/time ranges. This is useful for silencing alerts during maintenance windows, holidays, or other planned periods.
Key Changes
New
MuteDateIntervalclass (timing.py): Implements date/time range checking with timezone support. Parses date strings inYYYY-MM-DD HH:MMformat and determines if the current time falls within a muted period.New
MuteIntervalmodel (sink_base_params.py): Pydantic model for mute interval configuration with validation for date/time format and timezone names. Includes a regex validator (check_date_time_format) to enforce the expected format.Updated
SinkBaseParams(sink_base_params.py): Added optionalmute_intervalsfield to allow configuration of mute periods per sink.Enhanced
SinkBase(sink_base.py):mute_date_intervalsattribute initialized from sink parameters_build_mute_intervals_from_params()method to constructMuteDateIntervalobjects from configurationaccepts()method to returnFalseif any mute interval is currently active, preventing notifications from being processedComprehensive test coverage (
test_sink_timing.py):TestMuteDateIntervalclass with tests for timezone validation, various date range scenarios (past, future, spanning boundaries), and timezone conversionsTestSinkBasewith tests verifying that muted intervals block notifications while non-active intervals allow normal processingDocumentation (
values.yaml): Added example configuration showing how to use mute intervals with multiple sinks and timezones.Implementation Details
(year, month, day, hour, minute)https://claude.ai/code/session_01FGiv1N3QcFMWAPT4e1pu93