Skip to content

Support customize the bucket of histogram metrics#2627

Merged
maobaolong merged 2 commits intoLMCache:devfrom
maobaolong:confHistoryBucket
Feb 24, 2026
Merged

Support customize the bucket of histogram metrics#2627
maobaolong merged 2 commits intoLMCache:devfrom
maobaolong:confHistoryBucket

Conversation

@maobaolong
Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong commented Feb 21, 2026

What this PR does / why we need it:

Special notes for your reviewers:

If applicable:

  • this PR contains user facing changes - docs added
  • this PR contains unit tests

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @maobaolong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the observability features by allowing users to define custom bucket boundaries for Prometheus histogram metrics. This provides greater flexibility in monitoring and analyzing performance data, enabling more granular insights into specific operational ranges. The changes involve updating the Prometheus logging infrastructure to consume configuration settings for buckets and providing clear documentation on how to use this new capability.

Highlights

  • Custom Prometheus Histogram Buckets: Introduced the ability to customize Prometheus histogram bucket boundaries for various metrics. Users can now define specific bucket ranges to better suit their monitoring needs.
  • Configuration via extra_config: Custom bucket definitions are provided through the extra_config section, using keys like histogram_bucket_<metric_name> with a list of numeric boundaries.
  • Updated PrometheusLogger: The PrometheusLogger class was modified to accept and utilize a configuration object, allowing it to dynamically apply custom bucket settings during histogram creation.
  • Comprehensive Documentation: New documentation was added detailing how to configure custom histogram buckets, including examples and a list of all available metric names that can be customized.
  • Unit Tests: New unit tests were added to ensure the correct application of default and custom histogram buckets, covering various configuration scenarios.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docs/source/api_reference/configurations.rst
    • Added a new section 'Custom Prometheus Histogram Buckets' to the configuration documentation.
    • Included instructions and examples for overriding default histogram bucket boundaries using extra_config.
    • Provided a list-table enumerating available histogram names and their descriptions for customization.
  • lmcache/observability.py
    • Modified the _create_histogram method to check for custom bucket definitions in the provided configuration.
    • Updated the PrometheusLogger.__init__ method to accept an optional config object.
    • Updated the PrometheusLogger.GetOrCreate static method to pass the config object to the constructor.
    • Updated the LMCacheStatsLogger.__init__ method to accept an optional config object and pass it to PrometheusLogger.GetOrCreate.
  • lmcache/v1/cache_engine.py
    • Modified LMCacheEngine.get_or_create to pass the config object when initializing LMCacheStatsLogger.
  • lmcache/v1/manager.py
    • Updated LMCacheManager._init_scheduler_components to pass the config object to PrometheusLogger.GetOrCreate.
  • tests/test_observability.py
    • Imported MagicMock and PrometheusLogger for testing.
    • Added a _cleanup_prometheus_logger fixture to reset the PrometheusLogger singleton and metrics between tests.
    • Added helper functions _make_metadata and _make_config for creating mock objects.
    • Implemented test_prometheus_logger_default_buckets to verify default bucket behavior.
    • Implemented test_prometheus_logger_custom_buckets to confirm custom buckets are applied from configuration.
    • Implemented test_prometheus_logger_partial_custom_buckets to ensure only specified histograms receive custom buckets.
    • Implemented test_prometheus_logger_get_or_create_with_config to test the GetOrCreate method with custom configuration.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@maobaolong
Copy link
Copy Markdown
Collaborator Author

@sammshen @chunxiaozheng Would you like to take a look at this PR? Thanks!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature allowing customization of Prometheus histogram buckets through extra_config. The implementation is well-structured, propagating the configuration object through the necessary layers. The accompanying documentation is clear, and the unit tests are thorough. My review includes a few suggestions to improve type safety by replacing Optional[Any] with a more specific type hint for the config parameter in lmcache/observability.py.

Comment thread lmcache/observability.py
Comment thread lmcache/observability.py
Comment thread lmcache/observability.py
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@maobaolong maobaolong added the full Run comprehensive tests on this PR label Feb 21, 2026
Copy link
Copy Markdown
Contributor

@sammshen sammshen left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Collaborator

@chunxiaozheng chunxiaozheng left a comment

Choose a reason for hiding this comment

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

lgtm

@maobaolong maobaolong merged commit 841f288 into LMCache:dev Feb 24, 2026
35 of 37 checks passed
sammshen pushed a commit to sammshen/LMCache that referenced this pull request Mar 1, 2026
* Support customize the bucket of histogram metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* address comments from gemini-bot

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
hlin99 pushed a commit to hlin99/LMCache that referenced this pull request Mar 2, 2026
* Support customize the bucket of histogram metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* address comments from gemini-bot

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
mauryaavinash95 pushed a commit to mauryaavinash95/LMCache that referenced this pull request Mar 7, 2026
* Support customize the bucket of histogram metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* address comments from gemini-bot

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
shaoxiawjc pushed a commit to shaoxiawjc/LMCache that referenced this pull request Mar 11, 2026
* Support customize the bucket of histogram metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* address comments from gemini-bot

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: shaoxiawjc <wjc2800@163.com>
realAaronWu pushed a commit to realAaronWu/LMCache that referenced this pull request Mar 20, 2026
* Support customize the bucket of histogram metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

* address comments from gemini-bot

Signed-off-by: baoloongmao <baoloongmao@tencent.com>

---------

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: Aaron Wu <aaron.wu@dell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants