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(store/v2): basic metrics #18529

Merged
merged 8 commits into from
Nov 28, 2023
Merged

feat(store/v2): basic metrics #18529

merged 8 commits into from
Nov 28, 2023

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Nov 20, 2023

Description

Closes: #18463

Measure time of core operations in RootStore.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced a new telemetry system to measure performance metrics for various store operations.
  • Enhancements

    • Improved store operations with the addition of telemetry measurements for better performance tracking.
  • Tests

    • Updated tests to accommodate new telemetry functionality within store operations.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2023

Walkthrough

The changes introduce a new metrics package and integrate it into the store package to enable metric collection for various store operations. The metrics package defines interfaces and implementations for measuring time metrics, including a no-op version for cases where metrics are not needed. The store package is updated to include a telemetry field and to call the MeasureSince method in key store operations, allowing for the collection of performance metrics.

Changes

File Path Change Summary
store/metrics/metrics.go Introduced a new metrics package with StoreMetrics interface and Metrics, NoOpMetrics implementations.
store/root/store.go Added metrics.StoreMetrics field and integrated MeasureSince calls in store methods.
store/root/store_test.go Updated tests to include metrics.NoOpMetrics or nil in RootStore initialization.

Assessment against linked issues

Objective Addressed Explanation
#18463: Store: Export Metrics The changes include the implementation of a metrics system within the store package, which aligns with the objective of exporting metrics from the store.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

@alexanderbez alexanderbez marked this pull request as ready for review November 20, 2023 22:39
@alexanderbez alexanderbez requested a review from a team as a code owner November 20, 2023 22:39
Copy link
Contributor

@alexanderbez your pull request is missing a changelog!

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8644e6b and 9617032.
Files selected for processing (3)
  • store/metrics/metrics.go (1 hunks)
  • store/root/store.go (8 hunks)
  • store/root/store_test.go (2 hunks)
Additional comments: 10
store/root/store_test.go (2)
  • 11-16: The import statement for the metrics package has been added correctly to support the new metrics functionality in the test suite. This change aligns with the pull request's goal of integrating metrics into the RootStore.

  • 33-39: The RootStore is now being initialized with a metrics.NoOpMetrics{} instance. This is a good practice for tests where metrics collection is not needed, as it avoids the overhead of the metrics collection process. However, ensure that the New function's signature has been updated to accept this new parameter and that all calls to New throughout the codebase have been updated accordingly.

store/root/store.go (8)
  • 12-17: The import statements are correctly updated to include the new metrics package. This is necessary for the new functionality being added to the RootStore.

  • 58-64: The addition of the telemetry field to the Store struct is consistent with the goal of integrating metrics into the RootStore. However, ensure that all instances of Store are now initialized with a valid metrics.StoreMetrics implementation to avoid nil pointer dereferences when calling s.telemetry.MeasureSince.

  • 58-74: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [66-88]

The New function has been correctly updated to accept a metrics.StoreMetrics parameter and initialize the telemetry field of the Store struct. This change is necessary for the new metrics functionality.

  • 166-171: The use of defer s.telemetry.MeasureSince("root_store", "query") is appropriate for measuring the duration of the Query method. However, ensure that the MeasureSince method is designed to handle cases where the telemetry field might be a NoOpMetrics instance, which should result in a no-op.

  • 212-217: The LoadLatestVersion method now includes a call to s.telemetry.MeasureSince to track the time taken by the method. This is consistent with the goal of adding metrics to the store operations.

  • 223-226: The LoadVersion method is correctly instrumented with a call to s.telemetry.MeasureSince to measure its execution time. This is in line with the changes made to other methods for metrics collection.

  • 290-297: The WorkingHash method is instrumented with a call to s.telemetry.MeasureSince to measure its execution time. This is in line with the changes made to other methods for metrics collection.

  • 319-323: The Commit method is instrumented with a call to s.telemetry.MeasureSince to measure its execution time. Ensure that the workingHash is indeed set before calling Commit to avoid runtime errors due to the precondition check.

store/metrics/metrics.go Outdated Show resolved Hide resolved
@alexanderbez alexanderbez marked this pull request as draft November 20, 2023 22:54
@alexanderbez alexanderbez marked this pull request as ready for review November 20, 2023 23:03
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9617032 and 41d7f76.
Files selected for processing (1)
  • store/root/store.go (6 hunks)
