1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

sdk/metric: use runtime.GOMAXPROCS(0) instead of runtime.NumCPU() in DefaultExemplarReservoirProviderSelector for the FixedSizeReservoirProvider default size (#7094)

This PR changes `DefaultExemplarReservoirProviderSelector` in
`go.opentelemetry.io/otel/sdk/metric` to use `runtime.GOMAXPROCS(0)`
instead of `runtime.NumCPU()` for the `FixedSizeReservoirProvider`
default size.

**Motivation**

The [runtime.NumCPU](https://pkg.go.dev/runtime#NumCPU) returns the
number of logical CPUs usable by the current process. In Kubernetes, the
method will return the total number of cores on the node, not the actual
number of cores available to the container. Since it is common practice
to allocate only a small fraction of the total CPU on a node to a
container, the current implementation may result in an excessive
`FixedSizeReservoir` size, which in turn negatively impacts the
resources consumed.

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
This commit is contained in:
Lev Zakharov
2025-07-29 18:13:21 +03:00
committed by GitHub
parent 2c57091e58
commit 9bf6470d8e
2 changed files with 6 additions and 3 deletions

View File

@@ -53,6 +53,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Change `AssertEqual` in `go.opentelemetry.io/otel/log/logtest` to accept `TestingT` in order to support benchmarks and fuzz tests. (#6908)
- Change `SDKProcessorLogQueueCapacity`, `SDKProcessorLogQueueSize`, `SDKProcessorSpanQueueSize`, and `SDKProcessorSpanQueueCapacity` in `go.opentelemetry.io/otel/semconv/v1.36.0/otelconv` to use a `Int64ObservableUpDownCounter`. (#7041)
- Change `DefaultExemplarReservoirProviderSelector` in `go.opentelemetry.io/otel/sdk/metric` to use `runtime.GOMAXPROCS(0)` instead of `runtime.NumCPU()` for the `FixedSizeReservoirProvider` default size. (#7094)
<!-- Released section -->
<!-- Don't change this section unless doing release -->

View File

@@ -66,9 +66,11 @@ func DefaultExemplarReservoirProviderSelector(agg Aggregation) exemplar.Reservoi
// provided, the default size MAY be the number of possible
// concurrent threads (e.g. number of CPUs) to help reduce
// contention. Otherwise, a default size of 1 SHOULD be used.
n = max(runtime.NumCPU(),
// Should never be the case, but be defensive.
1)
//
// Use runtime.GOMAXPROCS instead of runtime.NumCPU to support
// containerized environments that may have less than the total number
// of logical CPUs available on the local machine allocated to it.
n = max(runtime.GOMAXPROCS(0), 1)
}
return exemplar.FixedSizeReservoirProvider(n)