common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URISchemeUnknown = ""
	URISchemeHttp    = "http"
	URISchemeHttps   = "https"
)
View Source
const (
	URIPortUnknown = ""
	URIPortHttp    = "80"
	URIPortHttps   = "443"
)

Variables

This section is empty.

Functions

func Duration

func Duration(s string, def time.Duration) time.Duration

func ExtractDomain added in v0.2.0

func ExtractDomain(uri string) string

Helper functions for extracting the domain from URI

func Md5

func Md5(b []byte) []byte

func Md5ToString

func Md5ToString(b []byte) string

func NormalizeCountries

func NormalizeCountries(countries []string) []string

func NormalizeCountry

func NormalizeCountry(s string) string

func NormalizeCountryForMetrics added in v0.2.0

func NormalizeCountryForMetrics(country string) string

Helper function for normalizing the country

func NormalizeURI

func NormalizeURI(s string) string

func URIScheme

func URIScheme(uri string) string

Types

type Detector

type Detector interface {
	Name() string
	Schedule() string
	Start(ctx context.Context)
	Detect() error
}

type DetectorDefaultConfig added in v1.0.0

type DetectorDefaultConfig struct {
	Name         string   `yaml:"name"`
	DetectorType string   `yaml:"detector_type"`
	Schedule     string   `yaml:"schedule"`
	Countries    []string `yaml:"countries"`
	Sources      []string `yaml:"sources"`
	Observers    []string `yaml:"observers"`
	Verifiers    []string `yaml:"verifiers"`
	Notifiers    []string `yaml:"notifiers"`
}

DetectorDefaultConfig holds the configuration for a single detector entry in the V3 YAML config.

type DetectorOptions

type DetectorOptions struct {
	StartTimeout int
}

type Detectors

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

func NewDetectors

func NewDetectors(options *DetectorOptions, observability *Observability) *Detectors

func (*Detectors) Add

func (ds *Detectors) Add(d ...Detector)

func (*Detectors) Scheduled

func (ds *Detectors) Scheduled() bool

func (*Detectors) Start

func (ds *Detectors) Start(once, wait bool, ctx context.Context)

type Memory added in v1.0.0

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

func NewMemory added in v1.0.0

func NewMemory(options *MemoryOptions, observability *Observability) *Memory

func (*Memory) Approve added in v1.0.0

func (m *Memory) Approve(key string)

func (*Memory) Delete added in v1.0.0

func (m *Memory) Delete(key string)

func (*Memory) Get added in v1.0.0

func (m *Memory) Get(key string) *MemoryEntry

func (*Memory) Record added in v1.0.0

func (m *Memory) Record(key, messageID, notifierName string)

type MemoryEntry added in v1.0.0

type MemoryEntry struct {
	MessageID    string
	NotifierName string
	State        MemoryState
	SentAt       time.Time
}

type MemoryOptions added in v1.0.0

type MemoryOptions struct {
	TTL string
}

type MemoryState added in v1.0.0

type MemoryState string
const (
	MemoryStateSent     MemoryState = "sent"
	MemoryStateApproved MemoryState = "approved"
)

type Notifier

type Notifier interface {
	Name() string
	Notify(vr *VerifyResult) error
}

type NotifierConfiguration

type NotifierConfiguration struct {
	Notifier    Notifier
	Probability NotifierProbability
}

type NotifierDefault added in v1.0.0

type NotifierDefault interface {
	Name() string
	NotifyDefault(vr *VerifyDefaultResult) error
}

NotifierDefault is the interface for notifiers that support the Default pipeline.

type NotifierDefaultConfig added in v1.0.0

type NotifierDefaultConfig struct {
	Name             string  `yaml:"name"`
	URL              string  `yaml:"url"`
	Bot              string  `yaml:"bot"`
	Channel          string  `yaml:"channel"`
	UserID           string  `yaml:"user_id"`
	Timeout          int     `yaml:"timeout"`
	Insecure         bool    `yaml:"insecure"`
	ThresholdWarning float64 `yaml:"threshold_warning"`
	ThresholdAlert   float64 `yaml:"threshold_alert"`
}

NotifierDefaultConfig holds the configuration for a single notifier entry in the V3 YAML config.

type NotifierDefaultConfiguration added in v1.0.0

type NotifierDefaultConfiguration struct {
	Notifier         NotifierDefault
	ThresholdWarning float64
	ThresholdAlert   float64
}

NotifierDefaultConfiguration wraps a NotifierDefault for use in the Default pipeline.

type NotifierDefaultTrackable added in v1.0.0

type NotifierDefaultTrackable interface {
	NotifierDefault
	NotifyDefaultWithTracking(vr *VerifyDefaultResult) ([]*NotifyDefaultTrackingItem, error)
	CheckMessageStatus(id string) (string, error)
}

NotifierDefaultTrackable extends NotifierDefault with message tracking and status checking.

type NotifierProbability

type NotifierProbability = float64

type Notifiers

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

func NewNotifiers

func NewNotifiers(observability *Observability) *Notifiers

func (*Notifiers) Add

func (ns *Notifiers) Add(n Notifier)

func (*Notifiers) FindConfigurationByPattern

func (ns *Notifiers) FindConfigurationByPattern(pattern string) []*NotifierConfiguration

func (*Notifiers) GetDefaultConfigurations

func (ns *Notifiers) GetDefaultConfigurations() []*NotifierConfiguration

func (*Notifiers) Items

func (ns *Notifiers) Items() []Notifier

type NotifyDefaultTrackingItem added in v1.0.0

type NotifyDefaultTrackingItem struct {
	ItemIndex int
	MessageID string
}

type Observability

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

func NewObservability

func NewObservability(logs *sre.Logs, metrics *sre.Metrics) *Observability

func (*Observability) Debug

func (o *Observability) Debug(obj interface{}, args ...interface{})

func (*Observability) Error

func (o *Observability) Error(obj interface{}, args ...interface{})

func (*Observability) Info

func (o *Observability) Info(obj interface{}, args ...interface{})

func (*Observability) Logs

func (o *Observability) Logs() *sre.Logs

func (*Observability) Metrics

func (o *Observability) Metrics() *sre.Metrics

func (*Observability) Panic added in v0.0.3

func (o *Observability) Panic(obj interface{}, args ...interface{})

Panic implements common.Logger.

func (*Observability) Warn

func (o *Observability) Warn(obj interface{}, args ...interface{})

type ObserveCountries

type ObserveCountries = map[string]*ObserveProbability

type ObserveDefaultItem added in v1.0.0

type ObserveDefaultItem struct {
	Labels map[string]string
	Value  float64
}

ObserveDefaultItem is a single result entry from a label-grouped Default pipeline observation.

type ObserveDefaultOutput added in v1.0.0

type ObserveDefaultOutput struct {
	Items []*ObserveDefaultItem
}

ObserveDefaultOutput is the result returned by ObserverDefault.ObserveDefault().

func (*ObserveDefaultOutput) IsEmpty added in v1.0.0

func (o *ObserveDefaultOutput) IsEmpty() bool

type ObserveEndpoint

type ObserveEndpoint struct {
	URI       string
	Countries ObserveCountries
	IPs       []string
	Response  *SourceEndpointResponse
}

type ObserveEndpoints

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

func (*ObserveEndpoints) Add

func (oes *ObserveEndpoints) Add(e ...*ObserveEndpoint)

func (*ObserveEndpoints) Clone

func (*ObserveEndpoints) IsEmpty

func (oes *ObserveEndpoints) IsEmpty() bool

func (*ObserveEndpoints) Items

func (oes *ObserveEndpoints) Items() []*ObserveEndpoint

func (*ObserveEndpoints) Reduce

func (oes *ObserveEndpoints) Reduce() ObserveEndpoints

type ObserveProbability

type ObserveProbability = float64

type ObserveResult

type ObserveResult struct {
	Configuration *ObserverConfiguration
	Endpoints     ObserveEndpoints
}

type Observer

type Observer interface {
	Name() string
	Observe(sr *SourceEndpointResult) (*ObserveResult, error)
}

type ObserverConfig added in v1.0.0

type ObserverConfig struct {
	Name         string  `yaml:"name"`
	QueryDatadog string  `yaml:"query_datadog"`
	QueryProm    string  `yaml:"query_prom"`
	Timeout      string  `yaml:"timeout"`
	Trashold     float64 `yaml:"trashold"`
}

ObserverConfig holds the configuration for a single observer entry in the V3 YAML config.

type ObserverConfiguration

type ObserverConfiguration struct {
	Observer    Observer
	Probability ObserveProbability
}

type ObserverDefault added in v1.0.0

type ObserverDefault interface {
	Name() string
	ObserveDefault(cfg *ObserverConfig) (*ObserveDefaultOutput, error)
}

ObserverDefault is the interface for observers that support the Default pipeline. They receive a ready-made query from the V3 config and return label-grouped results.

type Observers

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

func NewObservers

func NewObservers(observability *Observability) *Observers

func (*Observers) Add

func (ob *Observers) Add(o Observer)

func (*Observers) FindConfigurationByPattern

func (ob *Observers) FindConfigurationByPattern(pattern string) []*ObserverConfiguration

func (*Observers) GetDefaultConfigurations

func (ob *Observers) GetDefaultConfigurations() []*ObserverConfiguration

func (*Observers) Items

func (ob *Observers) Items() []Observer

type SourceDefaultInterface added in v1.0.0

type SourceDefaultInterface interface {
	Name() string
	Load() (*SourceDefaultResult, error)
}

SourceDefaultInterface is the interface for V3 YAML-based configuration sources.

type SourceDefaultResult added in v1.0.0

type SourceDefaultResult struct {
	Observers []*ObserverConfig
	Verifiers []*VerifierConfig
	Notifiers []*NotifierDefaultConfig
	Detectors []*DetectorDefaultConfig
}

SourceDefaultResult is the result returned by SourceDefaultInterface.Load(). It contains all observers, verifiers, notifiers and detectors parsed from the V3 YAML configuration.

type SourceEndpoint

type SourceEndpoint struct {
	URI       string                  `json:"uri"`
	Disabled  bool                    `json:"disabled"`
	Countries []string                `json:"countries,omitempty"`
	IPs       []string                `json:"ips,omitempty"`
	Detectors []string                `json:"detectors,omitempty"`
	Response  *SourceEndpointResponse `json:"response,omitempty"`
}

func CheckSourceEndpoints

func CheckSourceEndpoints(es []*SourceEndpoint) []*SourceEndpoint

type SourceEndpointInterface added in v1.0.0

type SourceEndpointInterface interface {
	Name() string
	Start(ctx context.Context) error
	Load() (*SourceEndpointResult, error)
}

type SourceEndpointResponse

type SourceEndpointResponse struct {
	Code    string `json:"code,omitempty"`
	Content string `json:"content,omitempty"`
}

type SourceEndpointResult added in v1.0.0

type SourceEndpointResult struct {
	Endpoints SourceEndpoints
}

type SourceEndpoints

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

func (*SourceEndpoints) Add

func (ses *SourceEndpoints) Add(e ...*SourceEndpoint)

func (*SourceEndpoints) Clone

func (*SourceEndpoints) IsEmpty

func (ses *SourceEndpoints) IsEmpty() bool

func (*SourceEndpoints) Items

func (ses *SourceEndpoints) Items() []*SourceEndpoint

func (*SourceEndpoints) Reduce

func (ses *SourceEndpoints) Reduce() SourceEndpoints

type Sources

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

func NewSources

func NewSources(observability *Observability) *Sources

func (*Sources) Add

func (ss *Sources) Add(s SourceEndpointInterface)

func (*Sources) FindByName

func (ss *Sources) FindByName(name string) SourceEndpointInterface

func (*Sources) Items

func (ss *Sources) Items() []SourceEndpointInterface

type TriggerOptions

type TriggerOptions struct {
	TTL string
}

type Triggers

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

func NewTriggers

func NewTriggers(options *TriggerOptions, observability *Observability) *Triggers

func (*Triggers) Exists

func (t *Triggers) Exists(key string) bool

func (*Triggers) Update

func (t *Triggers) Update(key string, ep *VerifyEndpoint)

type URI

type URI struct {
	Scheme   string
	UserName string
	Password string
	Host     string
	Port     string
	Path     string
	Query    string
	Fragment string
}

type Verifier

type Verifier interface {
	Name() string
	Verify(or *ObserveResult) (*VerifyResult, error)
}

type VerifierConfig added in v1.0.0

type VerifierConfig struct {
	Name            string `yaml:"name"`
	URL             string `yaml:"url"`
	BusinessProcess string `yaml:"business_process"`
	Timeout         int    `yaml:"timeout"`
	TestTimeout     int    `yaml:"test_timeout"`
	TestRetries     int    `yaml:"test_retries"`
}

VerifierConfig holds the configuration for a single verifier entry in the V3 YAML config.

type VerifierConfiguration

type VerifierConfiguration struct {
	Verifier    Verifier
	Probability VerifyProbability
}

