Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(weave): sane limits on delete handling #3895

Merged
merged 2 commits into from
Mar 18, 2025

Conversation

gtarpenning
Copy link
Member

@gtarpenning gtarpenning commented Mar 18, 2025

Description

In the pathological case the delete path has an unbounded query (all traces in a project are children of the same parent), put a sane limit on the query.

This is a temporary solution, the robust solution will require a trace to know about its children. Right now, traces only have pointers to parents, so we can't walk down the tree (only up).

Testing

👀

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced deletion operations by introducing a processing limit, ensuring improved performance and more predictable behavior during large-scale deletions.

@circle-job-mirror
Copy link

circle-job-mirror bot commented Mar 18, 2025

@gtarpenning gtarpenning marked this pull request as ready for review March 18, 2025 17:41
@gtarpenning gtarpenning requested a review from a team as a code owner March 18, 2025 17:41
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request revises the calls_delete method in the ClickHouseTraceServer class. The modifications include updating comments to clarify that the method retrieves the requested calls to delete, extracting parent trace IDs into a new variable parent_trace_ids, and introducing a limit of 10,000 calls in the query. No changes have been made to the declarations of exported or public entities.

Changes

File Path Change Summary
weave/trace_server/.../clickhouse_trace_server_batched.py Updated comments in calls_delete to clarify call retrieval; extracted parent trace IDs into parent_trace_ids; added a limit of 10,000 to the calls query.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Req as Client Request
    participant Srv as ClickHouseTraceServer
    participant DB as Database
    Req->>Srv: Invoke calls_delete()
    Srv->>Srv: Retrieve parent calls and extract parent_trace_ids
    Srv->>DB: Execute query using parent_trace_ids with LIMIT 10000
    DB-->>Srv: Return matching calls
    Srv->>Srv: Process deletion of calls
    Srv-->>Req: Return deletion result

Possibly related PRs

Suggested reviewers

  • andrewtruong

Poem

I'm a rabbit, hopping with delight,
Adjusted queries in the day and night.
Parent IDs gathered with care and pace,
With a limit in place—running a cleaner race.
CodeRabbit cheers with a twitching nose,
Celebrating changes wherever it goes!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

@gtarpenning gtarpenning requested a review from neutralino1 March 18, 2025 17:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
weave/trace_server/clickhouse_trace_server_batched.py (2)

490-498: Add the query limit as a constant rather than using a magic number.

Adding a limit to prevent unbounded queries is excellent, but the 10_000 limit should be defined as a constant at the module level (like other constants such as MAX_DELETE_CALLS_COUNT).

- limit=10_000,
+ limit=MAX_CALLS_DELETE_BATCH_SIZE,

Add this constant to the constants section around line 137:

MAX_DELETE_CALLS_COUNT = 1000
MAX_CALLS_DELETE_BATCH_SIZE = 10000
INITIAL_CALLS_STREAM_BATCH_SIZE = 50

490-498: Consider adding logging or handling for truncated results.

The current implementation limits results to 10,000 calls but doesn't provide any notification or special handling if the actual number of calls exceeds this limit. Consider adding a warning log when the limit is reached to help diagnose potential issues with incomplete deletions.

  all_calls = list(
      self.calls_query_stream(
          tsi.CallsQueryReq(
              project_id=req.project_id,
              filter=tsi.CallsFilter(trace_ids=parent_trace_ids),
              columns=["id", "parent_id"],
              limit=10_000,
          )
      )
  )
+ if len(all_calls) == 10_000:
+     logger.warning(
+         f"Potentially truncated delete operation. Limit of 10,000 calls reached for project_id={req.project_id}"
+     )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 668768e and cef61fa.

📒 Files selected for processing (1)
  • weave/trace_server/clickhouse_trace_server_batched.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Focus on pythonic code patterns. Check for proper exception handling. Verify type hints usage where applicable. Look for potential performance improvements. Don't commen...

**/*.py: Focus on pythonic code patterns.
Check for proper exception handling.
Verify type hints usage where applicable.
Look for potential performance improvements.
Don't comment on formatting if black/isort is configured.
Check for proper dependency injection patterns.
Verify proper async handling if applicable.

  • weave/trace_server/clickhouse_trace_server_batched.py
🧬 Code Definitions (1)
weave/trace_server/clickhouse_trace_server_batched.py (3)
weave/trace_server/sqlite_trace_server.py (1) (1)
  • calls_query_stream (534:535)
weave/trace_server/trace_server_interface.py (3) (3)
  • calls_query_stream (914:914)
  • CallsQueryReq (319:346)
  • CallsFilter (298:307)
tests/conftest.py (1) (1)
  • calls_query_stream (117:118)
⏰ Context from checks skipped due to timeout of 90000ms (40)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, trace)
🔇 Additional comments (1)
weave/trace_server/clickhouse_trace_server_batched.py (1)

476-488: Good refactor: Extracting parent trace IDs improves code readability.

This refactoring improves the code by extracting parent_trace_ids as a named variable, making the code more readable and the intention clearer.

@gtarpenning gtarpenning merged commit 2072fe5 into master Mar 18, 2025
131 of 133 checks passed
@gtarpenning gtarpenning deleted the griffin/delete-optimization branch March 18, 2025 18:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants