Skip to content

Introduce reset metrics api#2602

Merged
maobaolong merged 1 commit intoLMCache:devfrom
maobaolong:reset_metrics_gh
Feb 18, 2026
Merged

Introduce reset metrics api#2602
maobaolong merged 1 commit intoLMCache:devfrom
maobaolong:reset_metrics_gh

Conversation

@maobaolong
Copy link
Copy Markdown
Collaborator

@maobaolong maobaolong commented Feb 14, 2026

What this PR does / why we need it:

This PR introduce a way to reset Prometheus metrics. It introduces dedicated methods within the PrometheusLogger to clear and re-register counters and histograms, and exposes this functionality through a new API endpoint. This allows for easier management and debugging of metric data, particularly in environments where metrics need to be reset periodically or on demand.

Special notes for your reviewers:

If applicable:

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

@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 capabilities of LMCache by implementing a mechanism to reset Prometheus metrics. It introduces dedicated methods within the PrometheusLogger to clear and re-register counters and histograms, and exposes this functionality through a new API endpoint. This allows for easier management and debugging of metric data, particularly in environments where metrics need to be reset periodically or on demand.

Highlights

  • Prometheus Metric Reset Functionality: Introduced reset_counters and reset_histograms methods within the PrometheusLogger class, allowing for the programmatic clearing and re-initialization of all registered Prometheus Counter and Histogram metrics.
  • Metric Creation Refactoring: Refactored the PrometheusLogger's __init__ method to use new helper methods, _create_counter and _create_histogram, for registering all metrics. This change centralizes metric creation and enables tracking for subsequent resetting.
  • New API Endpoint for Metrics Reset: Added a new POST endpoint /metrics/reset to the internal API server, which triggers the reset_observability_metrics function to clear all Prometheus metrics.
  • New Metrics and Histogram Bucket Adjustments: Added a new counter for num_unsuccessful_retrieve_requests and new histograms for fs_connector_get_time, nitrofs_connector_read_time, and instrumented_connector_get_time. Existing histogram bucket definitions were also refined for better granularity.

🧠 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
  • lmcache/observability.py
    • Added _create_counter and _create_histogram methods to PrometheusLogger for standardized metric registration.
    • Modified PrometheusLogger.__init__ to utilize the new _create_counter and _create_histogram methods for all Prometheus metrics.
    • Implemented reset_counters and reset_histograms methods in PrometheusLogger to clear and re-initialize metrics.
    • Introduced a new global function reset_observability_metrics to orchestrate the resetting of all Prometheus metrics.
    • Updated type hints to include Sequence for more flexible iterable types.
    • Adjusted bucket definitions for several histograms and introduced short_profiling_buckets and long_profiling_buckets.
    • Added counter_num_unsuccessful_retrieve_requests and new histogram metrics for connector timings.
  • lmcache/v1/internal_api_server/common/metrics_api.py
    • Imported the reset_observability_metrics function.
    • Added a new POST endpoint /metrics/reset to allow external triggers for resetting Prometheus metrics.
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.

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 functionality to reset Prometheus metrics via a new API endpoint, /metrics/reset, and refactors metric creation. However, the new /metrics/reset endpoint lacks authentication or authorization, posing a critical security risk by allowing unauthorized users to clear monitoring data, which could lead to a denial of service. Additionally, two critical bugs causing NameError exceptions were identified, along with a suggestion to remove an unused parameter for improved code quality.

Comment thread lmcache/observability.py Outdated
Comment thread lmcache/v1/internal_api_server/common/metrics_api.py
@maobaolong maobaolong force-pushed the reset_metrics_gh branch 3 times, most recently from 75f545f to e7c84f6 Compare February 14, 2026 07:17
Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
@LMCache LMCache deleted a comment from gemini-code-assist Bot Feb 14, 2026
@maobaolong maobaolong changed the title Reset metrics gh Introduce reset metrics api Feb 14, 2026
@maobaolong
Copy link
Copy Markdown
Collaborator Author

maobaolong commented Feb 15, 2026

.

@maobaolong maobaolong closed this Feb 15, 2026
@maobaolong maobaolong reopened this Feb 15, 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!

@maobaolong
Copy link
Copy Markdown
Collaborator Author

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

@maobaolong maobaolong added the full Run comprehensive tests on this PR label Feb 16, 2026
@maobaolong maobaolong enabled auto-merge (squash) February 16, 2026 10:19
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 6aaeaa4 into LMCache:dev Feb 18, 2026
49 of 50 checks passed
DongDongJu pushed a commit to DongDongJu/LMCache that referenced this pull request Feb 22, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: DongDongJu <commisori28@gmail.com>
DongDongJu pushed a commit to DongDongJu/LMCache that referenced this pull request Feb 22, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
sammshen pushed a commit to sammshen/LMCache that referenced this pull request Mar 1, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
hlin99 pushed a commit to hlin99/LMCache that referenced this pull request Mar 2, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
mauryaavinash95 pushed a commit to mauryaavinash95/LMCache that referenced this pull request Mar 7, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
shaoxiawjc pushed a commit to shaoxiawjc/LMCache that referenced this pull request Mar 11, 2026
Support reset metrics (merge request !31)

Squash merge branch 'reset_metrics' into 'remote-backend-0120'

* Add thread safe annotation
* fix
* Reset histogram type metrics
* Support reset metrics

Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: shaoxiawjc <wjc2800@163.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