Skip to content

Conversation

iypetrov
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

  • Use hist.GetMetricWithLabelValues instead of hist.WithLabelValues to avoid the panic 'Label value is not valid UTF-8' and receive instead of that empty counter/gauge/timer/histogram.

How was this change tested?

  • Four new tests were added to ensure the system remains stable when it receives an invalid label.

Checklist

@iypetrov iypetrov requested a review from a team as a code owner May 15, 2025 14:35
@iypetrov iypetrov requested a review from mahadzaryab1 May 15, 2025 14:35
@dosubot dosubot bot added the bug label May 15, 2025
@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch from a3dcfd5 to df9e1db Compare May 15, 2025 14:39
@yurishkuro yurishkuro requested a review from Copilot May 15, 2025 23:15
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR resolves issue #2944 by replacing calls to WithLabelValues with GetMetricWithLabelValues to avoid a panic when receiving invalid UTF-8 label values. It also adds test cases to verify that counters, gauges, timers, and histograms return their corresponding null metrics when encountering these invalid labels.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/metrics/prometheus/factory_test.go Adds tests to ensure invalid UTF-8 labels result in null metrics.
internal/metrics/prometheus/factory.go Replaces WithLabelValues with GetMetricWithLabelValues and adds logging for error cases.

@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch 2 times, most recently from 8956652 to 26d5f0a Compare May 16, 2025 05:07
Copy link

codecov bot commented May 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.20%. Comparing base (bfa0b2c) to head (24af996).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7128      +/-   ##
==========================================
- Coverage   96.20%   96.20%   -0.01%     
==========================================
  Files         362      363       +1     
  Lines       21853    21877      +24     
==========================================
+ Hits        21024    21046      +22     
- Misses        620      621       +1     
- Partials      209      210       +1     
Flag Coverage Δ
badger_v1 9.86% <0.00%> (-0.01%) ⬇️
badger_v2 1.90% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v1-manual 14.84% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v2-auto 1.89% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v2-manual 1.89% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v1-manual 14.84% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v2-auto 1.89% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v2-manual 1.89% <0.00%> (-0.01%) ⬇️
elasticsearch-6.x-v1 20.68% <0.00%> (-0.01%) ⬇️
elasticsearch-7.x-v1 20.76% <0.00%> (-0.01%) ⬇️
elasticsearch-8.x-v1 20.94% <0.00%> (-0.01%) ⬇️
elasticsearch-8.x-v2 1.90% <0.00%> (-0.01%) ⬇️
grpc_v1 11.40% <0.00%> (-0.01%) ⬇️
grpc_v2 1.90% <0.00%> (-0.01%) ⬇️
kafka-3.x-v1 10.14% <0.00%> (-0.01%) ⬇️
kafka-3.x-v2 1.90% <0.00%> (-0.01%) ⬇️
memory_v2 1.90% <0.00%> (-0.01%) ⬇️
opensearch-1.x-v1 20.81% <0.00%> (-0.01%) ⬇️
opensearch-2.x-v1 20.81% <0.00%> (-0.01%) ⬇️
opensearch-2.x-v2 1.90% <0.00%> (-0.01%) ⬇️
query 1.90% <0.00%> (-0.01%) ⬇️
tailsampling-processor 0.51% <0.00%> (-0.01%) ⬇️
unittests 95.02% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch from d396b9f to eaef979 Compare May 19, 2025 03:59
@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch 3 times, most recently from 180487d to 01e949c Compare May 21, 2025 13:46
@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch from 7c2ab64 to 02f2274 Compare May 22, 2025 04:15
github-merge-queue bot pushed a commit that referenced this pull request May 25, 2025
## Which problem is this PR solving?
- The need for "sanitizer" concept some up in other scenarios, e.g.
#7128, but currently it was hidden under jaeger binary internal.

## Description of the changes
- Move it instead to internal/jptrace/sanitizer, which is a reasonably
logical place considering that it affects the data model

## How was this change tested?
- CI

---------

Signed-off-by: Yuri Shkuro <github@ysh.us>
iypetrov added 8 commits May 26, 2025 23:49
…ometheus library

Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
… temporary variable, because it is used 2 times

Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
… ones

Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
@iypetrov iypetrov force-pushed the fix-prometheus-label-value-is-not-valid-utf-8-cause-api-timeout branch from feb7d25 to 0a64ce6 Compare May 26, 2025 20:49
…ackage

Signed-off-by: Ilia Petrov <ilia.yavorov.petrov@gmail.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
@yurishkuro yurishkuro enabled auto-merge May 26, 2025 21:55
@yurishkuro yurishkuro added this pull request to the merge queue May 26, 2025
Merged via the queue into jaegertracing:main with commit 137dfcb May 26, 2025
59 checks passed
This was referenced Jul 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 25, 2025
## Which problem is this PR solving?
- Resolves part of #7261 

## Description of the changes
- Files identified by deadcode tool: `internal/jptrace/utf8.go` -
`SanitizeUTF8` function unreachable
- When introduced: PR #7128
- When unused: the pr that introduced it never actually used the
function
- The fix was implemented by switching from `WithLabelValues()` to
`GetMetricWithLabelValues()` in the prometheus factory, the
`SanitizeUTF8` function was added but never used.
- Files to remove:
  - `internal/jptrace/utf8.go`
  - `internal/jptrace/utf8_test.go`

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `npm run lint` and `npm run test`

Signed-off-by: Parship Chowdhury <i.am.parship@gmail.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus 'Label value is not valid UTF-8' cause API timeout
2 participants