Page MenuHomePhabricator

Invalid UTF-8 string handling in metrics.go
Closed, ResolvedPublic1 Estimated Story Points

Description

Requests with invalid utf-8 can cause panic in the prometheus metrics.go library

goroutine 24 [running]:
github.com/prometheus/client_golang/prometheus.(*GaugeVec).WithLabelValues(...)
	/go/pkg/mod/github.com/prometheus/client_golang@v1.17.0/prometheus/gauge.go:238
wikimedia-enterprise/api/main/submodules/httputil.(*MetricsRecorder).Serve.func1()
	/app/submodules/httputil/metrics.go:233 +0x539
created by wikimedia-enterprise/api/main/submodules/httputil.(*MetricsRecorder).Serve in goroutine 45
	/app/submodules/httputil/metrics.go:229 +0x26
  1. Replace gcx.Request.URL.Path with gcx.FullPath() that is not prone to invalid utf-8 issues and will ease the high cardinality problem since the path labels will have
path="/v2/structured-contents/*name"
  1. Remove the gcx.ClientIP() and usr.GetUsername() from the labels completely as they are the cause of high cardinality.

Event Timeline

RThomas-WMF raised the priority of this task from High to Needs Triage.
RThomas-WMF renamed this task from Invalid UTF-8 string in the API requests causes Panic to Invalid UTF-8 string handling in metrics.go.Jun 26 2025, 1:34 PM
RThomas-WMF set the point value for this task to 2.Jun 27 2025, 3:37 AM
RThomas-WMF triaged this task as High priority.
RThomas-WMF added a subscriber: SGupta-WMF.
RThomas-WMF changed the task status from Open to In Progress.Jul 2 2025, 7:15 AM
RThomas-WMF claimed this task.
RThomas-WMF changed the point value for this task from 2 to 1.