checker

package
v0.0.0-...-7652ffb Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 41 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// MaxTestTargets is the maximum number of test-check targets returned
	// from the resolver that we use.
	MaxTestTargets      = 5
	NumCheckSyncRetries = 11

	// BastionProtoVersion is used for feature flagging fields in various Bastion
	// message types that specify a version number.
	BastionProtoVersion = 2

	// Time to allow requests to read a response body.
	BodyReadTimeout = 10 * time.Second

	// Maximum length of response bodies
	MaxContentLength = 128000
)
View Source
const (
	MaxRoutinesPerWorkerType = 10
	MaxQueueDepth            = 10
)
View Source
const (
	// Checks with an interval less than 15 seconds will fail to be created.
	MinimumCheckInterval = 15
)

Variables

View Source
var (
	BezosClient                opsee.BezosClient
	CloudWatchStatisticsPeriod = 60
)
View Source
var (
	DefaultResponseCacheTTL = time.Second * time.Duration(5)
)
View Source
var Recruiters = &recruiters{
	recruitersMap: make(map[string]NewWorkerFunc),
}

Functions

func ConnectCloudwatchBezosClient

func ConnectCloudwatchBezosClient() error

func NewCheckTargets

func NewCheckTargets(resolver Resolver, check *schema.Check) (*schema.CheckTargets, error)

Types

type AWSResolver

type AWSResolver struct {
	BezosClient opsee.BezosClient
	VpcId       string
	Region      string
	User        *schema.User
}

TODO: The resolver should not query the EC2Scanner directly, but should go through the instance/group cache instead.

func (*AWSResolver) Resolve

func (this *AWSResolver) Resolve(ctx context.Context, target *schema.Target) ([]*schema.Target, error)

type CheckTimer

type CheckTimer struct {
	Check *schema.Check
	// contains filtered or unexported fields
}

CheckTimer sends a check over a channel at a set interval. TODO(greg): Instead of sending check pointers over this channel, we should send a check execution task -- some wrapper object with a context that includes a deadline. Basically, add contexts to scheduled executions.

func NewCheckTimer

func NewCheckTimer(check *schema.Check, runChan chan *schema.Check) (*CheckTimer, error)

NewCheckTimer creates a new timer and associates the given channel with that timer. Every N seconds (the Check's Duration field), the CheckTimer will send the check over the runChan channel. If this channel blocks for more than N seconds, you will start executing stale check requests. Managing backpressure for this channel is important. TODO(greg): manage backpressure for this channel.

func (*CheckTimer) Stop

func (c *CheckTimer) Stop()

Stop the Check's timer.

type Checker

type Checker struct {
	Port      int
	Scheduler *Scheduler

	Runner *RemoteRunner
	// contains filtered or unexported fields
}

func NewChecker

func NewChecker(r Resolver) *Checker

func (*Checker) CreateCheck

func (*Checker) DeleteCheck

func (*Checker) GetExistingChecks

func (c *Checker) GetExistingChecks(tries int) ([]*schema.Check, error)

func (*Checker) RetrieveCheck

func (c *Checker) RetrieveCheck(ctx context.Context, req *opsee.CheckResourceRequest) (*opsee.ResourceResponse, error)

func (*Checker) Start

func (c *Checker) Start() error

Start all of the checker loops, grpc server, etc.

func (*Checker) Stop

func (c *Checker) Stop()

Stop all of the checker loops, grpc server, etc.

func (*Checker) TestCheck

func (*Checker) UpdateCheck

type CheckerRpcClient

type CheckerRpcClient struct {
	Client opsee.CheckerClient
	// contains filtered or unexported fields
}

func NewRpcClient

func NewRpcClient(host string, port int) (*CheckerRpcClient, error)

func (*CheckerRpcClient) Close

func (c *CheckerRpcClient) Close()

type CloudWatchRequest

type CloudWatchRequest struct {
	User                   *schema.User
	Region                 string
	VpcId                  string
	MaxAge                 time.Duration
	Target                 *schema.Target
	Metrics                []*schema.CloudWatchMetric
	Namespace              string
	StatisticsIntervalSecs int
	StatisticsPeriod       int
	Statistics             []string
}

func (*CloudWatchRequest) Do

func (this *CloudWatchRequest) Do(ctx context.Context) <-chan *Response

func (*CloudWatchRequest) GetDimensions

func (this *CloudWatchRequest) GetDimensions(metric *schema.CloudWatchMetric) ([]*opsee_aws_cloudwatch.Dimension, error)

TODO(dan) should we add a target to the metric or assume that they all have the same target

type CloudWatchWorker

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

func (*CloudWatchWorker) Work

func (this *CloudWatchWorker) Work(ctx context.Context, task *Task) *Task

type Dispatcher

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

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher returns a dispatcher with populated internal worker groups.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, tg TaskGroup) chan *Task

Dispatch guarantees that every Task in a TaskGroup has a response. A call to Dispatch will return a channel that is closed when all tasks have finished completion. Cancelling the context will cause Dispatch to insert an error as the response that indicates the context was cancelled.

type HTTPRequest

