check

package
v0.0.0-...-065eb90 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 67

README

package check

This package is responsible of defining the types representing an agent check along with an interface implemented by the code responsible to create a check instance based on an existing configuration.

Check Loaders

Loaders implement the CheckLoader interface, they are responsible to instantiate one object of type check.Check for every configuration instance within a integration.Config object. A Loader usually invokes the Configure method on check objects passing in the configuration instance in YAML format: how to use it, it's up to the check itself.

Usage example:

// given a list of configurations, try to load corresponding checks using different loaders
checks := []check.Check{}
for _, conf := range configs {
  for _, loader := range loaders {
    res, err := loader.Load(conf)
    if err == nil {
      checks = append(checks, res...)
    }
  }
}
// `checks` contains one check per configuration instance found.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipCheckInstance = errors.New("refused to load the check instance")

ErrSkipCheckInstance is returned from Configure() when a check is intentionally refusing to load a check instance, and NOT due to an error. The distinction is important for deciding whether or not to log the error and report it on the status page.

Loaders should check for this error after calling Configure() and should not log it as an error. The scheduler reports this error to the agent status if and only if all loaders fail to load the check instance.

Usage example: one version of the check is written in Python, and another is written in Golang. Each loader is called on the given configuration, and will reject the configuration if it does not match the right version, without raising errors to the log or agent status. If another error is returned then the errors will be properly logged and reported in the agent status.

Functions

func CollectDefaultMetrics

func CollectDefaultMetrics(c integration.Config) bool

CollectDefaultMetrics returns if the config is for a JMX check which has collect_default_metrics: true

func GetInventoryChecksContext

func GetInventoryChecksContext() (inventorychecks.Component, error)

GetInventoryChecksContext returns a reference to the inventorychecks component for Python and Go checks to use.

func GetMetadata

func GetMetadata(c Info, includeConfig bool) map[string]interface{}

GetMetadata returns information about a specific check instances. If 'includeConfig' it true, the instance configuration will be scrubbed and included in the returned map

func InitializeInventoryChecksContext

func InitializeInventoryChecksContext(ic inventorychecks.Component)

InitializeInventoryChecksContext set the reference to inventorychecks in checkContext

func IsJMXConfig

func IsJMXConfig(config integration.Config) bool

IsJMXConfig checks if a certain YAML config contains at least one instance of a JMX config

func IsJMXInstance

func IsJMXInstance(name string, instance integration.Data, initConfig integration.Data) bool

IsJMXInstance checks if a certain YAML instance is a JMX config

func ReleaseContext

func ReleaseContext()

ReleaseContext reset to nil all the references hold by the current context

func Retry

func Retry(retryDuration time.Duration, retries int, callback func() error, friendlyName string) (err error)

Retry retries a callback up to `retries`-times in a `retryDuration` period of time, and bails out if the limit is reached.

Types

type Check

type Check interface {
	// Run runs the check
	Run() error
	// Stop stops the check if it's running
	Stop()
	// Cancel cancels the check. Cancel is called when the check is unscheduled:
	// - unlike Stop, it is called even if the check is not running when it's unscheduled
	// - if the check is running, Cancel is called after Stop and may be called before the call to Stop completes
	Cancel()
	// String provides a printable version of the check name
	String() string
	// Configure configures the check
	Configure(senderManger sender.SenderManager, integrationConfigDigest uint64, config, initConfig integration.Data, source string) error
	// Interval returns the interval time for the check
	Interval() time.Duration
	// ID provides a unique identifier for every check instance
	ID() checkid.ID
	// GetWarnings returns the last warning registered by the check
	GetWarnings() []error
	// GetSenderStats returns the stats from the last run of the check.
	GetSenderStats() (stats.SenderStats, error)
	// Version returns the version of the check if available
	Version() string
	// ConfigSource returns the configuration source of the check
	ConfigSource() string
	// IsTelemetryEnabled returns if telemetry is enabled for this check
	IsTelemetryEnabled() bool
	// InitConfig returns the init_config configuration of the check
	InitConfig() string
	// InstanceConfig returns the instance configuration of the check
	InstanceConfig() string
	// GetDiagnoses returns the diagnoses cached in last run or diagnose explicitly
	GetDiagnoses() ([]diagnosis.Diagnosis, error)
}

Check is an interface for types capable to run checks

type Info

type Info interface {
	// String provides a printable version of the check name
	String() string
	// Interval returns the interval time for the check
	Interval() time.Duration
	// ID provides a unique identifier for every check instance
	ID() checkid.ID
	// Version returns the version of the check if available
	Version() string
	// ConfigSource returns the configuration source of the check
	ConfigSource() string
	// InitConfig returns the init_config configuration of the check
	InitConfig() string
	// InstanceConfig returns the instance configuration of the check
	InstanceConfig() string
}

Info is an interface to pull information from types capable to run checks. This is a subsection from the Check interface with only read only method.

type Loader

type Loader interface {
	Name() string
	Load(senderManager sender.SenderManager, config integration.Config, instance integration.Data) (Check, error)
}

Loader is the interface wrapping the operations to load a check from different sources, like Python modules or Go objects.

A single check is loaded for the given `instance` YAML.

type MockInfo

type MockInfo struct {
	Name         string
	CheckID      checkid.ID
	Source       string
	InitConf     string
	InstanceConf string
}

MockInfo is a mock for test using check.Info interface

func (MockInfo) ConfigSource

func (m MockInfo) ConfigSource() string

ConfigSource returns the source of the check

func (MockInfo) ID

func (m MockInfo) ID() checkid.ID

ID returns the ID of the check

func (MockInfo) InitConfig

func (m MockInfo) InitConfig() string

InitConfig returns the init_config of the check

func (MockInfo) InstanceConfig

func (m MockInfo) InstanceConfig() string

InstanceConfig returns the instance config of the check

func (MockInfo) Interval

func (m MockInfo) Interval() time.Duration

Interval returns 0 always

func (MockInfo) String

func (m MockInfo) String() string

String returns the name of the check

func (MockInfo) Version

func (m MockInfo) Version() string

Version returns an empty string

type RetryableError

type RetryableError struct {
	Err error
}

RetryableError is the error type that Retry interprets as a request to retry the callback

func (RetryableError) Error

func (e RetryableError) Error() string

Directories

Path Synopsis
defaults module

Jump to

Keyboard shortcuts

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