Documentation ¶
Index ¶
- func BackfillOption(count int) func(*Options)
- func DestinationMetricTypeStrings() []string
- func DryRunOption(dryRun bool) func(*Options)
- func DumpReportsOption(dump bool) func(*Options)
- type Alert
- func (alert *Alert) CorrectionTime() (time.Duration, bool)
- func (alert *Alert) EvaluateReliabilities(timeFrame time.Duration, enableReassessment bool) (Reliabilities, error)
- func (alert *Alert) IsVirtual() bool
- func (alert *Alert) String() string
- func (alert *Alert) WithHostID(hostID string) *Alert
- func (alert *Alert) WithReason(reason string) *Alert
- type AlertBasedSLI
- type AlertBasedSLIConfig
- type Alerts
- type App
- type Config
- type DataProvider
- type Definition
- func (d *Definition) AlertBasedSLIs(monitors []*Monitor) []*Monitor
- func (d *Definition) CreateReports(ctx context.Context, provider DataProvider, now time.Time, backfill int) ([]*Report, error)
- func (d *Definition) CreateReportsWithAlertsAndPeriod(ctx context.Context, alerts Alerts, startAt, endAt time.Time) ([]*Report, error)
- func (d *Definition) ID() string
- func (d *Definition) StartAt(now time.Time, backfill int) time.Time
- type Destination
- type DestinationConfig
- type DestinationMetricConfig
- type DestinationMetricType
- func (t DestinationMetricType) DefaultEnabled() bool
- func (t DestinationMetricType) DefaultTypeName() string
- func (t DestinationMetricType) ID() string
- func (i DestinationMetricType) IsADestinationMetricType() bool
- func (i DestinationMetricType) MarshalYAML() (interface{}, error)
- func (i DestinationMetricType) String() string
- func (i *DestinationMetricType) UnmarshalYAML(unmarshal func(interface{}) error) error
- type DryRunMackerelClient
- type IsNoViolationCollection
- type MackerelClient
- type Monitor
- func (m *Monitor) EvaluateReliabilities(hostID string, timeFrame time.Duration, startAt, endAt time.Time) (Reliabilities, bool)
- func (m *Monitor) ID() string
- func (m *Monitor) Name() string
- func (m *Monitor) String() string
- func (m *Monitor) Type() string
- func (m *Monitor) WithEvaluator(...) *Monitor
- type Options
- type Reliabilities
- func (c Reliabilities) CalcTime(cursor, n int) (upTime, failureTime, deltaFailureTime time.Duration)
- func (c Reliabilities) Clone() Reliabilities
- func (c Reliabilities) CursorAt(i int) time.Time
- func (c Reliabilities) Len() int
- func (c Reliabilities) Less(i, j int) bool
- func (c Reliabilities) Merge(other Reliabilities) (Reliabilities, error)
- func (c Reliabilities) MergeInRange(other Reliabilities, startAt, endAt time.Time) (Reliabilities, error)
- func (c Reliabilities) Swap(i, j int)
- func (c Reliabilities) TimeFrame() time.Duration
- type Reliability
- func (r *Reliability) Clone() *Reliability
- func (r *Reliability) CursorAt() time.Time
- func (r *Reliability) FailureTime() time.Duration
- func (r *Reliability) Merge(other *Reliability) (*Reliability, error)
- func (r *Reliability) TimeFrame() time.Duration
- func (r *Reliability) TimeFrameEndAt() time.Time
- func (r *Reliability) TimeFrameStartAt() time.Time
- func (r *Reliability) UpTime() time.Duration
- type Report
- func (r *Report) ErrorBudgetConsumptionRate() float64
- func (r *Report) ErrorBudgetUsageRate() float64
- func (r *Report) GetDestinationMetricValue(metricType DestinationMetricType) float64
- func (r *Report) MarshalJSON() ([]byte, error)
- func (r *Report) SetTime(upTime time.Duration, failureTime time.Duration, ...)
- func (r *Report) String() string
- type Repository
- func (repo *Repository) FetchAlerts(ctx context.Context, startAt time.Time, endAt time.Time) (Alerts, error)
- func (repo *Repository) FetchVirtualAlerts(ctx context.Context, serviceName string, sloID string, startAt time.Time, ...) (Alerts, error)
- func (repo *Repository) FindMonitors() ([]*Monitor, error)
- func (repo *Repository) GetOrgName(ctx context.Context) (string, error)
- func (repo *Repository) SaveReports(ctx context.Context, reports []*Report) error
- func (repo *Repository) WithDryRun() *Repository
- type SLOConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackfillOption ¶
BackfillOption specifies how many points of data to calculate retroactively from the current time.
func DestinationMetricTypeStrings ¶ added in v1.1.0
func DestinationMetricTypeStrings() []string
DestinationMetricTypeStrings returns a slice of all String values of the enum
func DryRunOption ¶
DryRunOption is an option to output the calculated error budget as standard without posting it to Mackerel.
func DumpReportsOption ¶ added in v1.0.0
Types ¶
type Alert ¶ added in v0.6.0
type Alert struct { Monitor *Monitor HostID string OpenedAt time.Time ClosedAt *time.Time Reason string // contains filtered or unexported fields }
func NewVirtualAlert ¶ added in v1.2.0
func (*Alert) CorrectionTime ¶ added in v0.7.0
func (*Alert) EvaluateReliabilities ¶ added in v0.7.0
func (*Alert) WithHostID ¶ added in v0.7.0
func (*Alert) WithReason ¶ added in v0.7.0
type AlertBasedSLI ¶ added in v1.0.0
type AlertBasedSLI struct {
// contains filtered or unexported fields
}
func NewAlertBasedSLI ¶ added in v1.0.0
func NewAlertBasedSLI(cfg *AlertBasedSLIConfig) *AlertBasedSLI
func (AlertBasedSLI) EvaluateReliabilities ¶ added in v1.0.0
func (o AlertBasedSLI) EvaluateReliabilities(timeFrame time.Duration, alerts Alerts, startAt, endAt time.Time) (Reliabilities, error)
func (AlertBasedSLI) MatchMonitor ¶ added in v1.0.0
func (o AlertBasedSLI) MatchMonitor(monitor *Monitor) bool
type AlertBasedSLIConfig ¶ added in v1.0.0
type AlertBasedSLIConfig struct { MonitorID string `json:"monitor_id,omitempty" yaml:"monitor_id,omitempty"` MonitorName string `json:"monitor_name,omitempty" yaml:"monitor_name,omitempty"` MonitorNamePrefix string `json:"monitor_name_prefix,omitempty" yaml:"monitor_name_prefix,omitempty"` MonitorNameSuffix string `json:"monitor_name_suffix,omitempty" yaml:"monitor_name_suffix,omitempty"` MonitorType string `json:"monitor_type,omitempty" yaml:"monitor_type,omitempty"` TryReassessment bool `json:"try_reassessment,omitempty" yaml:"try_reassessment,omitempty"` }
func (*AlertBasedSLIConfig) Restrict ¶ added in v1.0.0
func (c *AlertBasedSLIConfig) Restrict() error
Restrict restricts a configuration.
type App ¶
type App struct { SLODefinitions []*Definition // contains filtered or unexported fields }
App manages life cycle
func NewWithMackerelClient ¶
func NewWithMackerelClient(client MackerelClient, cfg *Config) (*App, error)
NewWithMackerelClient is there to accept mock clients.
type Config ¶
type Config struct { RequiredVersion string `yaml:"required_version" json:"required_version"` SLOConfig `yaml:"-,inline" json:"-,inline"` SLO []*SLOConfig `yaml:"slo" json:"slo"` // contains filtered or unexported fields }
Config for App
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
NewDefaultConfig creates a default configuration.
func (*Config) ValidateVersion ¶
ValidateVersion validates a version satisfies required_version.
type DataProvider ¶ added in v1.0.0
type Definition ¶
type Definition struct {
// contains filtered or unexported fields
}
Definition is SLO Definition
func NewDefinition ¶
func NewDefinition(cfg *SLOConfig) (*Definition, error)
NewDefinition creates Definition from SLOConfig
func (*Definition) AlertBasedSLIs ¶ added in v1.0.0
func (d *Definition) AlertBasedSLIs(monitors []*Monitor) []*Monitor
func (*Definition) CreateReports ¶ added in v0.5.0
func (d *Definition) CreateReports(ctx context.Context, provider DataProvider, now time.Time, backfill int) ([]*Report, error)
CreateReports returns Report with Metrics
func (*Definition) CreateReportsWithAlertsAndPeriod ¶ added in v1.0.0
type Destination ¶ added in v0.6.0
type Destination struct { ServiceName string MetricPrefix string MetricSuffix string MetricTypeNames map[DestinationMetricType]string MetricTypeEnabled map[DestinationMetricType]bool }
func NewDestination ¶ added in v1.1.0
func NewDestination(cfg *DestinationConfig) *Destination
func (*Destination) MetricEnabled ¶ added in v1.1.0
func (d *Destination) MetricEnabled(metricType DestinationMetricType) bool
func (*Destination) MetricName ¶ added in v1.1.0
func (d *Destination) MetricName(metricType DestinationMetricType) string
type DestinationConfig ¶ added in v1.0.0
type DestinationConfig struct { ServiceName string `json:"service_name" yaml:"service_name"` MetricPrefix string `json:"metric_prefix" yaml:"metric_prefix"` MetricSuffix string `json:"metric_suffix" yaml:"metric_suffix"` Metrics map[string]*DestinationMetricConfig `json:"metrics" yaml:"metrics"` }
DestinationConfig is a configuration for submitting service metrics to Mackerel
func (*DestinationConfig) Merge ¶ added in v1.0.0
func (c *DestinationConfig) Merge(o *DestinationConfig) *DestinationConfig
Merge merges DestinationConfig together
func (*DestinationConfig) Restrict ¶ added in v1.0.0
func (c *DestinationConfig) Restrict(sloID string) error
Restrict restricts a definition configuration.
type DestinationMetricConfig ¶ added in v1.1.0
type DestinationMetricConfig struct { MetricTypeName string `json:"metric_type_name,omitempty" yaml:"metric_type_name,omitempty"` Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"` }
func (*DestinationMetricConfig) Merge ¶ added in v1.1.0
func (c *DestinationMetricConfig) Merge(o *DestinationMetricConfig) *DestinationMetricConfig
Merge merges DestinationMetricConfig together
func (*DestinationMetricConfig) Restrict ¶ added in v1.1.0
func (c *DestinationMetricConfig) Restrict(t DestinationMetricType) error
Restrict restricts a definition configuration.
type DestinationMetricType ¶ added in v1.1.0
type DestinationMetricType int
const ( ErrorBudget DestinationMetricType = iota ErrorBudgetRemainingPercentage ErrorBudgetPercentage ErrorBudgetConsumption ErrorBudgetConsumptionPercentage UpTime //uptime FailureTime )
func DestinationMetricTypeString ¶ added in v1.1.0
func DestinationMetricTypeString(s string) (DestinationMetricType, error)
DestinationMetricTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func DestinationMetricTypeValues ¶ added in v1.1.0
func DestinationMetricTypeValues() []DestinationMetricType
DestinationMetricTypeValues returns all values of the enum
func (DestinationMetricType) DefaultEnabled ¶ added in v1.1.0
func (t DestinationMetricType) DefaultEnabled() bool
func (DestinationMetricType) DefaultTypeName ¶ added in v1.1.0
func (t DestinationMetricType) DefaultTypeName() string
func (DestinationMetricType) ID ¶ added in v1.1.0
func (t DestinationMetricType) ID() string
func (DestinationMetricType) IsADestinationMetricType ¶ added in v1.1.0
func (i DestinationMetricType) IsADestinationMetricType() bool
IsADestinationMetricType returns "true" if the value is listed in the enum definition. "false" otherwise
func (DestinationMetricType) MarshalYAML ¶ added in v1.1.0
func (i DestinationMetricType) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for DestinationMetricType
func (DestinationMetricType) String ¶ added in v1.1.0
func (i DestinationMetricType) String() string
func (*DestinationMetricType) UnmarshalYAML ¶ added in v1.1.0
func (i *DestinationMetricType) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for DestinationMetricType
type DryRunMackerelClient ¶ added in v0.6.1
type DryRunMackerelClient struct {
MackerelClient
}
func (DryRunMackerelClient) PostServiceMetricValues ¶ added in v0.6.1
func (c DryRunMackerelClient) PostServiceMetricValues(serviceName string, metricValues []*mackerel.MetricValue) error
type IsNoViolationCollection ¶ added in v0.6.0
func (IsNoViolationCollection) IsUp ¶ added in v0.6.0
func (c IsNoViolationCollection) IsUp(t time.Time) bool
func (IsNoViolationCollection) NewReliabilities ¶ added in v0.7.0
func (c IsNoViolationCollection) NewReliabilities(timeFrame time.Duration, startAt, endAt time.Time) (Reliabilities, error)
type MackerelClient ¶
type MackerelClient interface { GetOrg() (*mackerel.Org, error) FindHosts(param *mackerel.FindHostsParam) ([]*mackerel.Host, error) FetchHostMetricValues(hostID string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error) FetchServiceMetricValues(serviceName string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error) PostServiceMetricValues(serviceName string, metricValues []*mackerel.MetricValue) error FindWithClosedAlerts() (*mackerel.AlertsResp, error) FindWithClosedAlertsByNextID(nextID string) (*mackerel.AlertsResp, error) GetMonitor(monitorID string) (mackerel.Monitor, error) FindMonitors() ([]mackerel.Monitor, error) FindGraphAnnotations(service string, from int64, to int64) ([]*mackerel.GraphAnnotation, error) }
MackerelClient is an abstraction interface for mackerel-client-go.Client
type Monitor ¶ added in v0.6.0
type Monitor struct {
// contains filtered or unexported fields
}
func NewMonitor ¶ added in v0.7.0
func (*Monitor) EvaluateReliabilities ¶ added in v0.7.0
type Reliabilities ¶ added in v0.7.0
type Reliabilities []*Reliability
Reliabilities is sortable
func NewReliabilities ¶ added in v0.7.0
func NewReliabilities(s []*Reliability) (Reliabilities, error)
func (Reliabilities) CalcTime ¶ added in v0.7.0
func (c Reliabilities) CalcTime(cursor, n int) (upTime, failureTime, deltaFailureTime time.Duration)
func (Reliabilities) Clone ¶ added in v0.7.0
func (c Reliabilities) Clone() Reliabilities
func (Reliabilities) CursorAt ¶ added in v0.7.0
func (c Reliabilities) CursorAt(i int) time.Time
CursorAt is a representative value of the time shown by the tumbling window
func (Reliabilities) Len ¶ added in v0.7.0
func (c Reliabilities) Len() int
func (Reliabilities) Less ¶ added in v0.7.0
func (c Reliabilities) Less(i, j int) bool
func (Reliabilities) Merge ¶ added in v0.7.0
func (c Reliabilities) Merge(other Reliabilities) (Reliabilities, error)
Merge two collection
func (Reliabilities) MergeInRange ¶ added in v0.7.0
func (c Reliabilities) MergeInRange(other Reliabilities, startAt, endAt time.Time) (Reliabilities, error)
func (Reliabilities) Swap ¶ added in v0.7.0
func (c Reliabilities) Swap(i, j int)
func (Reliabilities) TimeFrame ¶ added in v0.7.0
func (c Reliabilities) TimeFrame() time.Duration
TimeFrame is the size of the tumbling window
type Reliability ¶ added in v0.6.0
type Reliability struct {
// contains filtered or unexported fields
}
Reliability represents a group of values related to reliability per tumbling window.
func NewReliability ¶ added in v0.6.0
func NewReliability(cursorAt time.Time, timeFrame time.Duration, isNoViolation IsNoViolationCollection) *Reliability
func (*Reliability) Clone ¶ added in v0.6.0
func (r *Reliability) Clone() *Reliability
func (*Reliability) CursorAt ¶ added in v0.6.0
func (r *Reliability) CursorAt() time.Time
CursorAt is a representative value of the time shown by the tumbling window
func (*Reliability) FailureTime ¶ added in v0.6.0
func (r *Reliability) FailureTime() time.Duration
FailureTime is the time when reliability could not be ensured, i.e. SLO was violated
func (*Reliability) Merge ¶ added in v0.6.0
func (r *Reliability) Merge(other *Reliability) (*Reliability, error)
Merge must be the same tumbling window
func (*Reliability) TimeFrame ¶ added in v0.6.0
func (r *Reliability) TimeFrame() time.Duration
TimeFrame is the size of the tumbling window
func (*Reliability) TimeFrameEndAt ¶ added in v0.6.0
func (r *Reliability) TimeFrameEndAt() time.Time
TimeFrameEndAt is the end time of the tumbling window
func (*Reliability) TimeFrameStartAt ¶ added in v0.6.0
func (r *Reliability) TimeFrameStartAt() time.Time
TimeFrameStartAt is the start time of the tumbling window
func (*Reliability) UpTime ¶ added in v0.6.0
func (r *Reliability) UpTime() time.Duration
UpTime is the uptime that can guarantee reliability.
type Report ¶
type Report struct { DefinitionID string Destination *Destination DataPoint time.Time TimeFrameStartAt time.Time TimeFrameEndAt time.Time UpTime time.Duration FailureTime time.Duration ErrorBudgetSize time.Duration ErrorBudget time.Duration ErrorBudgetConsumption time.Duration }
Report has SLI/SLO/ErrorBudget numbers in one rolling window
func NewReports ¶ added in v0.6.0
func NewReports(definitionID string, destination *Destination, errorBudgetSize float64, timeFrame time.Duration, reliability Reliabilities) []*Report
func (*Report) ErrorBudgetConsumptionRate ¶
ErrorBudgetConsumptionRate returns ErrorBudgetConsumption/ErrorBudgetSize
func (*Report) ErrorBudgetUsageRate ¶
ErrorBudgetUsageRate returns (1.0 - ErrorBudget/ErrorBudgetSize)
func (*Report) GetDestinationMetricValue ¶ added in v1.1.0
func (r *Report) GetDestinationMetricValue(metricType DestinationMetricType) float64
func (*Report) MarshalJSON ¶
MarshalJSON implements json.Marshaler
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository handles reading and writing data
func NewRepository ¶
func NewRepository(client MackerelClient) *Repository
NewRepository creates Repository
func (*Repository) FetchAlerts ¶ added in v0.6.0
func (repo *Repository) FetchAlerts(ctx context.Context, startAt time.Time, endAt time.Time) (Alerts, error)
FetchAlerts retrieves alerts for a specified period of time
func (*Repository) FetchVirtualAlerts ¶ added in v1.2.0
func (repo *Repository) FetchVirtualAlerts(ctx context.Context, serviceName string, sloID string, startAt time.Time, endAt time.Time) (Alerts, error)
FetchVirtualAlerts retrieves graph annotations for a specified time period and returns them as virtual alerts.
func (*Repository) FindMonitors ¶ added in v0.6.0
func (repo *Repository) FindMonitors() ([]*Monitor, error)
func (*Repository) GetOrgName ¶ added in v0.7.0
func (repo *Repository) GetOrgName(ctx context.Context) (string, error)
func (*Repository) SaveReports ¶
func (repo *Repository) SaveReports(ctx context.Context, reports []*Report) error
SaveReports posts Reports to Mackerel
func (*Repository) WithDryRun ¶ added in v0.6.1
func (repo *Repository) WithDryRun() *Repository
type SLOConfig ¶ added in v1.0.0
type SLOConfig struct { ID string `json:"id" yaml:"id"` RollingPeriod string `yaml:"rolling_period" json:"rolling_period"` Destination *DestinationConfig `yaml:"destination" json:"destination"` ErrorBudgetSize interface{} `yaml:"error_budget_size" json:"error_budget_size"` AlertBasedSLI []*AlertBasedSLIConfig `json:"alert_based_sli" yaml:"alert_based_sli"` CalculateInterval string `yaml:"calculate_interval" json:"calculate_interval"` // contains filtered or unexported fields }
SLOConfig is a setting related to SLI/SLO
func (*SLOConfig) DurationCalculate ¶ added in v1.0.0
DurationCalculate converts CalculateInterval as time.Duration
func (*SLOConfig) DurationRollingPeriod ¶ added in v1.0.0
DurationRollingPeriod converts RollingPeriod as time.Duration