type VerifierDefaultInterface added in v1.0.0

type VerifierDefaultInterface interface {
	Name() string
	VerifyDefault(out *ObserveDefaultOutput) (*VerifyDefaultResult, error)
}

VerifierDefaultInterface is the interface for verifiers that support the Default pipeline.

type VerifierMetrics added in v0.2.0

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

func NewVerifierMetrics added in v0.2.0

func NewVerifierMetrics(metrics *sreCommon.Metrics) *VerifierMetrics

func (*VerifierMetrics) GetMetrics added in v0.2.0

func (vm *VerifierMetrics) GetMetrics() *sreCommon.Metrics

GetMetrics returns the metrics object for direct access

func (*VerifierMetrics) RecordTestErrorByType added in v0.2.1

func (vm *VerifierMetrics) RecordTestErrorByType(componentType, componentName, domain, country, errorType string, duration float64)

RecordTestErrorByType records the error with component type

func (*VerifierMetrics) RecordTestResult added in v0.2.0

func (vm *VerifierMetrics) RecordTestResult(verifier, domain, country string, probability float64, duration float64)

RecordTestResult records the result of the test with probability

func (*VerifierMetrics) RecordTestStartByType added in v0.2.1

func (vm *VerifierMetrics) RecordTestStartByType(componentType, componentName, domain, country string)

RecordTestStartByType records the start of the test with component type

func (*VerifierMetrics) RecordTestSuccessByType added in v0.2.1

func (vm *VerifierMetrics) RecordTestSuccessByType(componentType, componentName, domain, country string, duration float64)

RecordTestSuccessByType records the successful execution with component type

type Verifiers

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

func NewVerifiers

func NewVerifiers(observability *Observability) *Verifiers

func (*Verifiers) Add

func (vs *Verifiers) Add(v Verifier)

func (*Verifiers) FindConfigurationByPattern

func (vs *Verifiers) FindConfigurationByPattern(pattern string) []*VerifierConfiguration

func (*Verifiers) GetDefaultConfigurations

func (vs *Verifiers) GetDefaultConfigurations() []*VerifierConfiguration

func (*Verifiers) Items

func (vs *Verifiers) Items() []Verifier

type VerifyCountries

type VerifyCountries = map[string]*VerifyStatus

type VerifyDefaultItem added in v1.0.0

type VerifyDefaultItem struct {
	Labels   map[string]string
	Value    float64
	Passed   bool
	Severity string
	Details  string
}

VerifyDefaultItem is a standardized verification result for one label-group from the Default pipeline.

type VerifyDefaultResult added in v1.0.0

type VerifyDefaultResult struct {
	Items []*VerifyDefaultItem
}

VerifyDefaultResult is the result returned by VerifierDefaultInterface.Verify(). It contains one VerifyDefaultItem per label-group returned by the observer.

func (*VerifyDefaultResult) IsEmpty added in v1.0.0

func (v *VerifyDefaultResult) IsEmpty() bool

type VerifyEndpoint

type VerifyEndpoint struct {
	URI       string
	Countries VerifyCountries
}

func (*VerifyEndpoint) Ident

func (ve *VerifyEndpoint) Ident() string

type VerifyEndpoints

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

func (*VerifyEndpoints) Add

func (ves *VerifyEndpoints) Add(e ...*VerifyEndpoint)

func (*VerifyEndpoints) Clone

func (*VerifyEndpoints) IsEmpty

func (ves *VerifyEndpoints) IsEmpty() bool

func (*VerifyEndpoints) Items

func (ves *VerifyEndpoints) Items() []*VerifyEndpoint

func (*VerifyEndpoints) Reduce

func (ves *VerifyEndpoints) Reduce() VerifyEndpoints

type VerifyProbability

type VerifyProbability = float64

type VerifyResult

type VerifyResult struct {
	Configuration *VerifierConfiguration
	Endpoints     VerifyEndpoints
}

type VerifyStatus

type VerifyStatus struct {
	Probability *VerifyProbability
	Flags       VerifyStatusFlags
}

type VerifyStatusFlag

type VerifyStatusFlag = string
const (
	VerifyStatusFlagWrongIPAddress    VerifyStatusFlag = "wrong_ip_address"
	VerifyStatusFlagWrongResponseCode VerifyStatusFlag = "wrong_response_code"
)

type VerifyStatusFlags

type VerifyStatusFlags = map[VerifyStatusFlag]bool

Jump to

Keyboard shortcuts

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