Documentation
¶
Index ¶
- Variables
- func OpenapiFromPerfData[T any](data T) (*openapi3.SchemaRef, error)
- type Check
- type CheckMock
- func (mock *CheckMock) DeregisterHandler(ctx context.Context, router *api.RoutingTree)
- func (mock *CheckMock) DeregisterHandlerCalls() []struct{ ... }
- func (mock *CheckMock) GetMetricCollectors() []prometheus.Collector
- func (mock *CheckMock) GetMetricCollectorsCalls() []struct{}
- func (mock *CheckMock) RegisterHandler(ctx context.Context, router *api.RoutingTree)
- func (mock *CheckMock) RegisterHandlerCalls() []struct{ ... }
- func (mock *CheckMock) Run(ctx context.Context) error
- func (mock *CheckMock) RunCalls() []struct{ ... }
- func (mock *CheckMock) Schema() (*openapi3.SchemaRef, error)
- func (mock *CheckMock) SchemaCalls() []struct{}
- func (mock *CheckMock) SetClient(c *http.Client)
- func (mock *CheckMock) SetClientCalls() []struct{ ... }
- func (mock *CheckMock) SetConfig(ctx context.Context, config any) error
- func (mock *CheckMock) SetConfigCalls() []struct{ ... }
- func (mock *CheckMock) Shutdown(ctx context.Context) error
- func (mock *CheckMock) ShutdownCalls() []struct{ ... }
- func (mock *CheckMock) Startup(ctx context.Context, cResult chan<- Result) error
- func (mock *CheckMock) StartupCalls() []struct{ ... }
- type Health
- func (h *Health) DeregisterHandler(_ context.Context, router *api.RoutingTree)
- func (h *Health) GetMetricCollectors() []prometheus.Collector
- func (h *Health) RegisterHandler(ctx context.Context, router *api.RoutingTree)
- func (h *Health) Run(ctx context.Context) error
- func (h *Health) Schema() (*openapi3.SchemaRef, error)
- func (h *Health) SetClient(_ *http.Client)
- func (h *Health) SetConfig(_ context.Context, config any) error
- func (h *Health) Shutdown(_ context.Context) error
- func (h *Health) Startup(_ context.Context, cResult chan<- Result) error
- type HealthConfig
- type Latency
- func (l *Latency) DeregisterHandler(_ context.Context, router *api.RoutingTree)
- func (h *Latency) GetMetricCollectors() []prometheus.Collector
- func (l *Latency) Handler(w http.ResponseWriter, _ *http.Request)
- func (l *Latency) RegisterHandler(_ context.Context, router *api.RoutingTree)
- func (l *Latency) Run(ctx context.Context) error
- func (l *Latency) Schema() (*openapi3.SchemaRef, error)
- func (l *Latency) SetClient(c *http.Client)
- func (l *Latency) SetConfig(_ context.Context, config any) error
- func (l *Latency) Shutdown(_ context.Context) error
- func (l *Latency) Startup(ctx context.Context, cResult chan<- Result) error
- type LatencyConfig
- type LatencyResult
- type Result
- type ResultDTO
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidConfig = errors.New("invalid config")
var RegisteredChecks = map[string]func() Check{ "health": NewHealthCheck, "latency": NewLatencyCheck, }
RegisteredChecks will be registered in this map The key is the name of the Check The name needs to map the configuration item key
Functions ¶
Types ¶
type Check ¶
type Check interface { // Run is called once per check interval // this should error if there is a problem running the check // Returns an error and a result. Returning a non nil error will cause a shutdown of the system Run(ctx context.Context) error // Startup is called once when the check is registered // In the Run() method, the check should send results to the cResult channel // this will cause sparrow to update its data store with the results Startup(ctx context.Context, cResult chan<- Result) error // Shutdown is called once when the check is unregistered or sparrow shuts down Shutdown(ctx context.Context) error // 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(ctx context.Context, config any) error // SetClient sets an HTTP client for the check. This method is used to configure // the check with a specific HTTP client, which can be used for network requests // during the check's execution SetClient(c *http.Client) // Schema returns an openapi3.SchemaRef of the result type returned by the check Schema() (*openapi3.SchemaRef, error) // RegisterHandler Allows the check to register a handler on sparrows http server at runtime RegisterHandler(ctx context.Context, router *api.RoutingTree) // DeregisterHandler allows the check to deregister a handler on sparrows http server at runtime DeregisterHandler(ctx context.Context, router *api.RoutingTree) // GetMetricCollectors allows the check to provide prometheus metric collectors GetMetricCollectors() []prometheus.Collector }
func NewLatencyCheck ¶
func NewLatencyCheck() Check
type CheckMock ¶ added in v0.1.2
type CheckMock struct { // DeregisterHandlerFunc mocks the DeregisterHandler method. DeregisterHandlerFunc func(ctx context.Context, router *api.RoutingTree) // GetMetricCollectorsFunc mocks the GetMetricCollectors method. GetMetricCollectorsFunc func() []prometheus.Collector // RegisterHandlerFunc mocks the RegisterHandler method. RegisterHandlerFunc func(ctx context.Context, router *api.RoutingTree) // RunFunc mocks the Run method. RunFunc func(ctx context.Context) error // SchemaFunc mocks the Schema method. SchemaFunc func() (*openapi3.SchemaRef, error) // SetClientFunc mocks the SetClient method. SetClientFunc func(c *http.Client) // SetConfigFunc mocks the SetConfig method. SetConfigFunc func(ctx context.Context, config any) error // ShutdownFunc mocks the Shutdown method. ShutdownFunc func(ctx context.Context) error // StartupFunc mocks the Startup method. StartupFunc func(ctx context.Context, cResult chan<- Result) error // 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{ DeregisterHandlerFunc: func(ctx context.Context, router *api.RoutingTree) { panic("mock out the DeregisterHandler method") }, GetMetricCollectorsFunc: func() []prometheus.Collector { panic("mock out the GetMetricCollectors method") }, RegisterHandlerFunc: func(ctx context.Context, router *api.RoutingTree) { panic("mock out the RegisterHandler method") }, RunFunc: func(ctx context.Context) error { panic("mock out the Run method") }, SchemaFunc: func() (*openapi3.SchemaRef, error) { panic("mock out the Schema method") }, SetClientFunc: func(c *http.Client) { panic("mock out the SetClient method") }, SetConfigFunc: func(ctx context.Context, config any) error { panic("mock out the SetConfig method") }, ShutdownFunc: func(ctx context.Context) error { panic("mock out the Shutdown method") }, StartupFunc: func(ctx context.Context, cResult chan<- Result) error { panic("mock out the Startup method") }, } // use mockedCheck in code that requires Check // and then make assertions. }
func (*CheckMock) DeregisterHandler ¶ added in v0.1.2
func (mock *CheckMock) DeregisterHandler(ctx context.Context, router *api.RoutingTree)
DeregisterHandler calls DeregisterHandlerFunc.
func (*CheckMock) DeregisterHandlerCalls ¶ added in v0.1.2
func (mock *CheckMock) DeregisterHandlerCalls() []struct { Ctx context.Context Router *api.RoutingTree }
DeregisterHandlerCalls gets all the calls that were made to DeregisterHandler. Check the length with:
len(mockedCheck.DeregisterHandlerCalls())
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) RegisterHandler ¶ added in v0.1.2
func (mock *CheckMock) RegisterHandler(ctx context.Context, router *api.RoutingTree)
RegisterHandler calls RegisterHandlerFunc.
func (*CheckMock) RegisterHandlerCalls ¶ added in v0.1.2
func (mock *CheckMock) RegisterHandlerCalls() []struct { Ctx context.Context Router *api.RoutingTree }
RegisterHandlerCalls gets all the calls that were made to RegisterHandler. Check the length with:
len(mockedCheck.RegisterHandlerCalls())
func (*CheckMock) RunCalls ¶ added in v0.1.2
RunCalls gets all the calls that were made to Run. Check the length with:
len(mockedCheck.RunCalls())
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) SetClientCalls ¶ added in v0.1.2
SetClientCalls gets all the calls that were made to SetClient. Check the length with:
len(mockedCheck.SetClientCalls())
func (*CheckMock) SetConfigCalls ¶ added in v0.1.2
SetConfigCalls gets all the calls that were made to SetConfig. Check the length with:
len(mockedCheck.SetConfigCalls())
func (*CheckMock) ShutdownCalls ¶ added in v0.1.2
ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:
len(mockedCheck.ShutdownCalls())
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
Health is a check that measures the availability of an endpoint
func (*Health) DeregisterHandler ¶
func (h *Health) DeregisterHandler(_ context.Context, router *api.RoutingTree)
DeregisterHandler dynamically deletes the server handler
func (*Health) GetMetricCollectors ¶ added in v0.1.2
func (h *Health) GetMetricCollectors() []prometheus.Collector
GetMetricCollectors returns all metric collectors of check
func (*Health) RegisterHandler ¶
func (h *Health) RegisterHandler(ctx context.Context, router *api.RoutingTree)
RegisterHandler dynamically registers a server handler if it is enabled by the config
func (*Health) Schema ¶
Schema provides the schema of the data that will be provided by the heath check
type HealthConfig ¶
type HealthConfig struct { Enabled bool `json:"enabled,omitempty"` Targets []string `json:"targets,omitempty"` HealthEndpoint bool `json:"healthEndpoint,omitempty"` }
HealthConfig contains the health check config
type Latency ¶
type Latency struct {
// contains filtered or unexported fields
}
func (*Latency) DeregisterHandler ¶
func (l *Latency) DeregisterHandler(_ context.Context, router *api.RoutingTree)
func (*Latency) GetMetricCollectors ¶ added in v0.1.2
func (h *Latency) GetMetricCollectors() []prometheus.Collector
GetMetricCollectors returns all metric collectors of check
func (*Latency) RegisterHandler ¶
func (l *Latency) RegisterHandler(_ context.Context, router *api.RoutingTree)
type LatencyConfig ¶
type LatencyResult ¶
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"` // Err should be nil if the check ran successfully indicating the check is "healthy" // if the check failed, this should be an error message that will be logged and returned to an API user Err string `json:"error"` }