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

Add partition length metrics to Olric #3053

Merged
merged 2 commits into from
Dec 14, 2023
Merged

Conversation

kwapik
Copy link
Contributor

@kwapik kwapik commented Dec 13, 2023

Description of change

This can be used to track number of keys and their backups in Olric.

Checklist
  • Tested in playground or other setup

Summary by CodeRabbit

  • New Features

    • Introduced new metrics to monitor the length of cache partitions and backup partitions, enhancing visibility into cache performance and health.
  • Refactor

    • Updated cache metrics collection to include new partition length measurements.

@kwapik kwapik requested a review from a team as a code owner December 13, 2023 13:46
Copy link
Contributor

coderabbitai bot commented Dec 13, 2023

Walkthrough

The recent changes involve enhancing the distributed cache metrics by introducing two new gauge metrics: one for the length of cache partitions and another for the length of backup cache partitions. These metrics are added to the DistCacheMetrics struct and are calculated within the DistCache type's scrapeMetrics method. Additionally, corresponding constants are defined in the metrics schema.

Changes

File(s) Change Summary
pkg/dist-cache/dist-cache-metrics.go, pkg/dist-cache/dist-cache.go Added PartitionsLength and BackupPartitionsLength metrics to DistCacheMetrics and updated scrapeMetrics to calculate these metrics.
pkg/metrics/schema.go Introduced new constants for cache partition length metrics.

Poem

🐇
In the realm of cache, a change took flight,
Metrics for partitions, now in plain sight.
Lengths counted with care, in backup and main,
CodeRabbit hopped joyfully, for clarity's gain.
🌟


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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.

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

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3828bba and cf96ea7.
Files selected for processing (3)
  • pkg/dist-cache/dist-cache-metrics.go (3 hunks)
  • pkg/dist-cache/dist-cache.go (1 hunks)
  • pkg/metrics/schema.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/metrics/schema.go
Additional comments: 8
pkg/dist-cache/dist-cache-metrics.go (4)
  • 22-23: The addition of PartitionsLength and BackupPartitionsLength to the DistCacheMetrics struct aligns with the PR's objective to introduce new metrics for tracking the number of keys and their backups across partitions. This change appears to be correctly implemented.

  • 69-76: The initialization of PartitionsLength and BackupPartitionsLength in the newDistCacheMetrics function is consistent with the initialization of other metrics in this function. The metric names and help descriptions are set appropriately.

  • 92-93: The update to the allMetrics method to include PartitionsLength and BackupPartitionsLength ensures that these new metrics will be collected and exposed by Prometheus. This change is correctly implemented.

  • 66-79: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [19-95]

It is recommended to test the new metrics in a playground or test environment to ensure they are being collected and reported as expected. This would involve deploying the changes and verifying the metrics through Prometheus queries.

pkg/dist-cache/dist-cache.go (4)
  • 151-171: The implementation of the new metrics within the scrapeMetrics method appears to correctly accumulate the lengths of partitions and backup partitions and sets the gauge metrics accordingly. However, there are a few points to consider:
  1. Error Handling: The error handling for the metric retrieval or creation logs a debug message and continues. This is consistent with the existing pattern in the method. However, it might be beneficial to consider if this is the desired behavior or if any additional action should be taken upon failure to retrieve or create metrics.

  2. Performance: The loop to calculate the lengths of partitions and backup partitions is straightforward and should perform well given that the number of partitions is not excessively large. If the number of partitions could be large, it might be worth considering if there's a more efficient way to retrieve these statistics from Olric directly.

  3. Best Practices: The code is clear and follows the existing structure of the scrapeMetrics method. It's good to see that the new metrics are consistent with the existing metrics in terms of naming and handling.

Overall, the changes seem to align with the PR objectives and are implemented correctly. It's important to ensure that the new metrics are documented and that any necessary updates to related documentation or dashboards are made to reflect these new metrics.

  • 151-171: Please ensure that the new metrics are thoroughly tested in a development or staging environment to verify their correctness and to ensure that they do not introduce any unexpected behavior.

  • 151-171: Consider if there are any concurrency concerns with the new metrics. Since scrapeMetrics may be called concurrently, ensure that the metric updates are thread-safe. The Prometheus client library typically handles concurrency internally, but it's good to confirm that this is the case for the used metric types.

  • 151-171: Please verify that the DistCacheMetrics struct and the newDistCacheMetrics and allMetrics methods within dist-cache-metrics.go have been updated to include and initialize the new metrics as described in the PR objectives and AI-generated summaries.

@kwapik kwapik enabled auto-merge (squash) December 14, 2023 11:29
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cf96ea7 and 01e8fa2.
Files selected for processing (1)
  • pkg/metrics/schema.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/metrics/schema.go

@kwapik kwapik merged commit 0ce654f into main Dec 14, 2023
21 checks passed
@kwapik kwapik deleted the kwapik/partition-len-metrics branch December 14, 2023 11:42
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.

2 participants