From 3d396670c5c61878224d304063a51dee5256259b Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Fri, 18 Aug 2023 13:40:36 +0300 Subject: [PATCH] Prevent conversion of escalation start/end times to UTC (#2826) # What this PR does Adds a boolean `convertToUTC` to the `TimeRange` component. For this use case on escalation chains since the user inputted fields are strings they will not be further converted to UTC and instead left as it is, which previously resulted in setting a wrong start/end combination. ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/2781 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- CHANGELOG.md | 2 ++ engine/apps/alerts/models/escalation_policy.py | 2 +- .../src/components/TimeRange/TimeRange.tsx | 14 ++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb56c729..eb27a499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Improve Grafana Alerting integration by @Ferril @teodosii ([#2742](https://github.com/grafana/oncall/pull/2742)) +- Fixed UTC conversion for escalation chain step of timerange + ([#2781](https://github.com/grafana/oncall/issues/2781)) ## v1.3.24 (2023-08-17) diff --git a/engine/apps/alerts/models/escalation_policy.py b/engine/apps/alerts/models/escalation_policy.py index a55f1d1b..1ae8da43 100644 --- a/engine/apps/alerts/models/escalation_policy.py +++ b/engine/apps/alerts/models/escalation_policy.py @@ -129,7 +129,7 @@ class EscalationPolicy(OrderedModel): STEP_TRIGGER_CUSTOM_WEBHOOK: ("Trigger webhook {{custom_webhook}}", "Trigger webhook"), STEP_NOTIFY_USERS_QUEUE: ("Round robin notification for {{users}}", "Notify users one by one (round-robin)"), STEP_NOTIFY_IF_TIME: ( - "Continue escalation if current time is in {{timerange}}", + "Continue escalation if current UTC time is in {{timerange}}", "Continue escalation if current time is in range", ), STEP_NOTIFY_IF_NUM_ALERTS_IN_TIME_WINDOW: ( diff --git a/grafana-plugin/src/components/TimeRange/TimeRange.tsx b/grafana-plugin/src/components/TimeRange/TimeRange.tsx index 66bdb00b..b48e7435 100644 --- a/grafana-plugin/src/components/TimeRange/TimeRange.tsx +++ b/grafana-plugin/src/components/TimeRange/TimeRange.tsx @@ -17,8 +17,8 @@ interface TimeRangeProps { } function getMoments(from: string, to: string) { - let fromMoment; - let toMoment; + let fromMoment: moment.Moment; + let toMoment: moment.Moment; if (!from || !to) { fromMoment = moment().startOf('hour'); @@ -29,18 +29,18 @@ function getMoments(from: string, to: string) { } } else { const [fh, fm] = from.split(':').map(Number); - fromMoment = moment().utc().hour(fh).minute(fm).second(0).local(); + fromMoment = moment().hour(fh).minute(fm).second(0).local(); const [th, tm] = to.split(':').map(Number); - toMoment = moment().utc().hour(th).minute(tm).second(0).local(); + toMoment = moment().hour(th).minute(tm).second(0).local(); } return [fromMoment, toMoment]; } function getRangeStrings(from: moment.Moment, to: moment.Moment) { - const fromString = from.clone().utc().format('HH:mm:00'); - const toString = to.clone().utc().format('HH:mm:00'); + const fromString = from.clone().format('HH:mm:00'); + const toString = to.clone().format('HH:mm:00'); return [fromString, toString]; } @@ -48,9 +48,7 @@ function getRangeStrings(from: moment.Moment, to: moment.Moment) { const TimeRange = (props: TimeRangeProps) => { const { className, from: f, to: t, onChange, disabled } = props; - // @ts-ignore const [from, setFrom] = useState(getMoments(f, t)[0]); - // @ts-ignore const [to, setTo] = useState(getMoments(f, t)[1]); useEffect(() => {