Documentation
¶
Overview ¶
Package monitor runs operator-defined uptime checks and records their results.
Index ¶
- Constants
- Variables
- func HourBucket(at int64) int64
- func Validate(m Monitor, cfg Config) error
- func ValidateTarget(ctx context.Context, m Monitor) error
- type Batcher
- type Checker
- type Config
- type CreateInput
- type History
- type Monitor
- type Options
- type Result
- type ResultSink
- type Rollup
- type Scheduler
- type Secrets
- type Service
- func (s *Service) Config() Config
- func (s *Service) Create(ctx context.Context, in CreateInput) (Monitor, error)
- func (s *Service) Delete(ctx context.Context, id string) error
- func (s *Service) Get(ctx context.Context, id string) (Monitor, error)
- func (s *Service) List(ctx context.Context) ([]Monitor, error)
- func (s *Service) Prune(ctx context.Context) error
- func (s *Service) Results(ctx context.Context, id string, window time.Duration, limit int) (History, error)
- func (s *Service) Run(ctx context.Context)
- type Spec
- type StatusRange
- type Store
Constants ¶
const ( ReasonTimeout = "timeout" ReasonBlocked = "blocked_address" ReasonConnect = "connect_failed" ReasonStatus = "status_mismatch" ReasonKeyword = "keyword_missing" ReasonRedirects = "redirect_limit" ReasonBadRequest = "bad_request" ReasonSecretMissing = "secret_unavailable" )
Failure classes stored in Result.Reason.
const ( DefaultWorkers = 4 DefaultMinIntervalHTTP = 30 * time.Second DefaultMinIntervalTCP = 30 * time.Second DefaultMaxTimeout = 30 * time.Second DefaultMaxCount = 100 DefaultBodyMaxBytes = 64 * 1024 DefaultMaxHeaders = 16 DefaultHeaderMaxBytes = 4096 DefaultMaxRedirects = 5 DefaultFlushInterval = 5 * time.Second DefaultBufferMax = 10000 DefaultRawRetention = 48 * time.Hour DefaultHourRetention = 400 * 24 * time.Hour DefaultPruneInterval = 10 * time.Minute DefaultPruneBatch = 1000 DefaultJitterPercent = 10 DefaultTickInterval = time.Second DefaultResultsMaxLimit = 1000 )
Defaults apply only when the matching APP_MONITOR_* variable is unset.
const ( KindHTTP = "http" KindTCP = "tcp" )
Monitor kinds.
const Location = "cp"
Location labels results from this control plane, the only vantage point so far.
Variables ¶
var ( ErrInvalid = errors.New("monitor: invalid") ErrNotFound = errors.New("monitor: not found") ErrLimit = errors.New("monitor: limit reached") )
Sentinel errors the API maps to status codes.
Functions ¶
func HourBucket ¶
HourBucket is the start of the hour containing unix second at.
Types ¶
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
Batcher buffers results so the single SQLite writer sees one transaction per flush.
func NewBatcher ¶
func NewBatcher(sink ResultSink, capacity int) *Batcher
NewBatcher builds a Batcher that holds at most capacity results.
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker runs one probe. Every dial goes through the netguard address check.
func NewChecker ¶
NewChecker builds a Checker whose connections refuse internal addresses unless the netguard private opt-in env is set.
type Config ¶
type Config struct {
Enabled bool
Workers int
MinIntervalHTTP time.Duration
MinIntervalTCP time.Duration
MaxTimeout time.Duration
MaxCount int
BodyMaxBytes int
MaxHeaders int
HeaderMaxBytes int
MaxRedirects int
FlushInterval time.Duration
BufferMax int
RawRetention time.Duration
HourRetention time.Duration
PruneInterval time.Duration
PruneBatch int
JitterPercent int
TickInterval time.Duration
ResultsMaxLimit int
UserAgent string
}
Config holds every limit of the monitor engine, all read from APP_MONITOR* variables.
func ConfigFromEnv ¶
ConfigFromEnv reads the engine settings. Unset variables take the defaults above.
type CreateInput ¶
CreateInput is a monitor definition plus its header values, which are stored encrypted and never returned.
type Monitor ¶
type Monitor struct {
ID string
Name string
Kind string
Interval time.Duration
Timeout time.Duration
Enabled bool
Spec Spec
CreatedAt time.Time
}
Monitor is one check definition.
type Options ¶
Options configures a Service. Secrets may be nil, which rejects monitors that carry headers.
type ResultSink ¶
ResultSink persists a batch of results and updates the hourly rollups in the same transaction.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler keeps monitors in a min-heap by due time. It takes the time as an argument so tests drive it with a fake clock.
func NewScheduler ¶
NewScheduler builds a Scheduler. A nil jitter uses a random share of the interval.
func (*Scheduler) Add ¶
Add schedules m, replacing an earlier entry with the same id. A disabled monitor is only removed.
type Secrets ¶
type Secrets interface {
SetValue(ctx context.Context, serviceName, envKey, plaintext string) error
Resolve(ctx context.Context, serviceName, envKey string) (string, error)
DeleteAll(ctx context.Context, serviceName string) error
}
Secrets keeps header values envelope-encrypted.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the scheduler, workers, batcher and pruner.
type Spec ¶
type Spec struct {
URL string `json:"url,omitempty"`
Method string `json:"method,omitempty"`
HeaderNames []string `json:"header_names,omitempty"`
Expect []StatusRange `json:"expect,omitempty"`
Contains string `json:"contains,omitempty"`
FollowRedirects bool `json:"follow_redirects,omitempty"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
}
Spec is the kind specific part of a monitor. Header values never live here, only their names.
type StatusRange ¶
StatusRange is an inclusive HTTP status interval.
type Store ¶
type Store interface {
ResultSink
ListMonitors(ctx context.Context) ([]Monitor, error)
GetMonitor(ctx context.Context, id string) (Monitor, error)
CountMonitors(ctx context.Context) (int, error)
SaveMonitor(ctx context.Context, m Monitor) error
DeleteMonitor(ctx context.Context, id string) error
ListResults(ctx context.Context, id string, since int64, limit int) ([]Result, error)
ListRollups(ctx context.Context, id string, sinceBucket int64, limit int) ([]Rollup, error)
PruneResults(ctx context.Context, id string, before int64, limit int) (int, error)
PruneRollups(ctx context.Context, id string, before int64, limit int) (int, error)
}
Store is the persistence the engine needs.