checks

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetry = helper.RetryConfig{
	Count: 3,
	Delay: time.Second,
}

DefaultRetry provides a default configuration for the retry mechanism

Functions

func OpenapiFromPerfData

func OpenapiFromPerfData[T any](data T) (*openapi3.SchemaRef, error)

OpenapiFromPerfData takes in check perfdata and returns an openapi3.SchemaRef of a result wrapping the perfData this is a workaround, since the openapi3gen.NewSchemaRefForValue function does not work with any types

Types

type Check

type Check interface {
	// Run is called once, to start running the check. The check should
	// run until the context is canceled and handle problems itself.
	// Returning a non-nil error will cause the shutdown of the check.
	Run(ctx context.Context, cResult chan ResultDTO) error
	// Shutdown is called once when the check is unregistered or sparrow shuts down
	Shutdown()
	// SetConfig is called once when the check is registered
	// This is also called while the check is running, if the remote config is updated
	// This should return an error if the config is invalid
	SetConfig(config Runtime) error
	// GetConfig returns the current configuration of the check
	GetConfig() Runtime
	// Name returns the name of the check
	Name() string
	// Schema returns an openapi3.SchemaRef of the result type returned by the check
	Schema() (*openapi3.SchemaRef, error)
	// GetMetricCollectors allows the check to provide prometheus metric collectors
	GetMetricCollectors() []prometheus.Collector
}

Check implementations are expected to perform specific monitoring tasks and report results.

type CheckBase added in v0.3.1

type CheckBase struct {
	// Mutex for thread-safe access to shared resources within the check implementation
	Mu sync.Mutex
	// Signal channel used to notify about shutdown of a check
	DoneChan chan struct{}
}

CheckBase is a struct providing common fields used by implementations of the Check interface. It serves as a foundational structure that should be embedded in specific check implementations.

type CheckMock added in v0.1.2

type CheckMock struct {
	// GetConfigFunc mocks the GetConfig method.
	GetConfigFunc func() Runtime

	// GetMetricCollectorsFunc mocks the GetMetricCollectors method.
	GetMetricCollectorsFunc func() []prometheus.Collector

	// NameFunc mocks the Name method.
	NameFunc func() string

	// RunFunc mocks the Run method.
	RunFunc func(ctx context.Context, cResult chan ResultDTO) error

	// SchemaFunc mocks the Schema method.
	SchemaFunc func() (*openapi3.SchemaRef, error)

	// SetConfigFunc mocks the SetConfig method.
	SetConfigFunc func(config Runtime) error

	// ShutdownFunc mocks the Shutdown method.
	ShutdownFunc func()
	// contains filtered or unexported fields
}

CheckMock is a mock implementation of Check.

func TestSomethingThatUsesCheck(t *testing.T) {

	// make and configure a mocked Check
	mockedCheck := &CheckMock{
		GetConfigFunc: func() Runtime {
			panic("mock out the GetConfig method")
		},
		GetMetricCollectorsFunc: func() []prometheus.Collector {
			panic("mock out the GetMetricCollectors method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		RunFunc: func(ctx context.Context, cResult chan ResultDTO) error {
			panic("mock out the Run method")
		},
		SchemaFunc: func() (*openapi3.SchemaRef, error) {
			panic("mock out the Schema method")
		},
		SetConfigFunc: func(config Runtime) error {
			panic("mock out the SetConfig method")
		},
		ShutdownFunc: func()  {
			panic("mock out the Shutdown method")
		},
	}

	// use mockedCheck in code that requires Check
	// and then make assertions.

}

func (*CheckMock) GetConfig added in v0.3.1

func (mock *CheckMock) GetConfig() Runtime

GetConfig calls GetConfigFunc.

func (*CheckMock) GetConfigCalls added in v0.3.1

func (mock *CheckMock) GetConfigCalls() []struct {
}

GetConfigCalls gets all the calls that were made to GetConfig. Check the length with:

len(mockedCheck.GetConfigCalls())

func (*CheckMock) GetMetricCollectors added in v0.1.2

func (mock *CheckMock) GetMetricCollectors() []prometheus.Collector

GetMetricCollectors calls GetMetricCollectorsFunc.

func (*CheckMock) GetMetricCollectorsCalls added in v0.1.2

func (mock *CheckMock) GetMetricCollectorsCalls() []struct {
}

GetMetricCollectorsCalls gets all the calls that were made to GetMetricCollectors. Check the length with:

len(mockedCheck.GetMetricCollectorsCalls())

func (*CheckMock) Name added in v0.3.1

func (mock *CheckMock) Name() string

Name calls NameFunc.

func (*CheckMock) NameCalls added in v0.3.1

func (mock *CheckMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedCheck.NameCalls())

func (*CheckMock) Run added in v0.1.2

func (mock *CheckMock) Run(ctx context.Context, cResult chan ResultDTO) error

Run calls RunFunc.

func (*CheckMock) RunCalls added in v0.1.2

func (mock *CheckMock) RunCalls() []struct {
	Ctx     context.Context
	CResult chan ResultDTO
}

RunCalls gets all the calls that were made to Run. Check the length with:

len(mockedCheck.RunCalls())

func (*CheckMock) Schema added in v0.1.2

func (mock *CheckMock) Schema() (*openapi3.SchemaRef, error)

Schema calls SchemaFunc.

func (*CheckMock) SchemaCalls added in v0.1.2

func (mock *CheckMock) SchemaCalls() []struct {
}

SchemaCalls gets all the calls that were made to Schema. Check the length with:

len(mockedCheck.SchemaCalls())

func (*CheckMock) SetConfig added in v0.1.2

func (mock *CheckMock) SetConfig(config Runtime) error

SetConfig calls SetConfigFunc.

func (*CheckMock) SetConfigCalls added in v0.1.2

func (mock *CheckMock) SetConfigCalls() []struct {
	Config Runtime
}

SetConfigCalls gets all the calls that were made to SetConfig. Check the length with:

len(mockedCheck.SetConfigCalls())

func (*CheckMock) Shutdown added in v0.1.2

func (mock *CheckMock) Shutdown()

Shutdown calls ShutdownFunc.

func (*CheckMock) ShutdownCalls added in v0.1.2

func (mock *CheckMock) ShutdownCalls() []struct {
}

ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:

len(mockedCheck.ShutdownCalls())

type ErrConfigMismatch added in v0.3.1

type ErrConfigMismatch struct {
	Expected string
	Current  string
}

ErrConfigMismatch is returned when a configuration is of the wrong type

func (ErrConfigMismatch) Error added in v0.3.1

func (e ErrConfigMismatch) Error() string

type ErrInvalidConfig

type ErrInvalidConfig struct {
	CheckName string
	Field     string
	Reason    string
}

ErrInvalidConfig is returned when a configuration is invalid

func (ErrInvalidConfig) Error added in v0.3.1

func (e ErrInvalidConfig) Error() string

type GlobalTarget added in v0.2.0

type GlobalTarget struct {
	Url      string    `json:"url"`
	LastSeen time.Time `json:"lastSeen"`
}

GlobalTarget includes the basic information regarding other Sparrow instances, which this Sparrow can communicate with.

type Result

type Result struct {
	// Data contains performance metrics about the check run
	Data any `json:"data"`
	// Timestamp is the UTC time the check was run
	Timestamp time.Time `json:"timestamp"`
}

Result encapsulates the outcome of a check run.

type ResultDTO

type ResultDTO struct {
	Name   string
	Result *Result
}

ResultDTO is a data transfer object used to associate a check's name with its result.

type Runtime added in v0.3.1

type Runtime interface {
	// For returns the name of the check being configured
	For() string
	// Validate checks if the configuration is valid
	Validate() error
}

Runtime is the interface that all check configurations must implement

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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