profilingcfg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package profilingcfg selects and builds a profiling.Provider from configuration: Grafana Pyroscope, the Go-native pprof HTTP server, or no profiling at all.

One of the four pillar config packages, so it has no WithPillars option — observability imports it to build a Pillars.

It supplies Pyroscope's upload rate default, which is unusual: defaults normally live with the config they belong to, and this one lives here because pyroscope.Config has no defaults of its own to apply it alongside. Like every default in this module it is applied before validation, so an unset rate is a configured deployment rather than a rejected one.

Index

Constants

View Source
const (
	// ProviderPyroscope represents Grafana Pyroscope.
	ProviderPyroscope = "pyroscope"
	// ProviderPprof represents Go-native pprof HTTP server.
	ProviderPprof = "pprof"
	// ProviderNoop, and the empty string, select no profiling at all. That is the
	// deliberate opt-out and stays supported; what is no longer supported is a
	// provider name this package does not recognize, which used to disable
	// profiling silently and looked exactly like the opt-out.
	ProviderNoop = "noop"
)

Variables

This section is empty.

Functions

func NewProfilingProvider

func NewProfilingProvider(ctx context.Context, c *Config, opts ...Option) (profiling.Provider, error)

NewProfilingProvider provides a profiling.Provider from a config.

func RegisterProfilingProvider

func RegisterProfilingProvider(i do.Injector)

RegisterProfilingProvider registers a profiling.Provider with the injector.

The logger is looked up optionally rather than through do.MustInvoke: a container that registers no logger still gets a profiler, which just says nothing about how it was started.

Types

type Config

type Config struct {
	Pyroscope   *pyroscope.Config `env:",init"        envPrefix:"PYROSCOPE_"       json:"pyroscope,omitempty"   yaml:"pyroscope,omitempty"`
	Pprof       *pprof.Config     `env:",init"        envPrefix:"PPROF_"           json:"pprof,omitempty"       yaml:"pprof,omitempty"`
	ServiceName string            `env:"SERVICE_NAME" json:"serviceName,omitempty" yaml:"serviceName,omitempty"`
	Provider    string            `env:"PROVIDER"     json:"provider,omitempty"    yaml:"provider,omitempty"`
	// contains filtered or unexported fields
}

Config contains settings related to profiling.

func (*Config) EnsureDefaults

func (c *Config) EnsureDefaults()

EnsureDefaults fills in the fields this package supplies a default for.

The upload rate used to be defaulted inside NewProfilingProvider, after the point where a validation call would have run, so pyroscope's own Required rule and the constructor disagreed about whether an unset rate was a configuration or a mistake. Defaults belong before validation, which is what this is for.

func (*Config) NewProfilingProvider

func (c *Config) NewProfilingProvider(ctx context.Context, opts ...Option) (profiling.Provider, error)

NewProfilingProvider provides a profiling provider based on config.

Each provider is built into a variable and returned only once its error is known to be nil. The provider constructors return their own concrete types, so returning one straight through would convert a nil *pyroscope.Provider into a non-nil profiling.Provider on the error path, and a caller testing the result against nil would find a provider that panics on first use.

func (*Config) ValidateWithContext

func (c *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates the config struct.

type Option

type Option func(*options)

Option configures how NewProfilingProvider assembles its provider.

The logger is an option rather than a parameter because it is genuinely optional: an absent logger logs nowhere. Requiring it positionally made a caller that wanted no logging name one anyway, usually a noop.

There is no WithPillars here, and there cannot be: the observability package that defines Pillars imports this one in order to build them. A pillar's own constructor is what a Pillars gets assembled from, so it takes the one dependency that precedes it and nothing else.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger. An absent logger logs nowhere.

Jump to

Keyboard shortcuts

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