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

Prometheus label values are not escaped correctly #9648

Closed
tvhong-amazon opened this issue Oct 5, 2023 · 0 comments · Fixed by #9656
Closed

Prometheus label values are not escaped correctly #9648

tvhong-amazon opened this issue Oct 5, 2023 · 0 comments · Fixed by #9656
Labels

Comments

@tvhong-amazon
Copy link
Contributor

tvhong-amazon commented Oct 5, 2023

Describe the bug

Hi,
While testing the Prometheus metrics, I noticed that the metric labels are not escaped correctly.

Example ra_metrics for 2 quorum queues:

  • "qq on the default vhost
  • queue \qq on the vhost "myvhost:
# TYPE rabbitmq_detailed_raft_log_commit_index gauge
# HELP rabbitmq_detailed_raft_log_commit_index Raft log commit index
rabbitmq_detailed_raft_log_commit_index{vhost=""myvhost",queue="\qq"} 2
rabbitmq_detailed_raft_log_commit_index 8
rabbitmq_detailed_raft_log_commit_index{vhost="/",queue=""qq"} 2
rabbitmq_detailed_raft_log_commit_index 10
# TYPE rabbitmq_detailed_raft_log_last_written_index gauge
# HELP rabbitmq_detailed_raft_log_last_written_index Raft log last written index
rabbitmq_detailed_raft_log_last_written_index{vhost=""myvhost",queue="\qq"} 2
rabbitmq_detailed_raft_log_last_written_index 8
rabbitmq_detailed_raft_log_last_written_index{vhost="/",queue=""qq"} 2
rabbitmq_detailed_raft_log_last_written_index 10

Reproduction steps

  1. Start a RabbitMQ node locally.
  2. Create a quorum queue with name "qq.
  3. (Optional) Create a new vhost "myvhost and add a quorum queue named \qq.
  4. Access metrics endpoint: http://localhost:15692/metrics/detailed?family=ra_metrics .
  5. Observe that the queue labels are not escaped correctly.

Expected behavior

Label values are escaped correctly as per Prometheus Exposition Format.

label_value can be any sequence of UTF-8 characters, but the backslash (\), double-quote ("), and line feed (\n) characters have to be escaped as \\, \", and \n, respectively.

For example:

rabbitmq_detailed_raft_log_commit_index{vhost="\"myvhost",queue="\\qq"} 2
rabbitmq_detailed_raft_log_commit_index{vhost="/",queue="\"qq"} 2

Additional context

I took a quick look at the dependent prometheus.erl library. Looks like it escapes the label values. Not sure why RabbitMQ doesn't.

https://github.com/deadtrickster/prometheus.erl/blob/b78e17eda43c7fcb2c05f76c7dd80db969cd8479/src/formats/prometheus_text_format.erl#L238-L245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant