Help us shape the future of Go! Take the 2026 Go Developer Survey

processlabels

package
v0.51.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package processlabels resolves the label set parca-agent attaches to a process and renders it as OTel semantic-convention resource attributes.

It is shared by the profile reporter and GPU metrics so that a process's profiles and its GPU metrics carry the same identity: the same metadata providers, the same optional relabel config, and the same rendering as typed resource attributes.

Index

Constants

View Source
const (
	AttrServiceName    = "service.name"
	AttrProcessPID     = "process.pid"
	AttrProcessExePath = "process.executable.path"
	AttrProcessExeName = "process.executable.name"
	AttrContainerID    = "container.id"
	AttrHostName       = "host.name"
	AttrK8sNodeName    = "k8s.node.name"

	// SchemaURL declares which convention version the keys above follow. It
	// matches what upstream's OTLP reporter stamps, and is spelled out for the
	// same reason the keys are.
	SchemaURL = "https://opentelemetry.io/schemas/1.37.0"
)

Resource attribute keys. They are spelled out rather than pulled from semconv, where a module bump could rename one silently.

Variables

This section is empty.

Functions

func DefaultProviders

func DefaultProviders(ctx context.Context, nodeName, agentRevision string,
	executables *lru.SyncedLRU[libpf.FileID, metadata.ExecInfo], cfg metadata.Config,
) ([]metadata.MetadataProvider, error)

DefaultProviders returns parca-agent's metadata provider chain. executables is the profiler's executable-metadata cache; pass nil outside the profiler, which leaves out the main-executable provider. LocalOnly replaces Kubernetes and runtime discovery with a host-only container ID lookup. Providers emit semconv keys directly when configured for OTLP.

func PutHostAttributes

func PutHostAttributes(attrs pcommon.Map, nodeName string, inKubernetes bool)

PutHostAttributes sets the attributes identifying the node: host.name, and k8s.node.name on a cluster, where --node must match the Kubernetes node name and so holds for every process here, pod or not.

func PutProcessAttributes

func PutProcessAttributes(attrs pcommon.Map, p Process, nodeName string, inKubernetes bool)

PutProcessAttributes sets p's resource attributes: the standard process identity first, so a consumer that only speaks semconv still gets it, then the host attributes, then p's labels, so relabel rules and external labels keep the names operators configured. Labels with a semconv equivalent are renamed, unless a relabel rule already set that key itself: the explicit rule wins. The process's own OTEL_RESOURCE_ATTRIBUTES come last and only fill keys nothing else set, so a process can add service.namespace or deployment.environment.name but cannot claim another host or container.

func ServiceName

func ServiceName(apmName string, comm libpf.Comm, execPath libpf.String, d Declared) string

ServiceName picks the service.name for a process. Consumers key resource identity on it, and apmName is set only for instrumented processes, so a system profiler needs the fallbacks or nearly every resource is anonymous.

The process context comes first: an OTel SDK publishes the resource the application configured, usually in code rather than in the environment, and can update it during the process's life, so it is the authoritative source. For a process that publishes none, the profiler derives the context from the environment, which then gives the same name as the environment itself.

The environment outranks comm because comm is the *thread* name: it comes from bpf_get_current_comm(), so a process that names its threads reports one resource per thread pool rather than one per service. A JVM fragments into "G1 Refine#0", "ForkJoinPool.co" and twenty others; OTEL_SERVICE_NAME collapses those back into the one service the operator actually named.

comm still outranks the executable's basename because it is what top and ps show, and because a basename collapses every interpreted service into "python3". The kernel truncates comm to 15 characters, which is only cosmetic.

Types

type Attribute

type Attribute struct {
	Key, Value string
}

Attribute is one resource attribute.

func DeclaredAttributes

func DeclaredAttributes(d Declared) []Attribute

DeclaredAttributes returns the attributes a process declared for itself other than service.name, which ServiceName resolves: those in its process context, then those in OTEL_RESOURCE_ATTRIBUTES for keys the context does not set. The result is deterministic: the context in key order, then the environment in the variable's order.

func ResourceAttributesFromEnv

func ResourceAttributesFromEnv(envVars map[libpf.String]libpf.String) []Attribute

ResourceAttributesFromEnv returns the attributes in the process's OTEL_RESOURCE_ATTRIBUTES other than service.name, which ServiceName resolves. The result is in the variable's order, so equal environments give equal slices.

type Config

type Config struct {
	CacheSize      uint32
	LabelTTL       time.Duration
	NodeName       string
	RelabelConfigs []*relabel.Config
	Providers      []metadata.MetadataProvider
}

Config configures a Resolver.

type Declared

type Declared struct {
	// Context are the resource attributes the profiler resolved for the
	// process: its OTEP 4719 process context if it publishes one, otherwise
	// the profiler's reading of the same OTel environment variables as Env.
	Context attribute.Set
	// Env are the process's OTel environment variables.
	Env map[libpf.String]libpf.String
}

Declared is what a process declared about itself, as the profiler captured it.

type Process

type Process struct {
	Labels labels.Labels

	PID            int64
	ExecutablePath string
	ContainerID    string
	ServiceName    string

	// EnvAttributes are the attributes the process declared for itself; see
	// DeclaredAttributes.
	EnvAttributes []Attribute
}

Process is what PutProcessAttributes renders: a process's resolved labels plus the identity fields that don't come from labels.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver produces per-process label sets: the node label, the metadata providers' output, relabel-config processing, then deletion of the __meta_* discovery labels. Results are cached per PID for the label TTL so long-lived processes still pick up metadata changes.

func New

func New(cfg Config) (*Resolver, error)

New builds a Resolver.

func (*Resolver) Fork

func (r *Resolver) Fork() (*Resolver, error)

Fork returns a Resolver with r's providers and relabel rules but a cache of its own, for a caller whose seed differs from r's: the cache is per PID, so sharing it would let one caller's seed leak into the other's results.

func (*Resolver) RelabelConfigs

func (r *Resolver) RelabelConfigs() []*relabel.Config

RelabelConfigs returns the relabel rules the Resolver applies.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, pid libpf.PID, seed func(*labels.Builder)) Result

Resolve returns pid's labels. seed, if non-nil, sets labels before the providers run, so relabel rules can see them; since the result is cached per PID, seed must depend only on the process, not on the call.

type Result

type Result struct {
	Labels labels.Labels
	Keep   bool
}

Result is a process's label set after relabelling. Keep is false when a relabel rule dropped the process, in which case nothing about it should be reported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL