external

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertificateProvider added in v1.0.0

type CertificateProvider struct {
	TimeOut time.Duration
}

CertificateProvider is a status provider that check SSL certificate

func (*CertificateProvider) Status added in v1.0.0

func (c *CertificateProvider) Status(req Request) (*Response, error)

Status url looks like: cert://example.com. It will try to get SSL certificate and check if it is valid and not going to expire soon

type DockerProvider

type DockerProvider struct {
	TimeOut time.Duration
}

DockerProvider is a status provider that uses docker

func (*DockerProvider) Status

func (d *DockerProvider) Status(req Request) (*Response, error)

Status the url looks like: docker:///var/run/docker.sock or docker://1.2.3.4:2375 optionally the url can contain a query param "required" with a comma separated list of required container names i.e. docker:///var/run/docker.sock?containers=foo,bar

type FileProvider added in v1.1.0

type FileProvider struct {
	TimeOut time.Duration
	// contains filtered or unexported fields
}

FileProvider is a status provider that checks the status of a file.

func (*FileProvider) Status added in v1.1.0

func (f *FileProvider) Status(req Request) (*Response, error)

Status returns the status of the file url looks like this: file://blah/foo.txt (relative path) or file:///blah/foo.txt (absolute path)

type HTTPProvider

type HTTPProvider struct {
	http.Client
}

HTTPProvider is an external service that checks the status of a HTTP endpoint

func (*HTTPProvider) Status

func (h *HTTPProvider) Status(req Request) (*Response, error)

Status returns the status of the external service via HTTP GET

type MongoProvider

type MongoProvider struct {
	TimeOut time.Duration
}

MongoProvider is a status provider that uses mongo

func (*MongoProvider) Status

func (m *MongoProvider) Status(req Request) (*Response, error)

Status returns status of mongo, checks if connection established and ping is ok request URL looks like mongo:mongodb://172.17.42.1:27017/test?oplogMaxDelta=30m oplogMaxDelta is optional, if set, checks if oplog is not too far behind

type NginxProvider added in v0.5.0

type NginxProvider struct {
	TimeOut time.Duration
	// contains filtered or unexported fields
}

NginxProvider is a status provider that uses nginx status response

func (*NginxProvider) Status added in v0.5.0

func (n *NginxProvider) Status(req Request) (*Response, error)

Status url looks like: nginx://example.com/nginx_status. It will try https first and if it fails http nginx response looks like this:

Active connections: 124
server accepts handled requests
 783855 783855 1676992
Reading: 0 Writing: 300 Waiting: 27

type ProgramProvider added in v0.4.0

type ProgramProvider struct {
	WithShell bool
	TimeOut   time.Duration
}

ProgramProvider is an external service that runs a command and checks the exit code.

func (*ProgramProvider) Status added in v0.4.0

func (p *ProgramProvider) Status(req Request) (*Response, error)

Status returns the status of the execution of the command from the request. url looks like this: program://cat?args=/tmp/foo

type Providers

type Providers struct {
	HTTP        StatusProvider
	Mongo       StatusProvider
	Docker      StatusProvider
	Program     StatusProvider
	Nginx       StatusProvider
	Certificate StatusProvider
	File        StatusProvider
	RMQ         StatusProvider
}

Providers is a list of StatusProvider

type RMQProvider added in v1.3.0

type RMQProvider struct {
	TimeOut time.Duration
	// contains filtered or unexported fields
}

RMQProvider is a status provider that uses RabbitMQ management API

func (*RMQProvider) Status added in v1.3.0

func (h *RMQProvider) Status(req Request) (*Response, error)

Status returns the status for a given queue via RabbitMQ management API Status url looks like: rmq://user:passwd@example.com:12345/queues/vhost/queue_name. It will try https first and if it fails http

type Request

type Request struct {
	Name string
	URL  string
}

Request is a name and request to external service

type Response

type Response struct {
	Name         string                 `json:"name"`
	StatusCode   int                    `json:"status_code"`
	ResponseTime int64                  `json:"response_time"` // milliseconds
	Body         map[string]interface{} `json:"body,omitempty"`
}

Response contains extended service information

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service wraps multiple StatusProvider and multiplex their Status() calls

func NewService

func NewService(providers Providers, concurrency int, reqs ...string) *Service

NewService creates new external service supporting multiple providers reqs are requests to external services presented as pairs of name and url, i.e. health:http://localhost:8080/health

func (*Service) Status

func (s *Service) Status() []Response

Status returns extended service information, runs concurrently

type StatusProvider

type StatusProvider interface {
	Status(req Request) (*Response, error)
}

StatusProvider is an interface for getting status from external services

type StatusProviderMock

type StatusProviderMock struct {
	// StatusFunc mocks the Status method.
	StatusFunc func(req Request) (*Response, error)
	// contains filtered or unexported fields
}

StatusProviderMock is a mock implementation of StatusProvider.

func TestSomethingThatUsesStatusProvider(t *testing.T) {

	// make and configure a mocked StatusProvider
	mockedStatusProvider := &StatusProviderMock{
		StatusFunc: func(req Request) (*Response, error) {
			panic("mock out the Status method")
		},
	}

	// use mockedStatusProvider in code that requires StatusProvider
	// and then make assertions.

}

func (*StatusProviderMock) Status

func (mock *StatusProviderMock) Status(req Request) (*Response, error)

Status calls StatusFunc.

func (*StatusProviderMock) StatusCalls

func (mock *StatusProviderMock) StatusCalls() []struct {
	Req Request
}

StatusCalls gets all the calls that were made to Status. Check the length with:

len(mockedStatusProvider.StatusCalls())

Jump to

Keyboard shortcuts

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