Skip to content

track how many rows are inserted into clickhouse #235

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

Merged

Conversation

iuwqyir
Copy link
Collaborator

@iuwqyir iuwqyir commented Jul 8, 2025

TL;DR

Added Prometheus metrics to track ClickHouse insert operations.

What changed?

  • Added new Prometheus counters in metrics.go to track ClickHouse insert operations:
    • clickhouse_main_storage_rows_inserted_total
    • clickhouse_transactions_inserted_total
    • clickhouse_logs_inserted_total
    • clickhouse_traces_inserted_total
  • Instrumented the ClickHouse connector to increment these counters when data is inserted
  • Added metrics tracking in both individual insert methods and batch insert operations

How to test?

  1. Run the application with Prometheus enabled
  2. Perform operations that insert data into ClickHouse
  3. Check Prometheus metrics endpoint to verify the new counters are incrementing correctly
  4. Validate that the metrics accurately reflect the number of rows inserted

Why make this change?

These metrics provide visibility into the volume of data being inserted into ClickHouse, which is crucial for monitoring system performance and data processing rates. This information helps with capacity planning, identifying bottlenecks, and ensuring the system is operating efficiently.

Summary by CodeRabbit

  • New Features
    • Added new metrics to track the total number of rows inserted into main storage, transactions, logs, and traces for ClickHouse operations. These metrics provide enhanced visibility into data insertion activity.

Copy link

coderabbitai bot commented Jul 8, 2025

Walkthrough

The changes introduce new Prometheus counters to track the number of rows inserted into various ClickHouse tables, including main storage, transactions, logs, and traces. The ClickHouse insertion methods are updated to increment these counters upon successful data insertion, enhancing observability without altering existing logic or control flow.

Changes

File(s) Change Summary
internal/metrics/metrics.go Added four Prometheus counters for tracking ClickHouse row insertions across different categories.
internal/storage/clickhouse.go Updated insertion methods to increment the new metrics after successful inserts.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ClickHouseConnector
    participant Metrics

    Client->>ClickHouseConnector: insertTransactions / insertLogs / insertTraces / InsertBlockData
    ClickHouseConnector->>ClickHouse: Insert rows
    alt Insert successful
        ClickHouseConnector->>Metrics: Increment relevant counter(s) by number of rows inserted
    end
    ClickHouseConnector-->>Client: Return result
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae2d185 and 8cd9a9a.

📒 Files selected for processing (2)
  • internal/metrics/metrics.go (1 hunks)
  • internal/storage/clickhouse.go (9 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/storage/clickhouse.go (1)
internal/metrics/metrics.go (4)
  • ClickHouseTransactionsInserted (163-166)
  • ClickHouseLogsInserted (168-171)
  • ClickHouseTracesInserted (173-176)
  • ClickHouseMainStorageRowsInserted (158-161)
🔇 Additional comments (6)
internal/metrics/metrics.go (1)

155-177: LGTM! Well-defined Prometheus metrics.

The new ClickHouse insert metrics are properly defined with:

  • Appropriate counter type for cumulative row counts
  • Consistent naming convention with _total suffix
  • Clear and descriptive help strings
  • Proper grouping under a descriptive comment section

These metrics will provide valuable observability into data insertion volumes.

internal/storage/clickhouse.go (5)

21-21: LGTM! Correct metrics import added.

The import for the metrics package is properly added to enable instrumentation.


275-275: LGTM! Correct metrics instrumentation for transaction inserts.

The counter is properly incremented after successful batch processing with the total number of transactions inserted.


338-338: LGTM! Correct metrics instrumentation for log inserts.

The counter is properly incremented after successful batch processing with the total number of logs inserted.


410-410: LGTM! Correct metrics instrumentation for trace inserts.

The counter is properly incremented after successful batch processing with the total number of traces inserted.


1195-1197: LGTM! Excellent batching logic for metrics tracking.

The metrics instrumentation in InsertBlockData correctly handles the batching scenario:

  1. Batch-level counting: Local counters are reset for each batch and accumulate counts within the batch
  2. Immediate metrics update: Individual metrics are incremented after each successful batch send
  3. Total tracking: Main storage counter is incremented with the total number of blocks after all batches complete

This approach ensures accurate metrics even with large datasets that require multiple batches, while providing timely updates per batch.

Also applies to: 1228-1228, 1267-1267, 1287-1287, 1358-1360, 1363-1363

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Collaborator Author

iuwqyir commented Jul 8, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@iuwqyir iuwqyir marked this pull request as ready for review July 8, 2025 17:28
@iuwqyir iuwqyir merged commit 184181a into main Jul 8, 2025
6 checks passed
@iuwqyir iuwqyir deleted the 07-08-track_how_many_rows_are_inserted_into_clickhouse branch July 8, 2025 18:02
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