Skip to content

Commit 937861c

Browse files
committed
Flatten mute_intervals: remove MuteParams wrapper, put timezone on each 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
1 parent 5b6af54 commit 937861c

4 files changed

Lines changed: 13 additions & 24 deletions

File tree

helm/robusta/values.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ playbookRepos: {}
1919
# slack_channel: my-channel
2020
# api_key: xoxb-your-key
2121
# mute_intervals:
22+
# - start_date: "2025-12-24 00:00"
23+
# end_date: "2025-12-26 23:59"
2224
# timezone: UTC
23-
# intervals:
24-
# - start_date: "2025-12-24 00:00"
25-
# end_date: "2025-12-26 23:59"
26-
# - start_date: "2026-01-01 00:00"
27-
# end_date: "2026-01-01 23:59"
25+
# - start_date: "2026-01-01 00:00"
26+
# end_date: "2026-01-01 23:59"
27+
# timezone: US/Eastern
2828
sinksConfig: []
2929

3030
# global parameters

src/robusta/core/sinks/sink_base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from robusta.core.model.k8s_operation_type import K8sOperationType
1010
from robusta.core.reporting.base import Finding
11-
from robusta.core.sinks.sink_base_params import ActivityInterval, ActivityParams, MuteParams, SinkBaseParams
11+
from robusta.core.sinks.sink_base_params import ActivityInterval, ActivityParams, MuteInterval, SinkBaseParams
1212
from robusta.core.sinks.timing import MuteDateInterval, TimeSlice, TimeSliceAlways
1313

1414

@@ -152,13 +152,12 @@ def _build_time_slices_from_params(self, params: ActivityParams):
152152
def _interval_to_time_slice(self, timezone: str, interval: ActivityInterval):
153153
return TimeSlice(interval.days, [(time.start, time.end) for time in interval.hours], timezone)
154154

155-
def _build_mute_intervals_from_params(self, params: MuteParams):
156-
if params is None:
155+
def _build_mute_intervals_from_params(self, params: Optional[List[MuteInterval]]):
156+
if not params:
157157
return []
158-
timezone = params.timezone
159158
return [
160-
MuteDateInterval(interval.start_date, interval.end_date, timezone)
161-
for interval in params.intervals
159+
MuteDateInterval(interval.start_date, interval.end_date, interval.timezone)
160+
for interval in params
162161
]
163162

164163
def is_global_config_changed(self) -> bool:

src/robusta/core/sinks/sink_base_params.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,17 @@ def check_date_time_format(value: str) -> str:
8181
class MuteInterval(BaseModel):
8282
start_date: str # YYYY-MM-DD HH:MM
8383
end_date: str # YYYY-MM-DD HH:MM
84+
timezone: str = "UTC"
8485

8586
_validator_start = validator("start_date", allow_reuse=True)(check_date_time_format)
8687
_validator_end = validator("end_date", allow_reuse=True)(check_date_time_format)
8788

88-
89-
class MuteParams(BaseModel):
90-
timezone: str = "UTC"
91-
intervals: List[MuteInterval]
92-
9389
@validator("timezone")
9490
def check_timezone(cls, timezone: str):
9591
if timezone not in pytz.all_timezones:
9692
raise ValueError(f"unknown timezone {timezone}")
9793
return timezone
9894

99-
@validator("intervals")
100-
def check_intervals(cls, intervals: List[MuteInterval]):
101-
if not intervals:
102-
raise ValueError("at least one interval has to be specified for mute_intervals")
103-
return intervals
104-
10595

10696
class RegularNotificationModeParams(BaseModel):
10797
# This is mandatory because using the regular mode without setting it
@@ -154,7 +144,7 @@ class SinkBaseParams(ABC, BaseModel):
154144
match: dict = {}
155145
scope: Optional[ScopeParams]
156146
activity: Optional[ActivityParams]
157-
mute_intervals: Optional[MuteParams]
147+
mute_intervals: Optional[List[MuteInterval]]
158148
grouping: Optional[GroupingParams]
159149
stop: bool = False # Stop processing if this sink has been matched
160150

tests/test_sink_timing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_invalid_time(self, time):
4242
class TestMuteDateInterval:
4343
def test_unknown_timezone(self):
4444
with pytest.raises(ValueError):
45-
MuteDateInterval("01-01 00:00", "01-02 00:00", "Mars/Cydonia")
45+
MuteDateInterval("2012-01-01 00:00", "2012-01-02 00:00", "Mars/Cydonia")
4646

4747
@pytest.mark.parametrize(
4848
"start_date,end_date,timezone,expected_muted",

0 commit comments

Comments
 (0)