Add timeout option for telegram notifier#5127
Conversation
📝 WalkthroughWalkthroughAdded a configurable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/configuration.md`:
- Around line 1805-1809: Update the documentation for the timeout setting to
remove or fix the misleading note about group_interval: clarify that the
Telegram receiver applies timeout directly to the HTTP client (symbol: timeout)
and does not compare or enforce it against group_interval, so setting timeout
higher than group_interval does not get automatically capped; rephrase the
sentence to state this behavior explicitly and ensure the note references the
Telegram receiver behavior rather than implying an enforced relationship with
group_interval.
In `@notify/telegram/telegram_test.go`:
- Around line 227-236: The "success" test case in telegram_test.go has a tight
timing window (latency: 100ms vs timeout: 120ms) which can be flaky on CI;
update the test table entries (the cases with name "success" and "timeout" that
set the latency and timeout fields) to increase the headroom—e.g., raise the
"success" timeout to a safer value (200ms) or reduce the simulated latency—so
the success case has a comfortable margin while keeping the "timeout" case still
below the latency.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: eebc574c-57db-4a14-938a-6138ed179007
📒 Files selected for processing (4)
config/notifiers.godocs/configuration.mdnotify/telegram/telegram.gonotify/telegram/telegram_test.go
| name: "success", | ||
| latency: 100 * time.Millisecond, | ||
| timeout: 120 * time.Millisecond, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "timeout", | ||
| latency: 100 * time.Millisecond, | ||
| timeout: 80 * time.Millisecond, | ||
| wantErr: true, |
There was a problem hiding this comment.
Tight timing window can make this test flaky.
The success case only leaves ~20ms headroom (100ms latency vs 120ms timeout), which is fragile on busy CI runners.
Proposed stabilization tweak
{
name: "success",
- latency: 100 * time.Millisecond,
- timeout: 120 * time.Millisecond,
+ latency: 50 * time.Millisecond,
+ timeout: 1 * time.Second,
wantErr: false,
},
{
name: "timeout",
- latency: 100 * time.Millisecond,
- timeout: 80 * time.Millisecond,
+ latency: 250 * time.Millisecond,
+ timeout: 25 * time.Millisecond,
wantErr: true,
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| name: "success", | |
| latency: 100 * time.Millisecond, | |
| timeout: 120 * time.Millisecond, | |
| wantErr: false, | |
| }, | |
| { | |
| name: "timeout", | |
| latency: 100 * time.Millisecond, | |
| timeout: 80 * time.Millisecond, | |
| wantErr: true, | |
| name: "success", | |
| latency: 50 * time.Millisecond, | |
| timeout: 1 * time.Second, | |
| wantErr: false, | |
| }, | |
| { | |
| name: "timeout", | |
| latency: 250 * time.Millisecond, | |
| timeout: 25 * time.Millisecond, | |
| wantErr: true, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@notify/telegram/telegram_test.go` around lines 227 - 236, The "success" test
case in telegram_test.go has a tight timing window (latency: 100ms vs timeout:
120ms) which can be flaky on CI; update the test table entries (the cases with
name "success" and "timeout" that set the latency and timeout fields) to
increase the headroom—e.g., raise the "success" timeout to a safer value (200ms)
or reduce the simulated latency—so the success case has a comfortable margin
while keeping the "timeout" case still below the latency.
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
c627cec to
881b187
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
notify/telegram/telegram_test.go (1)
240-276: Test logic is sound; consider verifying error type for the timeout case.The test structure is clean: proper server lifecycle management, correct context setup for testing HTTP client timeout (not context deadline), and appropriate use of table-driven tests.
One optional enhancement: the timeout case could verify the error is specifically a timeout rather than any error, which would catch false positives if the notifier fails for unrelated reasons.
💡 Optional: Verify timeout error type
- _, err = notifier.Notify(ctx, alert) - require.Equal(t, tc.wantErr, err != nil) + _, err = notifier.Notify(ctx, alert) + if tc.wantErr { + require.Error(t, err) + var netErr net.Error + require.ErrorAs(t, err, &netErr) + require.True(t, netErr.Timeout(), "expected timeout error") + } else { + require.NoError(t, err) + }Would require adding
"net"to imports.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@notify/telegram/telegram_test.go` around lines 240 - 276, Update the timeout test case to assert the error is specifically a timeout: after calling notifier.Notify(ctx, alert) check that err is non-nil and then assert it satisfies net.Error && err.Timeout() (or use errors.Is for context.DeadlineExceeded if appropriate); modify the table-case that sets tc.timeout/wantErr to also expect a timeout and add the "net" import to the test file; locate this change around the test loop that constructs cfg, calls New(...) and notifier.Notify(...) in notify/telegram/telegram_test.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@notify/telegram/telegram_test.go`:
- Around line 240-276: Update the timeout test case to assert the error is
specifically a timeout: after calling notifier.Notify(ctx, alert) check that err
is non-nil and then assert it satisfies net.Error && err.Timeout() (or use
errors.Is for context.DeadlineExceeded if appropriate); modify the table-case
that sets tc.timeout/wantErr to also expect a timeout and add the "net" import
to the test file; locate this change around the test loop that constructs cfg,
calls New(...) and notifier.Notify(...) in notify/telegram/telegram_test.go.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f6083ffc-5fd0-4014-84a7-4ec6e119c915
📒 Files selected for processing (4)
config/notifiers.godocs/configuration.mdnotify/telegram/telegram.gonotify/telegram/telegram_test.go
✅ Files skipped from review due to trivial changes (1)
- docs/configuration.md
🚧 Files skipped from review as they are similar to previous changes (2)
- notify/telegram/telegram.go
- config/notifiers.go
This change introduces a
Timeoutoption for the Telegram notifier. When set, the HTTP client used by the notifier will time out if a request to the Telegram API takes longer than the configured duration.Pull Request Checklist
Please check all the applicable boxes.
benchstatto compare benchmarksWhich user-facing changes does this PR introduce?
Summary by CodeRabbit
New Features
Documentation
Tests