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

feat(index): distinguish different types of index metrics #4337

Merged

Conversation

zhongzc
Copy link
Contributor

@zhongzc zhongzc commented Jul 10, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

AS STATED

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Enhanced metrics tracking with more granular data through new IntCounterVec and IntGaugeVec.
  • Improvements

    • Added new constants and fields to support better indexing (TYPE_INVERTED_INDEX, TYPE_FULLTEXT_INDEX).
    • Improved memory usage tracking within the Indexer struct.
    • Custom initialization for statistics in SstIndexCreator to provide more detailed metrics.
  • Bug Fixes

    • Updated methods to ensure accurate metrics collection, including flush_mem_metrics.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

The recent updates primarily focus on enhancing metrics tracking and struct initialization in the mito2 module. Key changes include switching from single metric counters and gauges to vectorized versions, adding specific index types, and refining how metrics are recorded. Additionally, the Statistics struct is now initialized with index type to facilitate more granular metric observation.

Changes

File/Path Change Summary
src/mito2/src/metrics.rs Updated metric declarations from single counters/gauges to vectorized versions with type labels.
src/mito2/src/sst/index.rs Added constants for index types, modified Indexer struct to include memory fields, and updated methods.
src/mito2/src/sst/index/fulltext_index/creator.rs Initialized SstIndexCreator's stats field with Statistics::new(TYPE_FULLTEXT_INDEX).
src/mito2/src/sst/index/inverted_index/creator.rs Updated SstIndexCreator's stats field initialization to Statistics::new(TYPE_INVERTED_INDEX).
src/mito2/src/sst/index/statistics.rs Added index_type field and new method to Statistics, updated Drop impl to include index_type.

Poem

In metrics land, a change unfolds,
Where stats in vectors, truth now holds.
Inverted, full-text, types align,
Memory tracked, metrics shine.
Code refined, metrics new,
For a future bright and true. 🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 10, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between da0c840 and 5831578.

Files selected for processing (5)
  • src/mito2/src/metrics.rs (1 hunks)
  • src/mito2/src/sst/index.rs (3 hunks)
  • src/mito2/src/sst/index/fulltext_index/creator.rs (2 hunks)
  • src/mito2/src/sst/index/inverted_index/creator.rs (2 hunks)
  • src/mito2/src/sst/index/statistics.rs (4 hunks)
Additional comments not posted (12)
src/mito2/src/sst/index/statistics.rs (4)

31-32: Addition of index_type field is appropriate.

The inclusion of the index_type field allows for better granularity in metrics tracking.


46-55: New method initialization is correct.

The new method initializes the index_type field along with other fields, ensuring proper setup of the Statistics struct.


89-108: Drop implementation updates are correct.

The updated Drop implementation correctly includes index_type in its metric observations, ensuring accurate tracking.


Line range hint 163-178:
Test case addition is appropriate.

The test case verifies the basic functionality of the Statistics struct, including the new index_type field.

src/mito2/src/sst/index/fulltext_index/creator.rs (2)

39-39: Initialization with TYPE_FULLTEXT_INDEX is appropriate.

The change ensures that the Statistics struct is initialized with the correct index type.


108-108: Initialization with TYPE_FULLTEXT_INDEX is appropriate.

The change ensures that the Statistics struct is initialized with the correct index type.

src/mito2/src/metrics.rs (1)

212-234: Metrics update to use IntCounterVec and IntGaugeVec with TYPE_LABEL is appropriate.

The changes improve the granularity of metrics tracking by including the index type as a label.

src/mito2/src/sst/index.rs (4)

41-43: Addition of TYPE_INVERTED_INDEX and TYPE_FULLTEXT_INDEX constants is appropriate.

The new constants are necessary for distinguishing between different index types.


98-100: Addition of last_mem_inverted_index and last_mem_fulltext_index fields is appropriate.

The new fields are necessary for tracking memory usage metrics for different index types.


108-123: Updates to call flush_mem_metrics in update, finish, and abort methods are appropriate.

The changes ensure that memory usage metrics are flushed after each operation, improving the accuracy of metrics tracking.


126-143: Addition of flush_mem_metrics method is appropriate.

The method accurately calculates and updates memory usage metrics for both inverted and full-text indexes.

src/mito2/src/sst/index/inverted_index/creator.rs (1)

123-123: LGTM! Ensure Statistics::new is correctly implemented.

The initialization of Statistics with TYPE_INVERTED_INDEX looks good.

However, verify that the Statistics::new method properly initializes all required fields.

Verification successful

Verification Successful

The Statistics::new method correctly initializes all required fields, including index_type, update_elapsed, finish_elapsed, cleanup_eplased, row_count, and byte_count.

  • index_type is properly initialized with TYPE_INVERTED_INDEX.
  • Other fields are initialized with default values.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `Statistics::new` method

# Test: Search for the `Statistics::new` method implementation. Expect: Proper initialization of all fields.
rg --type rust -A 5 'impl Statistics {.*fn new'

Length of output: 174


Script:

#!/bin/bash
# Description: Verify the implementation of `Statistics::new` method

# Test: Search for the `Statistics::new` method implementation. Expect: Proper initialization of all fields.
rg --type rust -A 5 'impl Statistics \{.*fn new'

Length of output: 50


Script:

#!/bin/bash
# Description: Search for all methods within the `Statistics` implementation to locate the `new` method.

# Test: Search for all methods in the `Statistics` implementation. Expect: Locate the `new` method.
rg --type rust 'impl Statistics \{'

Length of output: 93


Script:

#!/bin/bash
# Description: Verify the implementation of `Statistics::new` method within the specific file

# Test: Search for the `new` method implementation in `src/mito2/src/sst/index/statistics.rs`
rg --type rust 'fn new' src/mito2/src/sst/index/statistics.rs -A 10

Length of output: 696

Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.90%. Comparing base (da0c840) to head (5831578).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4337      +/-   ##
==========================================
- Coverage   85.18%   84.90%   -0.29%     
==========================================
  Files        1060     1060              
  Lines      189069   189089      +20     
==========================================
- Hits       161057   160542     -515     
- Misses      28012    28547     +535     

@waynexia waynexia enabled auto-merge July 11, 2024 06:42
Copy link
Contributor

@evenyag evenyag left a comment

Choose a reason for hiding this comment

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

LGTM

@waynexia waynexia added this pull request to the merge queue Jul 14, 2024
Merged via the queue into GreptimeTeam:main with commit 377a513 Jul 14, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants