Skip to content

Conversation

@renecannao
Copy link
Contributor

@renecannao renecannao commented Feb 9, 2026

This PR extends PR #5069 by adding protocol labels to distinguish MySQL and PostgreSQL prometheus metrics across all modules, and fully enables PostgreSQL metrics export.

Summary

This PR resolves Issue #5068 by adding protocol labels to all MySQL and PostgreSQL prometheus metrics, allowing them to coexist without metric name collisions.

Changes in this PR

This PR builds upon PR #5069 (which only added protocol labels to Host Groups Manager metrics) and extends it to:

1. Thread Handler Metrics

  • Add protocol="mysql" labels to 65 MySQL_Thread.cpp metrics
  • Add protocol="pgsql" labels to 60 PgSQL_Thread.cpp metrics
  • Enable GloPTH (PostgreSQL threads handler) metrics export

2. Query Cache Metrics

  • Create separate qc_metrics_map_mysql and qc_metrics_map_pgsql with protocol labels
  • Use if constexpr (std::is_same_v<QC_DERIVED, MySQL_Query_Cache>) for compile-time map selection
  • Enable GloPgQC (PostgreSQL query cache) metrics export

3. Documentation

  • Add comprehensive documentation in doc/PROMETHEUS_PROTOCOL_LABELS.md

Total Impact

Example Output

After this PR, users will see:

proxysql_client_connections_total{protocol="mysql",status="aborted"} X
proxysql_client_connections_total{protocol="pgsql",status="aborted"} Y

proxysql_query_cache_count_get_total{protocol="mysql",status="ok"} 50000
proxysql_query_cache_count_get_total{protocol="pgsql",status="ok"} 25000

Implementation Details

The Query Cache implementation uses C++17 type traits for zero-overhead compile-time dispatch:

if constexpr (std::is_same_v<QC_DERIVED, MySQL_Query_Cache>) {
    init_prometheus_counter_array(qc_metrics_map_mysql, this->metrics.p_counter_array);
} else {
    init_prometheus_counter_array(qc_metrics_map_pgsql, this->metrics.p_counter_array);
}

Related

Summary by CodeRabbit

Release Notes

  • New Features

    • Added protocol labels to Prometheus metrics to distinguish MySQL and PostgreSQL data, preventing metric collisions
    • Separated metric collections per database backend with protocol-specific labels ("mysql" and "pgsql")
    • Re-enabled PostgreSQL metrics collection with zero runtime overhead
  • Documentation

    • Added guidance on filtering and aggregating metrics by protocol in Prometheus queries

evkuzin and others added 6 commits August 8, 2025 06:10
…plication

add protocol labels for shared metrics between mysql and psql
…etrics

This commit extends PR #5069 by adding protocol labels to distinguish
MySQL and PostgreSQL metrics in the Thread Handler modules.

Changes:
- Add { "protocol", "mysql" } labels to 65 MySQL_Thread.cpp metrics
- Add { "protocol", "pgsql" } labels to 60 PgSQL_Thread.cpp metrics
- Enable GloPTH (PostgreSQL threads handler) metrics export
- Document Query Cache limitation (template base class collision)

This resolves Issue #5068 by ensuring PostgreSQL prometheus metrics
are properly exported with protocol labels, distinguishing them from
MySQL metrics.

Related: #5068, #5069
…etrics

This commit resolves the prometheus metric collision between MySQL and
PostgreSQL Query Cache instances by creating separate metric maps with
protocol labels and using compile-time type trait selection.

Changes:
- Add #include <type_traits> to Query_Cache.cpp
- Create qc_metrics_map_mysql with { "protocol", "mysql" } labels (8 metrics)
- Create qc_metrics_map_pgsql with { "protocol", "pgsql" } labels (8 metrics)
- Modify Query_Cache constructor to use if constexpr with std::is_same_v
  to select the appropriate metrics map based on derived type
- Enable GloPgQC metrics export in update_modules_metrics()

This allows MySQL and PostgreSQL query cache metrics to coexist without
collision, following the same pattern as Thread Handler metrics.

Related: #5068, #5069
Add comprehensive documentation describing the protocol labels feature
introduced in this branch to resolve metric collisions between MySQL and
PostgreSQL prometheus metrics.

Related: #5068, #5069
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

This pull request adds protocol-specific labels to Prometheus metrics across multiple ProxySQL modules, enabling distinction between MySQL and PostgreSQL metrics. A new documentation file explains the enhancement approach. PostgreSQL metrics collection is re-enabled, and the Query Cache module is refactored with separate per-protocol metric maps using compile-time selection.

Changes

Cohort / File(s) Summary
Documentation
doc/PROMETHEUS_PROTOCOL_LABELS.md
New comprehensive guide documenting the protocol-labels enhancement, problem description, solution, code integration examples, and verification steps for distinguishing MySQL and PostgreSQL metrics.
Thread Metrics
lib/MySQL_Thread.cpp, lib/PgSQL_Thread.cpp
Added protocol-specific labels (protocol: mysql and protocol: pgsql respectively) to metric_tags in th_metrics_map, affecting counters and gauges for bytes, query times, connection latencies, and monitor-related metrics.
Host Groups Managers
lib/MySQL_HostGroups_Manager.cpp, lib/PgSQL_HostGroups_Manager.cpp
Added protocol-specific labels to connection-related metrics (server/client connections created, delayed, aborted, denied scenarios) in their respective metric maps.
Query Cache Metrics
lib/Query_Cache.cpp
Introduced separate protocol-specific metric maps (qc_metrics_map_mysql and qc_metrics_map_pgsql), replaced single combined map with compile-time backend selection via if constexpr and type traits, added protocol labels to all metrics.
Metrics Collection
lib/ProxySQL_Admin.cpp
Re-enabled PostgreSQL metrics collection by removing disabled #if 0 block, now unconditionally updates PgHGM and GloPTH metrics via p_update_metrics().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whisker-twitch for protocol tales,
MySQL and Postgres now leave their trails,
With labels so bright, no more metric collisions,
Prometheus cheers at our clear divisions! 🎯✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: adding protocol labels to PostgreSQL metrics and extending Prometheus metrics coverage, which is fully reflected in the changeset.
Linked Issues check ✅ Passed The PR fully addresses Issue #5068 by adding protocol labels to distinguish MySQL and PostgreSQL metrics, preventing name collisions and ensuring correct metric values per protocol.
Out of Scope Changes check ✅ Passed All changes are directly scoped to adding protocol labels to metrics across multiple modules and enabling PostgreSQL metrics export, with no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v3.0-5069

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

Summary of Changes

Hello @renecannao, 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 significantly enhances ProxySQL's Prometheus monitoring capabilities by addressing metric collisions between MySQL and PostgreSQL modules. It introduces a protocol label to differentiate metrics, ensuring accurate and independent monitoring for both database types. Furthermore, it fully enables the export of PostgreSQL Thread Handler and Query Cache metrics, providing comprehensive visibility into PostgreSQL operations within ProxySQL.

Highlights

  • Prometheus Metric Collision Resolution: Resolved Prometheus metric collisions between MySQL and PostgreSQL modules by introducing a protocol label to distinguish metrics from different database sources.
  • Expanded PostgreSQL Metrics Coverage: Fully enabled Prometheus metrics export for PostgreSQL modules, specifically for Thread Handler (GloPTH) and Query Cache (GloPgQC), providing comprehensive visibility into PostgreSQL operations.
  • Compile-Time Metric Map Selection: Implemented zero-overhead compile-time metric map selection in the Query Cache using C++17 if constexpr and std::is_same_v to handle protocol-specific metrics efficiently.
  • Comprehensive Documentation: Added detailed documentation in doc/PROMETHEUS_PROTOCOL_LABELS.md explaining the problem, solution, and impact of the new protocol labels.
  • Label Application Across Modules: Applied protocol="mysql" labels to 65 MySQL Thread Handler metrics and protocol="pgsql" labels to 60 PostgreSQL Thread Handler metrics, as well as to 8 Query Cache metrics and various Host Groups Manager metrics.

🧠 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
  • doc/PROMETHEUS_PROTOCOL_LABELS.md
    • Added new documentation explaining the problem of metric collision, the solution using protocol labels, and detailed changes across modules.
  • lib/MySQL_HostGroups_Manager.cpp
    • Updated metric definitions to include protocol="mysql" labels for server connections, client connections, and access denied metrics.
  • lib/MySQL_Thread.cpp
    • Modified numerous thread handler metrics to include protocol="mysql" labels for bytes transferred, query processing times, statement counts, and various operational counters and gauges.
  • lib/PgSQL_HostGroups_Manager.cpp
    • Updated metric definitions to include protocol="pgsql" labels for server connections, client connections, and access denied metrics.
  • lib/PgSQL_Thread.cpp
    • Modified numerous thread handler metrics to include protocol="pgsql" labels for bytes transferred, query processing times, statement counts, and various operational counters and gauges.
  • lib/ProxySQL_Admin.cpp
    • Enabled the p_update_metrics() calls for PostgreSQL Thread Handler (GloPTH) and PostgreSQL Query Cache (GloPgQC) by removing the conditional compilation (#if 0) that previously disabled them.
  • lib/Query_Cache.cpp
    • Included <type_traits> for compile-time type checking.
    • Defined separate qc_metrics_map_mysql and qc_metrics_map_pgsql with respective protocol labels.
    • Updated the Query_Cache constructor to use if constexpr for compile-time selection of the appropriate metric map.
    • Added protocol labels to query cache metrics.
Activity
  • No specific activity (comments, reviews, progress updates) was provided in the context for this pull request.
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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

Copy link

@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 is a great pull request that effectively resolves the metric collision issue between MySQL and PostgreSQL modules. The addition of protocol labels is a clean solution that follows Prometheus best practices. The use of C++17's if constexpr for compile-time selection in the Query Cache is particularly elegant and efficient. The accompanying documentation is comprehensive and very helpful for understanding the changes.

I have a few minor suggestions to improve code formatting and reduce duplication, but overall, this is a high-quality contribution.


| File | Lines Changed | Description |
|------|--------------|-------------|
| `lib/MySQL_HostGroups_Manager.cpp` | +25/-10 | Added `protocol="mysql"` labels to PgHGM metrics |

Choose a reason for hiding this comment

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

medium

There seems to be a small typo in the table. For the file lib/MySQL_HostGroups_Manager.cpp, the description says "Added protocol="mysql" labels to PgHGM metrics". Since this file is for MySQL, it should probably refer to MyHGM metrics, not PgHGM (PostgreSQL Host Groups Manager) metrics.

Suggested change
| `lib/MySQL_HostGroups_Manager.cpp` | +25/-10 | Added `protocol="mysql"` labels to PgHGM metrics |
| `lib/MySQL_HostGroups_Manager.cpp` | +25/-10 | Added `protocol="mysql"` labels to MyHGM metrics |

Comment on lines +605 to +609
metric_tags {

{ "protocol", "mysql" }

}

Choose a reason for hiding this comment

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

medium

The formatting for metric_tags with only one label seems a bit verbose due to the extra newlines. For better readability and conciseness, consider using a more compact form. This applies to multiple metrics in this file where a single protocol label is added.

metric_tags { { "protocol", "mysql" } }

Comment on lines +531 to +535
metric_tags {

{ "protocol", "pgsql" }

}

Choose a reason for hiding this comment

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

medium

The formatting for metric_tags with only one label seems a bit verbose due to the extra newlines. For better readability and conciseness, consider using a more compact form. This applies to multiple metrics in this file where a single protocol label is added.

metric_tags { { "protocol", "pgsql" } }

Copy link

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
lib/PgSQL_HostGroups_Manager.cpp (2)

3204-3219: ⚠️ Potential issue | 🟠 Major

Pre-existing bug: gauge family arrays are swapped during server removal.

Line 3209 removes a gauge obtained from p_connection_pool_conn_used_map via the connection_pool_conn_free family, and Line 3213 does the reverse. The families should match their respective maps. The MySQL_HostGroups_Manager.cpp variant correctly maps these (conn_free→conn_free, conn_used→conn_used), confirming this is a PgSQL-specific bug.

🐛 Proposed fix
 		gauge = status.p_connection_pool_conn_used_map[key];
-		status.p_dyn_gauge_array[PgSQL_p_hg_dyn_gauge::connection_pool_conn_free]->Remove(gauge);
+		status.p_dyn_gauge_array[PgSQL_p_hg_dyn_gauge::connection_pool_conn_used]->Remove(gauge);
 		status.p_connection_pool_conn_used_map.erase(key);
 
 		gauge = status.p_connection_pool_conn_free_map[key];
-		status.p_dyn_gauge_array[PgSQL_p_hg_dyn_gauge::connection_pool_conn_used]->Remove(gauge);
+		status.p_dyn_gauge_array[PgSQL_p_hg_dyn_gauge::connection_pool_conn_free]->Remove(gauge);
 		status.p_connection_pool_conn_free_map.erase(key);

515-654: ⚠️ Potential issue | 🟠 Major

Fix metric naming errors and add protocol labels to prevent Prometheus collisions.

Three metrics have incorrect names:

  • Line 621: "proxysql_pghgm_myconnpool_get_ping_total" → should be "proxysql_pghgm_pgconnpool_get_ping_total" (myconnpool is a copy-paste error from MySQL).
  • Line 650: "proxysql_myhgm_auto_increment_multiplex_total" → should be "proxysql_pghgm_auto_increment_multiplex_total" (myhgm is the MySQL prefix; should be pghgm).

Additionally, metrics like proxysql_com_rollback_total, proxysql_com_commit_cnt_total, and proxysql_selects_for_update__autocommit0_total use empty metric_tags {}, while MySQL_HostGroups_Manager exports identically-named metrics. These will collide in Prometheus. Add { "protocol", "pgsql" } to these metrics to differentiate them, as seen in other metrics like proxysql_access_denied_wrong_password_total (lines 553–556).

🤖 Fix all issues with AI agents
In `@doc/PROMETHEUS_PROTOCOL_LABELS.md`:
- Around line 38-41: Update the unlabeled fenced code blocks in
PROMETHEUS_PROTOCOL_LABELS.md by changing the opening triple backticks to
include a language identifier (e.g., ```text or ```promql) for the blocks
containing the proxysql_client_connections_total examples; apply this change to
the block shown (around the
proxysql_client_connections_total{protocol="mysql",status="created"} lines) and
the similar block at the later occurrence (around lines 338-343) so markdownlint
MD040 is satisfied.

In `@lib/PgSQL_Thread.cpp`:
- Around line 894-952: The gauge metric names mistakenly use "mysql" while the
protocol label is "pgsql"; update the tuples for
p_th_gauge::mysql_backend_buffers_bytes,
p_th_gauge::mysql_frontend_buffers_bytes,
p_th_gauge::mysql_session_internal_bytes and p_th_gauge::mysql_thread_workers to
use pgsql-appropriate metric names (e.g. change "proxysql_mysql_..." to
"proxysql_pgsql_..." or remove the protocol prefix) and adjust the help text for
p_th_gauge::mysql_thread_workers to refer to "pgsql-threads" instead of
"mysql-threads" so names and descriptions match protocol="pgsql".
- Around line 762-800: The metric name strings for the p_th_counter entries
referencing MySQL are inconsistent with protocol="pgsql"; update the metric
names in the tuples for p_th_counter::mysql_unexpected_frontend_com_quit,
p_th_counter::mysql_unexpected_frontend_packets,
p_th_counter::mysql_whitelisted_sqli_fingerprint,
p_th_counter::mysql_killed_backend_connections and
p_th_counter::mysql_killed_backend_queries to either protocol-agnostic names
(e.g., remove the mysql_ prefix like proxysql_killed_backend_connections_total)
or to pgsql-specific names (e.g.,
proxysql_pgsql_killed_backend_connections_total) so the metric name matches the
protocol tag, and then update any registration/usage/docs that reference the old
names to maintain consistency/backwards-compatibility as needed.
- Around line 618-627: The help text for the metric tuple using
p_th_counter::slow_queries and name "proxysql_slow_queries_total" incorrectly
references "mysql-long_query_time" while the metric is tagged protocol="pgsql";
update the description string to reference the PostgreSQL equivalent (e.g.
"pgsql-long_query_time" or another correct PgSQL config variable) so the help
text matches the p_th_counter::slow_queries metric and metric_tags
protocol="pgsql".
🧹 Nitpick comments (3)
lib/PgSQL_Thread.cpp (1)

628-646: GTID metrics may not apply to PostgreSQL.

proxysql_gtid_consistent_queries_total and proxysql_gtid_session_collected_total are MySQL-specific concepts (Global Transaction ID). Exposing them with protocol="pgsql" will likely always report zero and may confuse PostgreSQL users monitoring via Prometheus.

Consider whether these should be omitted from the PgSQL metrics map rather than being labeled with protocol="pgsql".

lib/Query_Cache.cpp (2)

542-548: Compile-time dispatch is clean, but consider guarding the else branch.

The if constexpr approach for selecting the correct metrics map is appropriate and incurs zero runtime overhead. However, the else branch implicitly assumes PgSQL_Query_Cache. If a third Query_Cache specialization were ever introduced, it would silently use the PgSQL map.

Consider adding a static_assert for safety:

Proposed hardening
 	if constexpr (std::is_same_v<QC_DERIVED, MySQL_Query_Cache>) {
 		init_prometheus_counter_array<qc_metrics_map_idx, p_qc_counter>(qc_metrics_map_mysql, this->metrics.p_counter_array);
 		init_prometheus_gauge_array<qc_metrics_map_idx, p_qc_gauge>(qc_metrics_map_mysql, this->metrics.p_gauge_array);
 	} else {
+		static_assert(std::is_same_v<QC_DERIVED, PgSQL_Query_Cache>, "Unexpected Query_Cache specialization");
 		init_prometheus_counter_array<qc_metrics_map_idx, p_qc_counter>(qc_metrics_map_pgsql, this->metrics.p_counter_array);
 		init_prometheus_gauge_array<qc_metrics_map_idx, p_qc_gauge>(qc_metrics_map_pgsql, this->metrics.p_gauge_array);
 	}

326-498: Near-identical maps could be generated by a helper to reduce duplication.

qc_metrics_map_mysql and qc_metrics_map_pgsql differ only in the protocol tag value. A factory function (e.g., make_qc_metrics_map(const std::string& protocol)) would eliminate ~80 lines of duplication and ensure both maps stay in sync if metric definitions change later.

This is optional given the maps are const and the duplication is purely data definitions.

Comment on lines +38 to +41
```
proxysql_client_connections_total{protocol="mysql",status="created"} 1000
proxysql_client_connections_total{protocol="pgsql",status="created"} 500
```
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add language identifiers to fenced code blocks (MD040).

markdownlint flags the unlabeled fences at Line 38 and Line 338. Mark them as text (or promql) to satisfy linting.

🛠️ Suggested fix
-```
+```text
 proxysql_client_connections_total{protocol="mysql",status="created"} 1000
 proxysql_client_connections_total{protocol="pgsql",status="created"} 500
-```
+```

-```
+```text
 proxysql_client_connections_total{protocol="mysql",status="aborted"} X
 proxysql_client_connections_total{protocol="mysql",status="created"} Y
 proxysql_client_connections_total{protocol="pgsql",status="aborted"} Z
 proxysql_client_connections_total{protocol="pgsql",status="created"} W
-```
+```

Also applies to: 338-343

🧰 Tools
🪛 markdownlint-cli2 (0.20.0)

[warning] 38-38: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
In `@doc/PROMETHEUS_PROTOCOL_LABELS.md` around lines 38 - 41, Update the unlabeled
fenced code blocks in PROMETHEUS_PROTOCOL_LABELS.md by changing the opening
triple backticks to include a language identifier (e.g., ```text or ```promql)
for the blocks containing the proxysql_client_connections_total examples; apply
this change to the block shown (around the
proxysql_client_connections_total{protocol="mysql",status="created"} lines) and
the similar block at the later occurrence (around lines 338-343) so markdownlint
MD040 is satisfied.

Comment on lines 618 to 627
std::make_tuple(
p_th_counter::slow_queries,
"proxysql_slow_queries_total",
"The total number of queries with an execution time greater than \"mysql-long_query_time\" milliseconds.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Help text references MySQL config variable for PgSQL metric.

Line 621: the proxysql_slow_queries_total help string says "mysql-long_query_time" but this metric is tagged protocol="pgsql". The description should reference the PgSQL equivalent variable (e.g., "pgsql-long_query_time") to avoid confusion.

Proposed fix
 	std::make_tuple(
 		p_th_counter::slow_queries,
 		"proxysql_slow_queries_total",
-		"The total number of queries with an execution time greater than \"mysql-long_query_time\" milliseconds.",
+		"The total number of queries with an execution time greater than \"pgsql-long_query_time\" milliseconds.",
 		metric_tags {
 
 			{ "protocol", "pgsql" }
🤖 Prompt for AI Agents
In `@lib/PgSQL_Thread.cpp` around lines 618 - 627, The help text for the metric
tuple using p_th_counter::slow_queries and name "proxysql_slow_queries_total"
incorrectly references "mysql-long_query_time" while the metric is tagged
protocol="pgsql"; update the description string to reference the PostgreSQL
equivalent (e.g. "pgsql-long_query_time" or another correct PgSQL config
variable) so the help text matches the p_th_counter::slow_queries metric and
metric_tags protocol="pgsql".

Comment on lines 762 to +800
std::make_tuple(
p_th_counter::mysql_unexpected_frontend_com_quit,
"proxysql_mysql_unexpected_frontend_com_quit_total",
"Unexpected 'COM_QUIT' received from the client.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_counter::hostgroup_locked_set_cmds,
"proxysql_hostgroup_locked_set_cmds_total",
"Total number of connections that have been locked in a hostgroup.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_counter::hostgroup_locked_queries,
"proxysql_hostgroup_locked_queries_total",
"Query blocked because connection is locked into some hostgroup but is trying to reach other.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_counter::mysql_unexpected_frontend_packets,
"proxysql_mysql_unexpected_frontend_packets_total",
"Unexpected packet received from client.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Several PgSQL metric names embed mysql_, creating a confusing label/name mismatch.

These Prometheus metric names contain mysql_ but carry protocol="pgsql":

  • proxysql_mysql_unexpected_frontend_com_quit_total (line 764)
  • proxysql_mysql_unexpected_frontend_packets_total (line 794)
  • proxysql_mysql_whitelisted_sqli_fingerprint_total (line 824)
  • proxysql_mysql_killed_backend_connections_total (line 834)
  • proxysql_mysql_killed_backend_queries_total (line 844)

Users querying Prometheus will see a metric named proxysql_mysql_killed_backend_connections_total{protocol="pgsql"}, which is contradictory. If preserving backward compatibility for MySQL is required, consider using protocol-agnostic names (e.g., proxysql_killed_backend_connections_total) or protocol-specific names (e.g., proxysql_pgsql_killed_backend_connections_total).

Also applies to: 832-851

🤖 Prompt for AI Agents
In `@lib/PgSQL_Thread.cpp` around lines 762 - 800, The metric name strings for the
p_th_counter entries referencing MySQL are inconsistent with protocol="pgsql";
update the metric names in the tuples for
p_th_counter::mysql_unexpected_frontend_com_quit,
p_th_counter::mysql_unexpected_frontend_packets,
p_th_counter::mysql_whitelisted_sqli_fingerprint,
p_th_counter::mysql_killed_backend_connections and
p_th_counter::mysql_killed_backend_queries to either protocol-agnostic names
(e.g., remove the mysql_ prefix like proxysql_killed_backend_connections_total)
or to pgsql-specific names (e.g.,
proxysql_pgsql_killed_backend_connections_total) so the metric name matches the
protocol tag, and then update any registration/usage/docs that reference the old
names to maintain consistency/backwards-compatibility as needed.

Comment on lines 894 to +952
std::make_tuple(
p_th_gauge::mysql_backend_buffers_bytes,
"proxysql_mysql_backend_buffers_bytes",
"Buffers related to backend connections if \"fast_forward\" is used (0 means fast_forward is not used).",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_gauge::mysql_frontend_buffers_bytes,
"proxysql_mysql_frontend_buffers_bytes",
"Buffers related to frontend connections (read/write buffers and other queues).",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_gauge::mysql_session_internal_bytes,
"proxysql_mysql_session_internal_bytes",
"Other memory used by ProxySQL to handle MySQL Sessions.",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_gauge::mirror_concurrency,
"proxysql_mirror_concurrency",
"Mirror current concurrency",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_gauge::mirror_queue_lengths,
"proxysql_mirror_queue_lengths",
"Mirror queue length",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
),
std::make_tuple(
p_th_gauge::mysql_thread_workers,
"proxysql_mysql_thread_workers",
"Number of MySQL Thread workers i.e. 'mysql-threads'",
metric_tags {}
metric_tags {

{ "protocol", "pgsql" }

}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Gauge metric names also embed mysql_ for PgSQL protocol.

Similarly to the counters above, several gauge metrics use mysql_-prefixed names with protocol="pgsql":

  • proxysql_mysql_backend_buffers_bytes (line 896)
  • proxysql_mysql_frontend_buffers_bytes (line 906)
  • proxysql_mysql_session_internal_bytes (line 916)
  • proxysql_mysql_thread_workers (line 946, help also says "mysql-threads")

Same concern applies — these names will be confusing in dashboards when paired with the protocol="pgsql" label.

🤖 Prompt for AI Agents
In `@lib/PgSQL_Thread.cpp` around lines 894 - 952, The gauge metric names
mistakenly use "mysql" while the protocol label is "pgsql"; update the tuples
for p_th_gauge::mysql_backend_buffers_bytes,
p_th_gauge::mysql_frontend_buffers_bytes,
p_th_gauge::mysql_session_internal_bytes and p_th_gauge::mysql_thread_workers to
use pgsql-appropriate metric names (e.g. change "proxysql_mysql_..." to
"proxysql_pgsql_..." or remove the protocol prefix) and adjust the help text for
p_th_gauge::mysql_thread_workers to refer to "pgsql-threads" instead of
"mysql-threads" so names and descriptions match protocol="pgsql".

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.

incorrect metric in prometheus exporter

2 participants