Skip to content

Change process_runtime_heap_alloc_bytes metric to include memory ballast size #8342

@mx-psi

Description

@mx-psi

The process/runtime/heap_alloc_bytes/process_runtime_heap_alloc_bytes metric is defined as

Bytes of allocated heap objects (see 'go doc runtime.MemStats.HeapAlloc')

but, since #45, the actual value is runtime.MemStats.HeapAlloc minus the memory ballast size if the memory_ballast extension is being used:

func (pm *processMetrics) readMemStatsIfNeeded() {
now := time.Now()
// If last time we read was less than one second ago just reuse the values
if now.Sub(pm.lastMsRead) < time.Second {
return
}
pm.lastMsRead = now
runtime.ReadMemStats(pm.ms)
if pm.ballastSizeBytes > 0 {
pm.ms.Alloc -= pm.ballastSizeBytes
pm.ms.HeapAlloc -= pm.ballastSizeBytes

This delays the process metrics initialization until extensions are running:

if err = proctelemetry.RegisterProcessMetrics(srv.telemetryInitializer.ocRegistry, srv.telemetryInitializer.mp, obsreportconfig.UseOtelForInternalMetricsfeatureGate.IsEnabled(), getBallastSize(srv.host)); err != nil {

We should remove this special case and change the metric to report the raw value of runtime.MemStats.HeapAlloc instead, which will simplify both the metric's semantics as well as the implementation of telemetry initialization. If we keep using the memory ballast extension (see the separate issue #8343 for discussion on this, which may happen after this change), we can add a metric to the memory_ballast extension to indicate the memory ballast size and be able to recover the previous value reported by this metric.

If we find out it is not desirable to just report runtime.MemStats.HeapAlloc, we should instead change the metric description to state that the memory ballast value is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    collector-telemetryhealthchecker and other telemetry collection issuesenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions