Skip to content

fix: enforce scrape timeout for all runs#2299

Open
adityathebe wants to merge 2 commits into
mainfrom
fix/timeout
Open

fix: enforce scrape timeout for all runs#2299
adityathebe wants to merge 2 commits into
mainfrom
fix/timeout

Conversation

@adityathebe

@adityathebe adityathebe commented Jul 7, 2026

Copy link
Copy Markdown
Member

CloudTrail scrapes could run indefinitely when triggered by the scheduled job path.

The manual run path had its own hardcoded timeout, but scheduled runs did not consistently apply a scrape deadline. Add a top-level ScrapeConfig timeout and enforce it centrally when scrapers run, falling back to the scraper.timeout property and then 4h.

Manual, scheduled, and CLI runs now share the same timeout behavior.

Summary by CodeRabbit

  • New Features

    • Added a configurable scraper timeout, including support for duration values like 30m and 1d.
    • Added OpenSearch connection support in configuration schemas.
  • Bug Fixes

    • Scraping now uses the configured timeout consistently, with a safe default when none is set.
    • Invalid timeout values now return a clear error instead of being accepted silently.
  • Documentation

    • Updated schema descriptions to better explain repository matching options and OpenSearch settings.

Scheduled scrapes could run without a deadline while manual runs used a separate hardcoded timeout.

Add a top-level ScrapeConfig timeout and apply it inside the scraper run path, falling back to scraper.timeout and then 4h so manual, scheduled, and CLI runs share the same behavior.
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Benchstat

Base: 6ab384739b1c80dc9ab37b7804712e096fe2f7a0
Head: 2bffd6a339a434e53957915b56030492e1ae1bae

📊 2 minor regression(s) (all within 5% threshold)

Benchmark Base Head Change p-value
BenchSaveResultsUpdateUnchanged/N=1000-4 2.594 2.645 +1.97% 0.002
RunTemplateBool/largeEnv-4 10.16Ki 10.16Ki +0.01% 0.015
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/config-db/bench
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
                                         │ bench-base.txt │           bench-head.txt           │
                                         │     sec/op     │    sec/op     vs base              │
LocationFilter/smallEnv-4                    18.64µ ± 17%   18.17µ ± 21%       ~ (p=0.093 n=6)
LocationFilter/largeEnv-4                    47.10µ ± 11%   45.94µ ± 14%       ~ (p=0.394 n=6)
RunTemplateBool/smallEnv-4                   10.82µ ±  3%   10.69µ ±  2%       ~ (p=0.240 n=6)
RunTemplateBool/largeEnv-4                   20.02µ ±  1%   19.94µ ±  1%       ~ (p=0.180 n=6)
BenchSaveResultsSeed/N=1000-4                 3.347 ± 16%    3.422 ± 13%       ~ (p=0.937 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4      2.594 ±  2%    2.645 ±  1%  +1.97% (p=0.002 n=6)
BenchSaveResultsUpdateChanged/N=1000-4        6.050 ±  2%    6.147 ±  1%       ~ (p=0.310 n=6)
geomean                                      3.727m         3.722m        -0.14%

                                         │ bench-base.txt │            bench-head.txt            │
                                         │      B/op      │     B/op      vs base                │
LocationFilter/smallEnv-4                    14.97Ki ± 0%   14.97Ki ± 0%       ~ (p=1.000 n=6) ¹
LocationFilter/largeEnv-4                    20.38Ki ± 0%   20.38Ki ± 0%  +0.00% (p=0.015 n=6)
RunTemplateBool/smallEnv-4                   8.359Ki ± 0%   8.359Ki ± 0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/largeEnv-4                   10.16Ki ± 0%   10.16Ki ± 0%  +0.01% (p=0.015 n=6)
BenchSaveResultsSeed/N=1000-4                1.277Gi ± 0%   1.277Gi ± 0%       ~ (p=1.000 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     32.20Mi ± 0%   32.21Mi ± 0%       ~ (p=1.000 n=6)
BenchSaveResultsUpdateChanged/N=1000-4       797.2Mi ± 1%   796.9Mi ± 1%       ~ (p=0.818 n=6)
geomean                                      990.3Ki        990.3Ki       -0.00%
¹ all samples are equal

                                         │ bench-base.txt │            bench-head.txt            │
                                         │   allocs/op    │  allocs/op    vs base                │
LocationFilter/smallEnv-4                     278.0 ±  0%    278.0 ±  0%       ~ (p=1.000 n=6) ¹
LocationFilter/largeEnv-4                     522.0 ±  0%    522.0 ±  0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/smallEnv-4                    216.0 ±  0%    216.0 ±  0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/largeEnv-4                    297.0 ±  0%    297.0 ±  0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsSeed/N=1000-4                442.7k ±  0%   442.7k ±  0%       ~ (p=0.974 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     396.9k ±  0%   396.9k ±  0%       ~ (p=1.000 n=6)
BenchSaveResultsUpdateChanged/N=1000-4       984.1k ± 13%   984.1k ± 13%       ~ (p=0.732 n=6)
geomean                                      7.703k         7.703k        +0.00%
¹ all samples are equal

                                         │ bench-base.txt │           bench-head.txt           │
                                         │      MB/s      │    MB/s     vs base                │
BenchSaveResultsSeed/N=1000-4                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateUnchanged/N=1000-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateChanged/N=1000-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                 ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR removes the per-call context timeout helper (ScrapeContext.WithTimeout) and instead adds a ScraperSpec.TimeoutDuration method that parses a configurable timeout string, applied centrally in scrapers/run.go. Call sites in cmd/run.go and scrapers/run_now.go drop their local timeout logic. JSON/CRD schemas add OpenSearch connection definitions, a scraper timeout field, and an updated repo description.

Changes

Scraper Timeout Refactor

Layer / File(s) Summary
ScraperSpec.TimeoutDuration contract and tests
api/v1/types.go, api/v1/timeout_test.go
Adds TimeoutDuration(defaultTimeout) (time.Duration, error) parsing ScraperSpec.Timeout via duration.ParseDuration with error wrapping, and a test covering default, "30m", "1d", and invalid inputs.
Central timeout application in Run
scrapers/run.go
Adds defaultScraperTimeout (4h) constant and applies the computed timeout to ctx.Context via WithTimeout, returning early on parse errors.
Removal of ScrapeContext.WithTimeout and call-site cleanup
api/context.go, cmd/run.go, scrapers/run_now.go
Deletes the ScrapeContext.WithTimeout method and unused imports, and removes now-redundant per-call timeout/cancel logic from cmd/run.go and runNowSync/runNowAsync.

OpenSearch Connection and Schema Description Updates

Layer / File(s) Summary
OpenSearch connection and timeout/repo schema updates
config/schemas/config_exec.schema.json, config/schemas/config_playwright.schema.json, config/schemas/scrape_config.schema.json, config/schemas/config_github.schema.json, chart/crds/configs.flanksource.com_scrapeconfigs.yaml
Adds OpensearchConnection definitions and ExecConnections.opensearch references, adds a ScraperSpec.timeout string field, and updates the GitHubRepository.repo description text.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: enforcing scrape timeouts consistently across all run paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/timeout
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/timeout

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/v1/types.go`:
- Around line 118-129: The ScraperSpec.TimeoutDuration helper currently accepts
parsed durations that are zero or negative, which later flow into
ctx.Context.WithTimeout in scrapers/run.go and can cancel scraping immediately.
Update TimeoutDuration to validate the parsed timeout is strictly greater than
zero before returning it, and return an error for "0s" or any negative value.
Keep the existing parsing/error handling in ScraperSpec.TimeoutDuration and use
the timeout value check right after duration.ParseDuration.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1954b355-4fa1-4fda-b4b0-8d73e20fda41

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab3847 and 2bffd6a.

📒 Files selected for processing (11)
  • api/context.go
  • api/v1/timeout_test.go
  • api/v1/types.go
  • chart/crds/configs.flanksource.com_scrapeconfigs.yaml
  • cmd/run.go
  • config/schemas/config_exec.schema.json
  • config/schemas/config_github.schema.json
  • config/schemas/config_playwright.schema.json
  • config/schemas/scrape_config.schema.json
  • scrapers/run.go
  • scrapers/run_now.go
💤 Files with no reviewable changes (1)
  • api/context.go

Comment thread api/v1/types.go
@adityathebe adityathebe requested a review from moshloop July 7, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant