Skip to content

fix(provider-endpoints): allow disabling scheduled probes#1335

Open
i-square wants to merge 1 commit into
ding113:devfrom
i-square:localfix/0.8.10/passive-endpoint-probe
Open

fix(provider-endpoints): allow disabling scheduled probes#1335
i-square wants to merge 1 commit into
ding113:devfrom
i-square:localfix/0.8.10/passive-endpoint-probe

Conversation

@i-square

@i-square i-square commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Adds a global switch (ENDPOINT_PROBE_SCHEDULER_ENABLED) to disable the background endpoint probe scheduler, and makes the previously-hardcoded 10s timeout-retry interval configurable (ENDPOINT_PROBE_TIMEOUT_RETRY_INTERVAL_MS). Both default to current behavior, so this change is fully backward-compatible.

Problem

The endpoint probe scheduler currently starts unconditionally (from src/instrumentation.ts) with no global off switch. In deployments with many endpoints (e.g. 100+ single-vendor endpoints), the scheduler keeps probing and writing to the probe-history table even with zero business traffic, competing for DB connections and contributing to the Something went wrong! / CONNECT_TIMEOUT postgres:5432 errors reported under load.

Separately, the 10s timeout-retry interval was a hardcoded constant, so endpoints in the timeout-retry category could not be tuned via environment variables.

Related Issues:

Solution

  • The guard lives inside startEndpointProbeScheduler(): when ENDPOINT_PROBE_SCHEDULER_ENABLED=false, it logs "Disabled by configuration" and returns early — no timer, no leader lock, no endpoint query. Existing call sites in src/instrumentation.ts are unchanged.
  • Added strict env parsers (parseBooleanWithDefault, parsePositiveIntWithDefault) that warn and fall back to the default on invalid input, rather than silently coercing.
  • getEndpointProbeSchedulerStatus() now exposes an enabled field so the active mode is observable.
  • Manual probe APIs and request-driven circuit-breaker behavior are untouched and remain available when the scheduler is off — real traffic still drives circuit-breaker failover, matching [Feature Request] 支持被动/按需端点健康检查,避免定时探测影响业务请求 #1326's expected behavior.

Changes

Core Changes

  • src/lib/provider-endpoints/probe-scheduler.ts: new SCHEDULER_ENABLED switch with early-return guard; TIMEOUT_OVERRIDE_INTERVAL_MS now read from ENDPOINT_PROBE_TIMEOUT_RETRY_INTERVAL_MS; validated env parsers with warn-on-invalid; status API gains enabled.

Supporting Changes

  • .env.example: documented both new variables and refreshed the surrounding comments.
  • tests/unit/lib/provider-endpoints/probe-scheduler.test.ts (+197): env-parsing defaults / truthy / falsy / invalid-warning cases, disabled-scheduler no-op verification, custom timeout-interval probing behavior.
  • tests/unit/lib/provider-endpoints/probe.test.ts: regression ensuring manual probe still records to history when the scheduler is disabled.

Breaking Changes

None. Both new variables default to the previous behavior (true and 10000ms). The scheduler status endpoint gains an additive enabled field.

Testing

Automated Tests

  • Unit tests added — env config parsing, disabled-scheduler no-op, custom timeout interval
  • Regression: manual probe still records when scheduler is disabled

Manual Testing

  1. Set ENDPOINT_PROBE_SCHEDULER_ENABLED=false and start the app.
  2. Confirm the startup log shows [EndpointProbeScheduler] Disabled by configuration.
  3. Confirm no source=scheduled probe records appear in the history table while idle.
  4. Trigger a manual probe via the management API — confirm it still records.
  5. Confirm normal proxy traffic still drives circuit-breaker failover.

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally
  • Documentation updated (.env.example)

Description enhanced by Claude AI

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9df069e7-4ccf-4fdf-927e-92d5b362b51b

📥 Commits

Reviewing files that changed from the base of the PR and between 6fcb827 and 1550a41.

📒 Files selected for processing (4)
  • .env.example
  • src/lib/provider-endpoints/probe-scheduler.ts
  • tests/unit/lib/provider-endpoints/probe-scheduler.test.ts
  • tests/unit/lib/provider-endpoints/probe.test.ts

📝 Walkthrough

Walkthrough

新增端点探测调度器启用开关和超时重试间隔配置,加入环境变量校验与默认值告警;禁用时跳过后台调度,但手动探测仍可执行并记录结果。测试覆盖相关配置和运行行为。

Changes

端点探测调度器配置

Layer / File(s) Summary
配置说明与运行时解析
.env.example, src/lib/provider-endpoints/probe-scheduler.ts
新增调度器开关和超时重试间隔配置,加入布尔值、正整数校验及默认值回退,并在状态中返回 enabled
调度器启动开关
src/lib/provider-endpoints/probe-scheduler.ts
调度器禁用时记录配置日志并跳过定时器、锁续约和端点探测流程。
调度行为与手动探测验证
tests/unit/lib/provider-endpoints/probe-scheduler.test.ts, tests/unit/lib/provider-endpoints/probe.test.ts
新增配置解析、非法值告警、禁用行为、超时重试阈值及调度器关闭后手动探测入库的测试。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了本次新增的“可禁用定时探测”这一核心改动。
Description check ✅ Passed 描述虽很简短,但与修复 #1326 及本次改动直接相关。
Linked Issues check ✅ Passed 实现了关闭调度器的开关,默认保持启用,并保留手动探测在关闭调度器时可用。
Out of Scope Changes check ✅ Passed 变更集中在调度器开关、配置和测试,没有明显超出目标范围的内容。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch localfix/0.8.10/passive-endpoint-probe

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working area:provider labels Jul 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces configuration options to enable or disable the background endpoint probe scheduler via the ENDPOINT_PROBE_SCHEDULER_ENABLED environment variable, and to customize the timeout retry interval using ENDPOINT_PROBE_TIMEOUT_RETRY_INTERVAL_MS. It implements robust parsing helpers with fallback values and warning logs, integrates these settings into the scheduler's lifecycle, and updates the scheduler status payload. Additionally, comprehensive unit tests have been added to verify the environment configuration parsing, the behavior of a disabled scheduler, and that manual probing remains functional when the scheduler is disabled. There are no review comments, and the changes are well-implemented.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions github-actions Bot added the size/M Medium PR (< 500 lines) label Jul 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

No significant issues identified in this PR. The implementation adds two well-validated environment variables (ENDPOINT_PROBE_SCHEDULER_ENABLED, ENDPOINT_PROBE_TIMEOUT_RETRY_INTERVAL_MS) with robust parsing, clear warning logging on invalid input, backward-compatible defaults, and thorough test coverage for the new code paths. The env-var parsing strategy (strict allowlist with fallback + warn) is actually more defensive than the existing centralized booleanTransform, and the .env.example documentation accurately reflects the new behavior.

PR Size: M

  • Lines changed: 293 (285 additions, 8 deletions)
  • Files changed: 4

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Claude AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider bug Something isn't working size/M Medium PR (< 500 lines)

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant