Skip to content

[skip-ci] fix: TSDB metric collection & config load from disk#5426

Merged
renecannao merged 2 commits into
v3.0from
tsdb-metric-update-fix
Feb 27, 2026
Merged

[skip-ci] fix: TSDB metric collection & config load from disk#5426
renecannao merged 2 commits into
v3.0from
tsdb-metric-update-fix

Conversation

@wazir-ahmed

@wazir-ahmed wazir-ahmed commented Feb 26, 2026

Copy link
Copy Markdown
Member
  • tsdb_sampler_loop() calls registry->Collect() without refreshing module metrics, causing stale metric values to be stored in the TSDB. Added update_modules_metrics() call before Collect() in the sampler.

  • TSDB variables stored on disk were not being loaded into runtime during startup. Added the missing flush_tsdb_variables___database_to_runtime() and invoke it during init.

Summary by CodeRabbit

  • New Features

    • Prometheus metrics are now automatically refreshed before collection.
  • Refactor

    • TSDB variable initialization refactored to use unified synchronization approach.
    • TSDB variable handling consolidated for improved consistency across startup sequences.

- `tsdb_sampler_loop()` calls `registry->Collect()` without refreshing
  module metrics, causing stale metric values to be stored in the TSDB.
- Added `update_modules_metrics()` call before `Collect()` in the sampler.

Signed-off-by: Wazir Ahmed <wazir@proxysql.com>
- TSDB variables stored on disk were not being loaded into runtime during
  startup. Add the missing `flush_tsdb_variables___database_to_runtime()`
  and invoke it during init.

- Inline the existing load/save wrappers in the header as thin delegations
  to the underlying flush functions

Signed-off-by: Wazir Ahmed <wazir@proxysql.com>
@coderabbitai

coderabbitai Bot commented Feb 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tsdb-metric-update-fix

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @wazir-ahmed, 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 resolves two key issues within ProxySQL's Time Series Database (TSDB) functionality. It guarantees the accuracy of collected metrics by ensuring all module metrics are updated prior to TSDB collection. Furthermore, it rectifies a problem where TSDB-related configuration variables stored on disk were not being loaded into the runtime during initialization, thereby ensuring proper application and persistence of these settings across restarts.

Highlights

  • TSDB Metric Freshness: Ensured that Prometheus module metrics are refreshed immediately before collection in the TSDB sampler loop, preventing stale data from being stored.
  • TSDB Variable Persistence: Implemented the loading of TSDB configuration variables from disk into the runtime environment during application startup, addressing an oversight where these settings were not being applied.

🧠 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
  • include/proxysql_admin.h
    • Declared a new function update_modules_metrics() for refreshing Prometheus metrics.
    • Refactored load_tsdb_variables_to_runtime() and save_tsdb_variables_from_runtime() to use generic flush functions, simplifying their implementation.
  • lib/Admin_Bootstrap.cpp
    • Added a call to flush_tsdb_variables___database_to_runtime() to ensure TSDB variables are loaded during the admin initialization process.
  • lib/Admin_FlushVariables.cpp
    • Extended the generic variable flushing mechanism to correctly handle tsdb module variables for both setting and getting.
    • Implemented the flush_tsdb_variables___database_to_runtime() function to manage loading TSDB variables from the database.
  • lib/ProxySQL_Admin.cpp
    • Removed the explicit implementations of load_tsdb_variables_to_runtime() and save_tsdb_variables_from_runtime(), as their logic is now handled by the refactored generic flush functions and inline definitions.
  • lib/ProxySQL_Statistics.cpp
    • Inserted a call to update_modules_metrics() within the tsdb_sampler_loop() to ensure all module metrics are current before Prometheus collection.
Activity
  • No human activity has been recorded on this pull request yet.
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.

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

Copy link
Copy Markdown

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 addresses two issues with the TSDB functionality. First, it ensures that metrics are refreshed before collection in the TSDB sampler loop by adding a call to update_modules_metrics(), preventing stale data from being stored. Second, it fixes a bug where TSDB configuration variables were not loaded from disk on startup by adding the necessary flush_tsdb_variables___database_to_runtime() call during initialization. The changes also include a refactoring of TSDB variable handling to use generic flushing functions, which improves code consistency and maintainability. The fixes appear correct and well-implemented.

@sonarqubecloud

Copy link
Copy Markdown

@wazir-ahmed
wazir-ahmed changed the base branch from v3.0-unified-large-pr to v3.0 February 27, 2026 11:37
@renecannao
renecannao merged commit 5b721a6 into v3.0 Feb 27, 2026
12 of 15 checks passed
@renecannao
renecannao deleted the tsdb-metric-update-fix branch March 7, 2026 20:40
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