Documentation ¶
Overview ¶
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. NOTE: many changes have been made to the original code for our use-case.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. NOTE: many changes have been made to the original code for our use-case.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. NOTE: many changes have been made to the original code for our use-case.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. NOTE: many changes have been made to the original code for our use-case.
This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. NOTE: many changes have been made to the original code for our use-case.
Index ¶
- Variables
- func MarshalConfig(c *Config, scrubSecrets bool) ([]byte, error)
- func MarshalConfigToWriter(c *Config, w io.Writer, scrubSecrets bool) error
- type BasicManager
- func (m *BasicManager) ApplyConfig(c Config) error
- func (m *BasicManager) DeleteConfig(name string) error
- func (m *BasicManager) GetInstance(name string) (ManagedInstance, error)
- func (m *BasicManager) InstanceReady(name string) bool
- func (m *BasicManager) ListConfigs() map[string]Config
- func (m *BasicManager) ListInstances() map[string]ManagedInstance
- func (m *BasicManager) Ready() bool
- func (m *BasicManager) Stop()
- func (m *BasicManager) UpdateManagerConfig(c BasicManagerConfig)
- type BasicManagerConfig
- type Config
- type ErrInvalidUpdate
- type Factory
- type Instance
- func (i *Instance) Appender(ctx context.Context) storage.Appender
- func (i *Instance) Ready() bool
- func (i *Instance) Run(ctx context.Context) error
- func (i *Instance) Stop() error
- func (i *Instance) Storage() storage.Storage
- func (i *Instance) StorageDirectory() string
- func (i *Instance) Tenant() string
- func (i *Instance) Update(c Config) (err error)
- type ManagedInstance
- type Manager
- type MetricValueCollector
- type Metrics
- type MockManager
- func (m MockManager) ApplyConfig(c Config) error
- func (m MockManager) DeleteConfig(name string) error
- func (m MockManager) GetInstance(name string) (ManagedInstance, error)
- func (m MockManager) InstanceReady(name string) bool
- func (m MockManager) ListConfigs() map[string]Config
- func (m MockManager) ListInstances() map[string]ManagedInstance
- func (m MockManager) Ready() bool
- func (m MockManager) Stop()
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultBasicManagerConfig is the default config for the BasicManager. DefaultBasicManagerConfig = BasicManagerConfig{ InstanceRestartBackoff: 5 * time.Second, } )
var ( DefaultConfig = Config{ Dir: "ruler-wal", TruncateFrequency: 60 * time.Minute, MinAge: 5 * time.Minute, MaxAge: 4 * time.Hour, RemoteFlushDeadline: 1 * time.Minute, } )
Default configuration values
Functions ¶
func MarshalConfig ¶
MarshalConfig marshals an instance config based on a provided content type.
Types ¶
type BasicManager ¶
type BasicManager struct {
// contains filtered or unexported fields
}
BasicManager creates a new BasicManager, implementing the Manager interface. BasicManager will directly launch instances and perform no extra processing.
Other implementations of Manager usually wrap a BasicManager.
func NewBasicManager ¶
func NewBasicManager(cfg BasicManagerConfig, metrics *Metrics, logger log.Logger, launch Factory) *BasicManager
NewBasicManager creates a new BasicManager. The launch function will be invoked any time a new Config is applied.
The lifecycle of any ManagedInstance returned by the launch function will be handled by the BasicManager. Instances will be automatically restarted if stopped, updated if the config changes, or removed when the Config is deleted.
func (*BasicManager) ApplyConfig ¶
func (m *BasicManager) ApplyConfig(c Config) error
ApplyConfig takes a Config and either starts a new managed instance or updates an existing managed instance. The value for Name in c is used to uniquely identify the Config and determine whether the Config has an existing associated managed instance.
func (*BasicManager) DeleteConfig ¶
func (m *BasicManager) DeleteConfig(name string) error
DeleteConfig removes a managed instance by its config name. Returns an error if there is no such managed instance with the given name.
func (*BasicManager) GetInstance ¶
func (m *BasicManager) GetInstance(name string) (ManagedInstance, error)
GetInstance returns the given instance by name.
func (*BasicManager) InstanceReady ¶
func (m *BasicManager) InstanceReady(name string) bool
InstanceReady indicates if an instance is ready for processing.
func (*BasicManager) ListConfigs ¶
func (m *BasicManager) ListConfigs() map[string]Config
ListConfigs lists the current active configs managed by BasicManager.
func (*BasicManager) ListInstances ¶
func (m *BasicManager) ListInstances() map[string]ManagedInstance
ListInstances returns the current active instances managed by BasicManager.
func (*BasicManager) Ready ¶
func (m *BasicManager) Ready() bool
Ready indicates if all instances are ready for processing.
func (*BasicManager) Stop ¶
func (m *BasicManager) Stop()
Stop stops the BasicManager and stops all active processes for configs.
func (*BasicManager) UpdateManagerConfig ¶
func (m *BasicManager) UpdateManagerConfig(c BasicManagerConfig)
UpdateManagerConfig updates the BasicManagerConfig.
type BasicManagerConfig ¶
BasicManagerConfig controls the operations of a BasicManager.
type Config ¶
type Config struct { Tenant string Name string RemoteWrite []*config.RemoteWriteConfig Dir string `yaml:"dir"` // How frequently the WAL should be truncated. TruncateFrequency time.Duration `yaml:"truncate_frequency,omitempty"` // Minimum and maximum time series should exist in the WAL for. MinAge time.Duration `yaml:"min_age,omitempty"` MaxAge time.Duration `yaml:"max_age,omitempty"` RemoteFlushDeadline time.Duration `yaml:"remote_flush_deadline,omitempty"` }
Config is a specific agent that runs within the overall Prometheus agent. It has its own set of scrape_configs and remote_write rules.
func UnmarshalConfig ¶
UnmarshalConfig unmarshals an instance config from a reader based on a provided content type.
func (*Config) ApplyDefaults ¶
ApplyDefaults applies default configurations to the configuration to all values that have not been changed to their non-zero value. ApplyDefaults also validates the config.
The value for global will saved.
func (Config) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Config) RegisterFlags ¶
func (*Config) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type ErrInvalidUpdate ¶
type ErrInvalidUpdate struct {
Inner error
}
ErrInvalidUpdate is returned whenever Update is called against an instance but an invalid field is changed between configs. If ErrInvalidUpdate is returned, the instance must be fully stopped and replaced with a new one with the new config.
func (ErrInvalidUpdate) As ¶
func (e ErrInvalidUpdate) As(err interface{}) bool
As will set the err object to ErrInvalidUpdate provided err is a pointer to ErrInvalidUpdate.
func (ErrInvalidUpdate) Error ¶
func (e ErrInvalidUpdate) Error() string
Error implements the error interface.
func (ErrInvalidUpdate) Is ¶
func (e ErrInvalidUpdate) Is(err error) bool
Is returns true if err is an ErrInvalidUpdate.
type Factory ¶
type Factory func(c Config) (ManagedInstance, error)
Factory should return an unstarted instance given some config.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is an individual metrics collector and remote_writer.
func New ¶
func New(reg prometheus.Registerer, cfg Config, metrics *wal.Metrics, logger log.Logger) (*Instance, error)
New creates a new Instance with a directory for storing the WAL. The instance will not start until Run is called on the instance.
func (*Instance) Run ¶
Run starts the instance, initializing Prometheus components, and will continue to run until an error happens during execution or the provided context is cancelled.
Run may be re-called after exiting, as components will be reinitialized each time Run is called.
func (*Instance) StorageDirectory ¶
StorageDirectory returns the directory where this Instance is writing series and samples to for the WAL.
type ManagedInstance ¶
type ManagedInstance interface { Ready() bool Run(ctx context.Context) error Update(c Config) error StorageDirectory() string Appender(ctx context.Context) storage.Appender Stop() error Tenant() string }
ManagedInstance is implemented by Instance. It is defined as an interface for the sake of testing from Manager implementations.
type Manager ¶
type Manager interface { // GetInstance retrieves a ManagedInstance by name. GetInstance(name string) (ManagedInstance, error) // ListInstances returns all currently managed instances running // within the Manager. The key will be the instance name from their config. ListInstances() map[string]ManagedInstance // ListConfigs returns the config objects associated with a managed // instance. The key will be the Name field from Config. ListConfigs() map[string]Config // ApplyConfig creates a new Config or updates an existing Config if // one with Config.Name already exists. ApplyConfig(Config) error // DeleteConfig deletes a given managed instance based on its Config.Name. DeleteConfig(name string) error // Ready indicates if all instances are ready for processing. Ready() bool // InstanceReady indicates if an instance is ready for processing. InstanceReady(name string) bool // Stop stops the Manager and all managed instances. Stop() }
Manager represents a set of methods for manipulating running instances at runtime.
type MetricValueCollector ¶
type MetricValueCollector struct {
// contains filtered or unexported fields
}
MetricValueCollector wraps around a Gatherer and provides utilities for pulling metric values from a given metric name and label matchers.
This is used by the agent instances to find the most recent timestamp successfully remote_written to for purposes of safely truncating the WAL.
MetricValueCollector is only intended for use with Gauges and Counters.
func NewMetricValueCollector ¶
func NewMetricValueCollector(g prometheus.Gatherer, match string) *MetricValueCollector
NewMetricValueCollector creates a new MetricValueCollector.
type Metrics ¶
type Metrics struct { AbnormalExits *prometheus.CounterVec RunningInstances prometheus.Gauge // contains filtered or unexported fields }
func NewMetrics ¶
func NewMetrics(r prometheus.Registerer) *Metrics
type MockManager ¶
type MockManager struct { GetInstanceFunc func(name string) (ManagedInstance, error) ListInstancesFunc func() map[string]ManagedInstance ListConfigsFunc func() map[string]Config ApplyConfigFunc func(Config) error DeleteConfigFunc func(name string) error StopFunc func() }
MockManager exposes methods of the Manager interface as struct fields. Useful for tests.
func (MockManager) ApplyConfig ¶
func (m MockManager) ApplyConfig(c Config) error
ApplyConfig implements Manager.
func (MockManager) DeleteConfig ¶
func (m MockManager) DeleteConfig(name string) error
DeleteConfig implements Manager.
func (MockManager) GetInstance ¶
func (m MockManager) GetInstance(name string) (ManagedInstance, error)
GetInstance implements Manager.
func (MockManager) InstanceReady ¶
func (m MockManager) InstanceReady(name string) bool
func (MockManager) ListConfigs ¶
func (m MockManager) ListConfigs() map[string]Config
ListConfigs implements Manager.
func (MockManager) ListInstances ¶
func (m MockManager) ListInstances() map[string]ManagedInstance
ListInstances implements Manager.
func (MockManager) Ready ¶
func (m MockManager) Ready() bool