Additional comments: 6
store/root/store.go (6)
  • 163-168: The Query function has been correctly updated to include the telemetry.MeasureSince call for metrics collection. This is a good use of deferred execution to ensure that the measurement is taken regardless of where the function returns.

  • 209-214: The LoadLatestVersion function has been correctly updated to include the telemetry.MeasureSince call for metrics collection. This is consistent with the changes made to the Query function and follows the same pattern of using deferred execution.

  • 220-223: The LoadVersion function has been correctly updated to include the telemetry.MeasureSince call for metrics collection. This is consistent with the changes made to the other functions and follows the same pattern of using deferred execution.

  • 289-294: The WorkingHash function has been correctly updated to include the telemetry.MeasureSince call for metrics collection. This is consistent with the changes made to the other functions and follows the same pattern of using deferred execution.

  • 315-320: The Commit function has been correctly updated to include the telemetry.MeasureSince call for metrics collection. This is consistent with the changes made to the other functions and follows the same pattern of using deferred execution.

  • 292-294: The WorkingHash function checks if s.workingHash is nil and if so, it calls s.writeSC(). However, there is a potential issue here. If s.writeSC() fails, the s.workingHash will remain nil, which could lead to unexpected behavior on subsequent calls to WorkingHash or Commit. It would be safer to ensure that s.workingHash is only set if s.writeSC() succeeds.

store/root/store.go Outdated Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
store/root/store.go Outdated Show resolved Hide resolved
store/root/store.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 41d7f76 and 934e038.
Files selected for processing (3)
  • store/metrics/metrics.go (1 hunks)
  • store/root/store.go (8 hunks)
  • store/root/store_test.go (1 hunks)
Additional comments: 12
store/metrics/metrics.go (3)
  • 11-14: The StoreMetrics interface is well-defined and follows the principle of least privilege by exposing only the necessary method MeasureSince.

  • 38-42: Ensure that the underlying metrics.MeasureSinceWithLabels function can handle empty keys without issues.

  • 21-35: Returning Metrics by value in NewMetrics is acceptable as it contains only a slice, which is a reference type.

store/root/store.go (9)
  • 5-8: The import of the "time" package is appropriate for the telemetry functionality added.

  • 63-64: The addition of the "telemetry" field to the "Store" struct aligns with the pull request's goal of adding metrics.

  • 67-73: The updated "New" function signature correctly includes the "metrics.StoreMetrics" parameter.

  • 167-170: Telemetry measurements have been correctly added to the "Query" method.

  • 216-219: Telemetry measurements have been correctly added to the "LoadLatestVersion" method.

  • 230-233: Telemetry measurements have been correctly added to the "LoadVersion" method.

  • 302-305: Telemetry measurements have been correctly added to the "WorkingHash" method.

  • 331-334: Telemetry measurements have been correctly added to the "Commit" method.

  • 329-339: The documentation for the "Commit" function has been updated to reflect the requirement of calling "WorkingHash" before "Commit", addressing the previous comment.

store/root/store_test.go Show resolved Hide resolved
store/metrics/metrics.go Outdated Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
store/root/store.go Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 934e038 and 72acad6.
Files selected for processing (1)
  • store/metrics/metrics.go (1 hunks)

store/metrics/metrics.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 72acad6 and 326041c.
Files selected for processing (3)
  • store/metrics/metrics.go (1 hunks)
  • store/root/store.go (8 hunks)
  • store/root/store_test.go (1 hunks)
Additional comments: 8
store/root/store.go (8)
  • 5-8: The addition of the "time" package is appropriate for the telemetry functionality added to various methods.

  • 59-64: The new "telemetry" field in the "Store" struct aligns with the changes outlined in the summary.

  • 67-72: The updated function signature of "New" to include "metrics.StoreMetrics" is consistent with the changes described.

  • 171-174: The explicit nil check for the "telemetry" field before calling "MeasureSince" is consistent with the user's preference to avoid unnecessary operations.

  • 220-223: The explicit nil check for the "telemetry" field before calling "MeasureSince" in "LoadLatestVersion" is consistent with the user's preference.

  • 234-237: The explicit nil check for the "telemetry" field before calling "MeasureSince" in "LoadVersion" is consistent with the user's preference.

  • 306-309: The explicit nil check for the "telemetry" field before calling "MeasureSince" in "WorkingHash" is consistent with the user's preference.

  • 335-338: The explicit nil check for the "telemetry" field before calling "MeasureSince" in "Commit" is consistent with the user's preference.

store/metrics/metrics.go Show resolved Hide resolved
store/metrics/metrics.go Show resolved Hide resolved
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

LGTM, thank you

Copy link
Contributor

@cool-develope cool-develope left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexanderbez alexanderbez added this pull request to the merge queue Nov 28, 2023
Merged via the queue into main with commit 0c633a5 Nov 28, 2023
60 of 61 checks passed
@alexanderbez alexanderbez deleted the bez/18463-store-v2-metrics branch November 28, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store: Export Metrics
3 participants