type HTTPRequest struct {
	Method             string           `json:"method"`
	Host               string           `json:"host"`
	URL                string           `json:"url"`
	Headers            []*schema.Header `json:"headers"`
	Body               string           `json:"body"`
	InsecureSkipVerify bool             `json:"insecure_skip_verify"`
}

func (*HTTPRequest) Do

func (r *HTTPRequest) Do(ctx context.Context) <-chan *Response

type HTTPWorker

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

func (*HTTPWorker) Work

func (w *HTTPWorker) Work(ctx context.Context, task *Task) *Task

type Interval

type Interval time.Duration

type MetricStatisticsResponse

type MetricStatisticsResponse struct {
	Index  int
	Error  error
	Metric *schema.Metric
}

type NSQRunner

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

func NewNSQRunner

func NewNSQRunner(runner *Runner, cfg *NSQRunnerConfig) (*NSQRunner, error)

func (*NSQRunner) Stop

func (r *NSQRunner) Stop()

type NSQRunnerConfig

type NSQRunnerConfig struct {
	Id                  string
	ConsumerQueueName   string
	ProducerQueueName   string
	ConsumerChannelName string
	ConsumerNsqdHost    string
	ProducerNsqdHost    string
	MaxHandlers         int
}

type NewWorkerFunc

type NewWorkerFunc func(chan Worker) Worker

type Publisher

type Publisher interface {
	Publish(string, []byte) error
	Stop()
}

type RemoteRunner

type RemoteRunner struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRemoteRunner

func NewRemoteRunner(cfg *NSQRunnerConfig) (*RemoteRunner, error)

func (*RemoteRunner) RunCheck

func (r *RemoteRunner) RunCheck(ctx context.Context, checkWithTargets *schema.CheckTargets) (*schema.CheckResult, error)

func (*RemoteRunner) Stop

func (r *RemoteRunner) Stop()

type Request

type Request interface {
	Do(context.Context) <-chan *Response
}

type Resolver

type Resolver interface {
	Resolve(context.Context, *schema.Target) ([]*schema.Target, error)
}

A Respolver resolves a target into an array of targets that are * directly addressable by a bastion component. * * It is important to note, that Target IDs should be unique across * a set of responses. This makes them

func NewResolver

func NewResolver(bezos opsee.BezosClient, cfg *config.Config) Resolver

type Response

type Response struct {
	Response schema.CheckResponseReply
	Error    error
}

type Runner

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

A Runner is responsible for running checks. Given a request for a check (see: RunCheck), it will execute that check within a context, returning a response for every resolved check target. The Runner is not meant for concurrent use. It provides an asynchronous API for submitting jobs and manages its own concurrency.

func NewRunner

func NewRunner(checkType interface{}) *Runner

NewRunner returns a runner associated with a particular resolver.

func (*Runner) RunCheck

func (r *Runner) RunCheck(ctx context.Context, check *schema.Check, targets []*schema.Target) ([]*schema.CheckResponse, error)

If the Context passed to RunCheck includes a MaxHosts value, at most MaxHosts CheckResponse objects will be returned.

If the Context passed to RunCheck is cancelled or its deadline is exceeded, all CheckResponse objects after that event will be passed to the channel with appropriate errors associated with them.

type Scheduler

type Scheduler struct {
	Producer Publisher
	// contains filtered or unexported fields
}
Scheduler is responsible for managing the set of timers used for checks

as well as publishing requests for runners to run checks.

func NewScheduler

func NewScheduler(r Resolver) *Scheduler

func (*Scheduler) CreateCheck

func (s *Scheduler) CreateCheck(check *schema.Check) (*schema.Check, error)

func (*Scheduler) DeleteCheck

func (s *Scheduler) DeleteCheck(check *schema.Check) (*schema.Check, error)

func (*Scheduler) RetrieveCheck

func (s *Scheduler) RetrieveCheck(check *schema.Check) (*schema.Check, error)

func (*Scheduler) Start

func (s *Scheduler) Start() error

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type SlateClient

type SlateClient struct {

	// MaxRetries is the number of times the SlateClient will retry a failed
	// request. Default: 11
	MaxRetries int
	// contains filtered or unexported fields
}

SlateClient -- for clienting slates.

func NewSlateClient

func NewSlateClient(slateUrl string) *SlateClient

func (*SlateClient) CheckAssertions

func (s *SlateClient) CheckAssertions(ctx context.Context, check *schema.Check, checkResponse json.RawMessage) (bool, error)

CheckAssertions issues a request to Slate to determine if a check response is passing or failing.

type SlateRequest

type SlateRequest struct {
	Assertions []*schema.Assertion `json:"assertions"`
	Response   json.RawMessage     `json:"response"`
}

type SlateResponse

type SlateResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

type Task

type Task struct {
	Type     string
	Target   *schema.Target
	Request  Request
	Response *Response
}

type TaskGroup

type TaskGroup []*Task

A TaskGroup is the unit of work for a Dispatcher.

type Worker

type Worker interface {
	Work(context.Context, *Task) *Task
}

func NewCloudWatchWorker

func NewCloudWatchWorker(queue chan Worker) Worker

func NewHTTPWorker

func NewHTTPWorker(queue chan Worker) Worker

Jump to

Keyboard shortcuts

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