You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-05 00:28:58 +02:00
Update module github.com/prometheus/common to v0.62.0 and fix tests (#6198)
Supersedes https://github.com/open-telemetry/opentelemetry-go/pull/6171 The update to prometheus/common changes the default escaping scheme to NoEscaping. Use of underscores vs original UTF-8 is still determined by content negotiation.
This commit is contained in:
@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/sdk/log`. (#6193)
|
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/sdk/log`. (#6193)
|
||||||
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`. (#6193)
|
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`. (#6193)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Update `github.com/prometheus/common` to v0.62.0., which changes the `NameValidationScheme` to `NoEscaping`. This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores. This is controlled by the `Content-Type` header, or can be reverted by setting `NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6198)
|
||||||
|
|
||||||
<!-- Released section -->
|
<!-- Released section -->
|
||||||
<!-- Don't change this section unless doing release -->
|
<!-- Don't change this section unless doing release -->
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantConfig: config{
|
wantConfig: config{
|
||||||
registerer: prometheus.DefaultRegisterer,
|
registerer: prometheus.DefaultRegisterer,
|
||||||
namespace: "test_",
|
namespace: "test/_",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ type collector struct {
|
|||||||
|
|
||||||
// prometheus counters MUST have a _total suffix by default:
|
// prometheus counters MUST have a _total suffix by default:
|
||||||
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/compatibility/prometheus_and_openmetrics.md
|
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/compatibility/prometheus_and_openmetrics.md
|
||||||
const counterSuffix = "_total"
|
const counterSuffix = "total"
|
||||||
|
|
||||||
// New returns a Prometheus Exporter.
|
// New returns a Prometheus Exporter.
|
||||||
func New(opts ...Option) (*Exporter, error) {
|
func New(opts ...Option) (*Exporter, error) {
|
||||||
@ -368,38 +368,38 @@ func createScopeInfoMetric(scope instrumentation.Scope) (prometheus.Metric, erro
|
|||||||
|
|
||||||
var unitSuffixes = map[string]string{
|
var unitSuffixes = map[string]string{
|
||||||
// Time
|
// Time
|
||||||
"d": "_days",
|
"d": "days",
|
||||||
"h": "_hours",
|
"h": "hours",
|
||||||
"min": "_minutes",
|
"min": "minutes",
|
||||||
"s": "_seconds",
|
"s": "seconds",
|
||||||
"ms": "_milliseconds",
|
"ms": "milliseconds",
|
||||||
"us": "_microseconds",
|
"us": "microseconds",
|
||||||
"ns": "_nanoseconds",
|
"ns": "nanoseconds",
|
||||||
|
|
||||||
// Bytes
|
// Bytes
|
||||||
"By": "_bytes",
|
"By": "bytes",
|
||||||
"KiBy": "_kibibytes",
|
"KiBy": "kibibytes",
|
||||||
"MiBy": "_mebibytes",
|
"MiBy": "mebibytes",
|
||||||
"GiBy": "_gibibytes",
|
"GiBy": "gibibytes",
|
||||||
"TiBy": "_tibibytes",
|
"TiBy": "tibibytes",
|
||||||
"KBy": "_kilobytes",
|
"KBy": "kilobytes",
|
||||||
"MBy": "_megabytes",
|
"MBy": "megabytes",
|
||||||
"GBy": "_gigabytes",
|
"GBy": "gigabytes",
|
||||||
"TBy": "_terabytes",
|
"TBy": "terabytes",
|
||||||
|
|
||||||
// SI
|
// SI
|
||||||
"m": "_meters",
|
"m": "meters",
|
||||||
"V": "_volts",
|
"V": "volts",
|
||||||
"A": "_amperes",
|
"A": "amperes",
|
||||||
"J": "_joules",
|
"J": "joules",
|
||||||
"W": "_watts",
|
"W": "watts",
|
||||||
"g": "_grams",
|
"g": "grams",
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
"Cel": "_celsius",
|
"Cel": "celsius",
|
||||||
"Hz": "_hertz",
|
"Hz": "hertz",
|
||||||
"1": "_ratio",
|
"1": "ratio",
|
||||||
"%": "_percent",
|
"%": "percent",
|
||||||
}
|
}
|
||||||
|
|
||||||
// getName returns the sanitized name, prefixed with the namespace and suffixed with unit.
|
// getName returns the sanitized name, prefixed with the namespace and suffixed with unit.
|
||||||
@ -414,19 +414,31 @@ func (c *collector) getName(m metricdata.Metrics, typ *dto.MetricType) string {
|
|||||||
// Remove the _total suffix here, as we will re-add the total suffix
|
// Remove the _total suffix here, as we will re-add the total suffix
|
||||||
// later, and it needs to come after the unit suffix.
|
// later, and it needs to come after the unit suffix.
|
||||||
name = strings.TrimSuffix(name, counterSuffix)
|
name = strings.TrimSuffix(name, counterSuffix)
|
||||||
|
// If the last character is an underscore, or would be converted to an underscore, trim it from the name.
|
||||||
|
// an underscore will be added back in later.
|
||||||
|
if convertsToUnderscore(rune(name[len(name)-1])) {
|
||||||
|
name = name[:len(name)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if c.namespace != "" {
|
if c.namespace != "" {
|
||||||
name = c.namespace + name
|
name = c.namespace + name
|
||||||
}
|
}
|
||||||
if suffix, ok := unitSuffixes[m.Unit]; ok && !c.withoutUnits && !strings.HasSuffix(name, suffix) {
|
if suffix, ok := unitSuffixes[m.Unit]; ok && !c.withoutUnits && !strings.HasSuffix(name, suffix) {
|
||||||
name += suffix
|
name += "_" + suffix
|
||||||
}
|
}
|
||||||
if addCounterSuffix {
|
if addCounterSuffix {
|
||||||
name += counterSuffix
|
name += "_" + counterSuffix
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertsToUnderscore returns true if the character would be converted to an
|
||||||
|
// underscore when the escaping scheme is underscore escaping. This is meant to
|
||||||
|
// capture any character that should be considered a "delimiter".
|
||||||
|
func convertsToUnderscore(b rune) bool {
|
||||||
|
return !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == ':' || (b >= '0' && b <= '9'))
|
||||||
|
}
|
||||||
|
|
||||||
func (c *collector) metricType(m metricdata.Metrics) *dto.MetricType {
|
func (c *collector) metricType(m metricdata.Metrics) *dto.MetricType {
|
||||||
switch v := m.Data.(type) {
|
switch v := m.Data.(type) {
|
||||||
case metricdata.Histogram[int64], metricdata.Histogram[float64]:
|
case metricdata.Histogram[int64], metricdata.Histogram[float64]:
|
||||||
|
@ -35,7 +35,7 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
recordMetrics func(ctx context.Context, meter otelmetric.Meter)
|
recordMetrics func(ctx context.Context, meter otelmetric.Meter)
|
||||||
options []Option
|
options []Option
|
||||||
expectedFile string
|
expectedFile string
|
||||||
enableUTF8 bool
|
disableUTF8 bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "counter",
|
name: "counter",
|
||||||
@ -195,6 +195,7 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "sanitized attributes to labels",
|
name: "sanitized attributes to labels",
|
||||||
expectedFile: "testdata/sanitized_labels.txt",
|
expectedFile: "testdata/sanitized_labels.txt",
|
||||||
|
disableUTF8: true,
|
||||||
options: []Option{WithoutUnits()},
|
options: []Option{WithoutUnits()},
|
||||||
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
|
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
|
||||||
opt := otelmetric.WithAttributes(
|
opt := otelmetric.WithAttributes(
|
||||||
@ -404,7 +405,6 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "counter utf-8",
|
name: "counter utf-8",
|
||||||
expectedFile: "testdata/counter_utf8.txt",
|
expectedFile: "testdata/counter_utf8.txt",
|
||||||
enableUTF8: true,
|
|
||||||
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
|
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
|
||||||
opt := otelmetric.WithAttributes(
|
opt := otelmetric.WithAttributes(
|
||||||
attribute.Key("A.G").String("B"),
|
attribute.Key("A.G").String("B"),
|
||||||
@ -471,11 +471,11 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if tc.enableUTF8 {
|
if tc.disableUTF8 {
|
||||||
model.NameValidationScheme = model.UTF8Validation
|
model.NameValidationScheme = model.LegacyValidation
|
||||||
defer func() {
|
defer func() {
|
||||||
// Reset to defaults
|
// Reset to defaults
|
||||||
model.NameValidationScheme = model.LegacyValidation
|
model.NameValidationScheme = model.UTF8Validation
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -5,7 +5,7 @@ go 1.22.0
|
|||||||
require (
|
require (
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
github.com/prometheus/client_model v0.6.1
|
github.com/prometheus/client_model v0.6.1
|
||||||
github.com/prometheus/common v0.61.0
|
github.com/prometheus/common v0.62.0
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
go.opentelemetry.io/otel v1.34.0
|
go.opentelemetry.io/otel v1.34.0
|
||||||
go.opentelemetry.io/otel/metric v1.34.0
|
go.opentelemetry.io/otel/metric v1.34.0
|
||||||
|
@ -29,8 +29,8 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+
|
|||||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ=
|
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
|
||||||
github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s=
|
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
@ -147,7 +147,7 @@ require (
|
|||||||
github.com/polyfloyd/go-errorlint v1.7.0 // indirect
|
github.com/polyfloyd/go-errorlint v1.7.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.61.0 // indirect
|
github.com/prometheus/common v0.62.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect
|
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect
|
||||||
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
|
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
|
||||||
|
@ -347,8 +347,8 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+
|
|||||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ=
|
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
|
||||||
github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s=
|
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 h1:+Wl/0aFp0hpuHM3H//KMft64WQ1yX9LdJY64Qm/gFCo=
|
github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 h1:+Wl/0aFp0hpuHM3H//KMft64WQ1yX9LdJY64Qm/gFCo=
|
||||||
|
Reference in New Issue
Block a user