Skip to content

feat(telemetry): Add bytes-scanned metrics for query jobs. - #2380

Open
rishikeshdevsot wants to merge 4 commits into
y-scope:mainfrom
rishikeshdevsot:search-metric
Open

feat(telemetry): Add bytes-scanned metrics for query jobs.#2380
rishikeshdevsot wants to merge 4 commits into
y-scope:mainfrom
rishikeshdevsot:search-metric

Conversation

@rishikeshdevsot

@rishikeshdevsot rishikeshdevsot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds OpenTelemetry metrics to the query scheduler that track how much archive data is selected for each search/aggregation job, in both uncompressed (original log volume) and compressed (on-disk) bytes.

  • Two new histogram metrics, emitted once per query job: clp.query.uncompressed_bytes_scanned, clp.query.compressed_bytes_scanned. Two new cumulative metrics: clp.query.uncompressed_bytes_scanned_total, clp.query.compressed_bytes_scanned_total

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Summary by CodeRabbit

  • New Features

    • Added telemetry that reports uncompressed and compressed bytes scanned for query jobs.
    • Query jobs now track total uncompressed and compressed bytes scanned.
  • Documentation

    • Updated the telemetry reference with definitions for the new cumulative counter and histogram metrics for query scheduling.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The query scheduler now selects archive size metadata, stores compressed and uncompressed scan-byte totals on search jobs, emits four OpenTelemetry metrics at completion, and documents the new metrics.

Changes

Query scheduler scan telemetry

Layer / File(s) Summary
Track archive scan-byte totals
components/job-orchestration/.../query_scheduler.py, components/job-orchestration/.../scheduler_data.py
Archive selection queries return compressed and uncompressed sizes, which are summed into new SearchJob fields.
Emit and document scan-byte metrics
components/job-orchestration/.../query_scheduler.py, docs/src/user-docs/reference-telemetry.md
Search completion records compressed and uncompressed totals in new histograms and counters, with matching telemetry reference entries.

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

Sequence Diagram(s)

sequenceDiagram
  participant QueryScheduler
  participant ArchiveSelection
  participant SearchJob
  participant OpenTelemetry
  QueryScheduler->>ArchiveSelection: Select archive sizes
  ArchiveSelection-->>QueryScheduler: Return compressed and uncompressed sizes
  QueryScheduler->>SearchJob: Store summed scan-byte totals
  QueryScheduler->>OpenTelemetry: Record totals at job completion
Loading

Suggested reviewers: junhaoliao

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding bytes-scanned telemetry for query jobs.
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 unit tests (beta)
  • Create PR with unit tests

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.

@rishikeshdevsot rishikeshdevsot changed the title Search metric feat(telemetry): Add bytes-scanned metrics for query jobs. Jul 17, 2026
@rishikeshdevsot
rishikeshdevsot marked this pull request as ready for review July 17, 2026 15:27
@rishikeshdevsot
rishikeshdevsot requested a review from a team as a code owner July 17, 2026 15:27

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py (1)

1-1: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Semantic mismatch between metric names ("scanned") and tracking logic ("selected").

The new metrics and fields use the term scanned, but the logic and descriptions explicitly track the data selected for query jobs (i.e., the total size of all archives initially matching the query). Because search jobs can terminate early (e.g., when reaching max_num_results), they may not scan all the selected archives, making the scanned label misleading.

If the intent is to track the initial data selected (as the descriptions suggest), please update the names to selected to align with the behaviour. If the intent is to track data actually scanned, the logic must be reworked to incrementally aggregate the sizes of only completed tasks.

  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py#L157-176: Rename the OpenTelemetry metrics to _bytes_selected and _bytes_selected_total (or change the tracking logic to measure actual scanned data).
  • components/job-orchestration/job_orchestration/scheduler/scheduler_data.py#L90-91: Rename the fields to uncompressed_bytes_selected and compressed_bytes_selected.
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py#L1043-1046: Update the metric emissions to use the correctly named metrics and fields.
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py#L1474-1476: Assign the values to the correctly named fields.
  • docs/src/user-docs/reference-telemetry.md#L34-35: Update the documentation table rows to reflect the renamed counters.
  • docs/src/user-docs/reference-telemetry.md#L60-61: Update the documentation table rows to reflect the renamed histograms.
🤖 Prompt for 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.

In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`
at line 1, The metrics and scheduler fields currently call data “scanned” while
tracking the total data initially selected by the query. Rename the related
OpenTelemetry metrics in query scheduler initialization, SchedulerData fields,
metric emissions, and assignments to use “selected” consistently, including
uncompressed/compressed variants; update both corresponding telemetry
documentation tables to match the new names.
🤖 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
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`:
- Around line 1474-1476: Update the archive byte totals in the query scheduler
result construction to treat NULL database values as zero before summing.
Specifically, adjust the uncompressed_size and compressed_size lookups in the
sum expressions for uncompressed_bytes_scanned and compressed_bytes_scanned,
preserving the existing aggregation for non-NULL values.

---

Outside diff comments:
In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`:
- Line 1: The metrics and scheduler fields currently call data “scanned” while
tracking the total data initially selected by the query. Rename the related
OpenTelemetry metrics in query scheduler initialization, SchedulerData fields,
metric emissions, and assignments to use “selected” consistently, including
uncompressed/compressed variants; update both corresponding telemetry
documentation tables to match the new names.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: c0129d25-fef6-462d-9529-010e2a4381e2

📥 Commits

Reviewing files that changed from the base of the PR and between 46f0c0a and 690eda9.

📒 Files selected for processing (3)
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py
  • components/job-orchestration/job_orchestration/scheduler/scheduler_data.py
  • docs/src/user-docs/reference-telemetry.md

Comment on lines +1474 to 1476
uncompressed_bytes_scanned=sum(a["uncompressed_size"] for a in archives_for_search),
compressed_bytes_scanned=sum(a["compressed_size"] for a in archives_for_search),
)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Safeguard against None values when summing database results.

If uncompressed_size or size can be NULL in the database schema, a["uncompressed_size"] will evaluate to None, causing sum() to raise a TypeError. Consider defaulting to 0 to safely handle potential NULL values.

🛡️ Proposed fix
-        uncompressed_bytes_scanned=sum(a["uncompressed_size"] for a in archives_for_search),
-        compressed_bytes_scanned=sum(a["compressed_size"] for a in archives_for_search),
+        uncompressed_bytes_scanned=sum((a["uncompressed_size"] or 0) for a in archives_for_search),
+        compressed_bytes_scanned=sum((a["compressed_size"] or 0) for a in archives_for_search),
📝 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.

Suggested change
uncompressed_bytes_scanned=sum(a["uncompressed_size"] for a in archives_for_search),
compressed_bytes_scanned=sum(a["compressed_size"] for a in archives_for_search),
)
uncompressed_bytes_scanned=sum((a["uncompressed_size"] or 0) for a in archives_for_search),
compressed_bytes_scanned=sum((a["compressed_size"] or 0) for a in archives_for_search),
)
🤖 Prompt for 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.

In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`
around lines 1474 - 1476, Update the archive byte totals in the query scheduler
result construction to treat NULL database values as zero before summing.
Specifically, adjust the uncompressed_size and compressed_size lookups in the
sum expressions for uncompressed_bytes_scanned and compressed_bytes_scanned,
preserving the existing aggregation for non-NULL values.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py (1)

1078-1081: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Metric emission logic looks correct; consider adding test coverage.

Emission is gated on a successful terminal-state DB update, mirroring the existing job_duration_histogram pattern, and matches the PR's intent (histogram once per job, counters cumulative). No functional issue found here, but there's no test exercising the new sum-and-emit path (byte totals computed in _handle_new_search_job and recorded here on completion).

🤖 Prompt for 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.

In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`
around lines 1078 - 1081, Add test coverage for the successful terminal-state
path that computes byte totals in _handle_new_search_job and records them at
completion alongside job_duration_histogram. Verify each byte histogram is
recorded once per job and each byte counter receives the cumulative total, while
preserving the existing emission gating behavior.
🤖 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.

Outside diff comments:
In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`:
- Around line 1078-1081: Add test coverage for the successful terminal-state
path that computes byte totals in _handle_new_search_job and records them at
completion alongside job_duration_histogram. Verify each byte histogram is
recorded once per job and each byte counter receives the cumulative total, while
preserving the existing emission gating behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 955768fe-87bb-4685-83b3-874807ad4bcc

📥 Commits

Reviewing files that changed from the base of the PR and between 690eda9 and 4c066fe.

📒 Files selected for processing (1)
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py

@Nathan903 Nathan903 self-assigned this Aug 4, 2026
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.

3 participants