From 8c5f16d18aa350c668e1aa050cf8a33b46e1afa2 Mon Sep 17 00:00:00 2001 From: Matt Dennison Date: Thu, 31 Oct 2024 14:36:53 -0700 Subject: [PATCH 1/3] fix: fix code gen and push crd changes --- CHANGELOG.md | 6 ++ ...loth.slok.dev_prometheusservicelevels.yaml | 5 ++ docker/dev/Dockerfile | 2 +- .../prometheus_rules_ensurer.go | 15 ++-- .../prometheus/prometheusmock/file_manager.go | 29 +++++-- pkg/kubernetes/api/sloth/v1/README.md | 79 ++++++++++--------- .../api/sloth/v1/zz_generated.deepcopy.go | 7 ++ ...loth.slok.dev_prometheusservicelevels.yaml | 5 ++ pkg/prometheus/alertwindows/v1/README.md | 12 +-- pkg/prometheus/api/v1/README.md | 38 +++++++-- 10 files changed, 131 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc04d42..48ecb497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [v0.13.1] - 2024-10-31 + +- Update Mockery from 2.14.0 to 2.46.3 +- Run `make go-gen` +- Run `make kube-gen` + ## [v0.13.0] - 2024-10-31 - Fix buildvcs issues with test scripts diff --git a/deploy/kubernetes/helm/sloth/crds/sloth.slok.dev_prometheusservicelevels.yaml b/deploy/kubernetes/helm/sloth/crds/sloth.slok.dev_prometheusservicelevels.yaml index 7283e667..107ee882 100644 --- a/deploy/kubernetes/helm/sloth/crds/sloth.slok.dev_prometheusservicelevels.yaml +++ b/deploy/kubernetes/helm/sloth/crds/sloth.slok.dev_prometheusservicelevels.yaml @@ -148,6 +148,11 @@ spec: description: description: Description is the description of the SLO. type: string + infoLabels: + additionalProperties: + type: string + description: Info labels added to the `sloth_slo_info` metric + type: object labels: additionalProperties: type: string diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 0c7bf9db..53a5c9c4 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -3,7 +3,7 @@ FROM golang:1.23 LABEL org.opencontainers.image.source https://github.com/slok/sloth ARG GOLANGCI_LINT_VERSION="1.61.0" -ARG MOCKERY_VERSION="2.14.0" +ARG MOCKERY_VERSION="2.46.3" ARG GOMARKDOC_VERSION="0.4.1" ARG HELM_VERSION="3.10.0" ARG ostype=Linux diff --git a/internal/k8sprometheus/k8sprometheusmock/prometheus_rules_ensurer.go b/internal/k8sprometheus/k8sprometheusmock/prometheus_rules_ensurer.go index f8995be0..b243ff9b 100644 --- a/internal/k8sprometheus/k8sprometheusmock/prometheus_rules_ensurer.go +++ b/internal/k8sprometheus/k8sprometheusmock/prometheus_rules_ensurer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package k8sprometheusmock @@ -19,6 +19,10 @@ type PrometheusRulesEnsurer struct { func (_m *PrometheusRulesEnsurer) EnsurePrometheusRule(ctx context.Context, pr *v1.PrometheusRule) error { ret := _m.Called(ctx, pr) + if len(ret) == 0 { + panic("no return value specified for EnsurePrometheusRule") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *v1.PrometheusRule) error); ok { r0 = rf(ctx, pr) @@ -29,13 +33,12 @@ func (_m *PrometheusRulesEnsurer) EnsurePrometheusRule(ctx context.Context, pr * return r0 } -type mockConstructorTestingTNewPrometheusRulesEnsurer interface { +// NewPrometheusRulesEnsurer creates a new instance of PrometheusRulesEnsurer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPrometheusRulesEnsurer(t interface { mock.TestingT Cleanup(func()) -} - -// NewPrometheusRulesEnsurer creates a new instance of PrometheusRulesEnsurer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewPrometheusRulesEnsurer(t mockConstructorTestingTNewPrometheusRulesEnsurer) *PrometheusRulesEnsurer { +}) *PrometheusRulesEnsurer { mock := &PrometheusRulesEnsurer{} mock.Mock.Test(t) diff --git a/internal/prometheus/prometheusmock/file_manager.go b/internal/prometheus/prometheusmock/file_manager.go index 703008ed..8fbb5557 100644 --- a/internal/prometheus/prometheusmock/file_manager.go +++ b/internal/prometheus/prometheusmock/file_manager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.46.3. DO NOT EDIT. package prometheusmock @@ -19,7 +19,15 @@ type FileManager struct { func (_m *FileManager) FindFiles(ctx context.Context, root string, matcher *regexp.Regexp) ([]string, error) { ret := _m.Called(ctx, root, matcher) + if len(ret) == 0 { + panic("no return value specified for FindFiles") + } + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, *regexp.Regexp) ([]string, error)); ok { + return rf(ctx, root, matcher) + } if rf, ok := ret.Get(0).(func(context.Context, string, *regexp.Regexp) []string); ok { r0 = rf(ctx, root, matcher) } else { @@ -28,7 +36,6 @@ func (_m *FileManager) FindFiles(ctx context.Context, root string, matcher *rege } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, *regexp.Regexp) error); ok { r1 = rf(ctx, root, matcher) } else { @@ -42,7 +49,15 @@ func (_m *FileManager) FindFiles(ctx context.Context, root string, matcher *rege func (_m *FileManager) ReadFile(ctx context.Context, path string) ([]byte, error) { ret := _m.Called(ctx, path) + if len(ret) == 0 { + panic("no return value specified for ReadFile") + } + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]byte, error)); ok { + return rf(ctx, path) + } if rf, ok := ret.Get(0).(func(context.Context, string) []byte); ok { r0 = rf(ctx, path) } else { @@ -51,7 +66,6 @@ func (_m *FileManager) ReadFile(ctx context.Context, path string) ([]byte, error } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, path) } else { @@ -61,13 +75,12 @@ func (_m *FileManager) ReadFile(ctx context.Context, path string) ([]byte, error return r0, r1 } -type mockConstructorTestingTNewFileManager interface { +// NewFileManager creates a new instance of FileManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFileManager(t interface { mock.TestingT Cleanup(func()) -} - -// NewFileManager creates a new instance of FileManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewFileManager(t mockConstructorTestingTNewFileManager) *FileManager { +}) *FileManager { mock := &FileManager{} mock.Mock.Test(t) diff --git a/pkg/kubernetes/api/sloth/v1/README.md b/pkg/kubernetes/api/sloth/v1/README.md index 46ef875c..607d255c 100755 --- a/pkg/kubernetes/api/sloth/v1/README.md +++ b/pkg/kubernetes/api/sloth/v1/README.md @@ -66,7 +66,7 @@ SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: sloth.GroupName, Version: version} ``` -## func Kind +## func [Kind]() ```go func Kind(kind string) schema.GroupKind @@ -74,7 +74,7 @@ func Kind(kind string) schema.GroupKind Kind takes an unqualified kind and returns back a Group qualified GroupKind. -## func Resource +## func [Resource]() ```go func Resource(resource string) schema.GroupResource @@ -82,7 +82,7 @@ func Resource(resource string) schema.GroupResource Resource takes an unqualified resource and returns a Group qualified GroupResource. -## func VersionKind +## func [VersionKind]() ```go func VersionKind(kind string) schema.GroupVersionKind @@ -90,7 +90,7 @@ func VersionKind(kind string) schema.GroupVersionKind VersionKind takes an unqualified kind and returns back a Group qualified GroupVersionKind. -## type Alert +## type [Alert]() Alert configures specific SLO alert. @@ -111,7 +111,7 @@ type Alert struct { } ``` -### func \(\*Alert\) DeepCopy +### func \(\*Alert\) [DeepCopy]() ```go func (in *Alert) DeepCopy() *Alert @@ -119,7 +119,7 @@ func (in *Alert) DeepCopy() *Alert DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Alert. -### func \(\*Alert\) DeepCopyInto +### func \(\*Alert\) [DeepCopyInto]() ```go func (in *Alert) DeepCopyInto(out *Alert) @@ -127,7 +127,7 @@ func (in *Alert) DeepCopyInto(out *Alert) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type Alerting +## type [Alerting]() Alerting wraps all the configuration required by the SLO alerts. @@ -154,7 +154,7 @@ type Alerting struct { } ``` -### func \(\*Alerting\) DeepCopy +### func \(\*Alerting\) [DeepCopy]() ```go func (in *Alerting) DeepCopy() *Alerting @@ -162,7 +162,7 @@ func (in *Alerting) DeepCopy() *Alerting DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Alerting. -### func \(\*Alerting\) DeepCopyInto +### func \(\*Alerting\) [DeepCopyInto]() ```go func (in *Alerting) DeepCopyInto(out *Alerting) @@ -170,7 +170,7 @@ func (in *Alerting) DeepCopyInto(out *Alerting) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type PrometheusServiceLevel +## type [PrometheusServiceLevel]() \+genclient \+k8s:deepcopy\-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object \+kubebuilder:subresource:status \+kubebuilder:printcolumn:name="SERVICE",type="string",JSONPath=".spec.service" \+kubebuilder:printcolumn:name="DESIRED SLOs",type="integer",JSONPath=".status.processedSLOs" \+kubebuilder:printcolumn:name="READY SLOs",type="integer",JSONPath=".status.promOpRulesGeneratedSLOs" \+kubebuilder:printcolumn:name="GEN OK",type="boolean",JSONPath=".status.promOpRulesGenerated" \+kubebuilder:printcolumn:name="GEN AGE",type="date",JSONPath=".status.lastPromOpRulesSuccessfulGenerated" \+kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" \+kubebuilder:resource:singular=prometheusservicelevel,path=prometheusservicelevels,shortName=psl;pslo,scope=Namespaced,categories=slo;slos;sli;slis @@ -186,7 +186,7 @@ type PrometheusServiceLevel struct { } ``` -### func \(\*PrometheusServiceLevel\) DeepCopy +### func \(\*PrometheusServiceLevel\) [DeepCopy]() ```go func (in *PrometheusServiceLevel) DeepCopy() *PrometheusServiceLevel @@ -194,7 +194,7 @@ func (in *PrometheusServiceLevel) DeepCopy() *PrometheusServiceLevel DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusServiceLevel. -### func \(\*PrometheusServiceLevel\) DeepCopyInto +### func \(\*PrometheusServiceLevel\) [DeepCopyInto]() ```go func (in *PrometheusServiceLevel) DeepCopyInto(out *PrometheusServiceLevel) @@ -202,7 +202,7 @@ func (in *PrometheusServiceLevel) DeepCopyInto(out *PrometheusServiceLevel) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -### func \(\*PrometheusServiceLevel\) DeepCopyObject +### func \(\*PrometheusServiceLevel\) [DeepCopyObject]() ```go func (in *PrometheusServiceLevel) DeepCopyObject() runtime.Object @@ -210,7 +210,7 @@ func (in *PrometheusServiceLevel) DeepCopyObject() runtime.Object DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -## type PrometheusServiceLevelList +## type [PrometheusServiceLevelList]() \+k8s:deepcopy\-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -225,7 +225,7 @@ type PrometheusServiceLevelList struct { } ``` -### func \(\*PrometheusServiceLevelList\) DeepCopy +### func \(\*PrometheusServiceLevelList\) [DeepCopy]() ```go func (in *PrometheusServiceLevelList) DeepCopy() *PrometheusServiceLevelList @@ -233,7 +233,7 @@ func (in *PrometheusServiceLevelList) DeepCopy() *PrometheusServiceLevelList DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusServiceLevelList. -### func \(\*PrometheusServiceLevelList\) DeepCopyInto +### func \(\*PrometheusServiceLevelList\) [DeepCopyInto]() ```go func (in *PrometheusServiceLevelList) DeepCopyInto(out *PrometheusServiceLevelList) @@ -241,7 +241,7 @@ func (in *PrometheusServiceLevelList) DeepCopyInto(out *PrometheusServiceLevelLi DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -### func \(\*PrometheusServiceLevelList\) DeepCopyObject +### func \(\*PrometheusServiceLevelList\) [DeepCopyObject]() ```go func (in *PrometheusServiceLevelList) DeepCopyObject() runtime.Object @@ -249,7 +249,7 @@ func (in *PrometheusServiceLevelList) DeepCopyObject() runtime.Object DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -## type PrometheusServiceLevelSpec +## type [PrometheusServiceLevelSpec]() ServiceLevelSpec is the spec for a PrometheusServiceLevel. @@ -271,7 +271,7 @@ type PrometheusServiceLevelSpec struct { } ``` -### func \(\*PrometheusServiceLevelSpec\) DeepCopy +### func \(\*PrometheusServiceLevelSpec\) [DeepCopy]() ```go func (in *PrometheusServiceLevelSpec) DeepCopy() *PrometheusServiceLevelSpec @@ -279,7 +279,7 @@ func (in *PrometheusServiceLevelSpec) DeepCopy() *PrometheusServiceLevelSpec DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusServiceLevelSpec. -### func \(\*PrometheusServiceLevelSpec\) DeepCopyInto +### func \(\*PrometheusServiceLevelSpec\) [DeepCopyInto]() ```go func (in *PrometheusServiceLevelSpec) DeepCopyInto(out *PrometheusServiceLevelSpec) @@ -287,7 +287,7 @@ func (in *PrometheusServiceLevelSpec) DeepCopyInto(out *PrometheusServiceLevelSp DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type PrometheusServiceLevelStatus +## type [PrometheusServiceLevelStatus]() ```go type PrometheusServiceLevelStatus struct { @@ -307,7 +307,7 @@ type PrometheusServiceLevelStatus struct { } ``` -### func \(\*PrometheusServiceLevelStatus\) DeepCopy +### func \(\*PrometheusServiceLevelStatus\) [DeepCopy]() ```go func (in *PrometheusServiceLevelStatus) DeepCopy() *PrometheusServiceLevelStatus @@ -315,7 +315,7 @@ func (in *PrometheusServiceLevelStatus) DeepCopy() *PrometheusServiceLevelStatus DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusServiceLevelStatus. -### func \(\*PrometheusServiceLevelStatus\) DeepCopyInto +### func \(\*PrometheusServiceLevelStatus\) [DeepCopyInto]() ```go func (in *PrometheusServiceLevelStatus) DeepCopyInto(out *PrometheusServiceLevelStatus) @@ -323,7 +323,7 @@ func (in *PrometheusServiceLevelStatus) DeepCopyInto(out *PrometheusServiceLevel DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type SLI +## type [SLI]() SLI will tell what is good or bad for the SLO. All SLIs will be get based on time windows, that's why Sloth needs the queries to use \`\{\{.window\}\}\` template variable. @@ -345,7 +345,7 @@ type SLI struct { } ``` -### func \(\*SLI\) DeepCopy +### func \(\*SLI\) [DeepCopy]() ```go func (in *SLI) DeepCopy() *SLI @@ -353,7 +353,7 @@ func (in *SLI) DeepCopy() *SLI DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SLI. -### func \(\*SLI\) DeepCopyInto +### func \(\*SLI\) [DeepCopyInto]() ```go func (in *SLI) DeepCopyInto(out *SLI) @@ -361,7 +361,7 @@ func (in *SLI) DeepCopyInto(out *SLI) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type SLIEvents +## type [SLIEvents]() SLIEvents is an SLI that is calculated as the division of bad events and total events, giving a ratio SLI. Normally this is the most common ratio type. @@ -379,7 +379,7 @@ type SLIEvents struct { } ``` -### func \(\*SLIEvents\) DeepCopy +### func \(\*SLIEvents\) [DeepCopy]() ```go func (in *SLIEvents) DeepCopy() *SLIEvents @@ -387,7 +387,7 @@ func (in *SLIEvents) DeepCopy() *SLIEvents DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SLIEvents. -### func \(\*SLIEvents\) DeepCopyInto +### func \(\*SLIEvents\) [DeepCopyInto]() ```go func (in *SLIEvents) DeepCopyInto(out *SLIEvents) @@ -395,7 +395,7 @@ func (in *SLIEvents) DeepCopyInto(out *SLIEvents) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type SLIPlugin +## type [SLIPlugin]() SLIPlugin will use the SLI returned by the SLI plugin selected along with the options. @@ -410,7 +410,7 @@ type SLIPlugin struct { } ``` -### func \(\*SLIPlugin\) DeepCopy +### func \(\*SLIPlugin\) [DeepCopy]() ```go func (in *SLIPlugin) DeepCopy() *SLIPlugin @@ -418,7 +418,7 @@ func (in *SLIPlugin) DeepCopy() *SLIPlugin DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SLIPlugin. -### func \(\*SLIPlugin\) DeepCopyInto +### func \(\*SLIPlugin\) [DeepCopyInto]() ```go func (in *SLIPlugin) DeepCopyInto(out *SLIPlugin) @@ -426,7 +426,7 @@ func (in *SLIPlugin) DeepCopyInto(out *SLIPlugin) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type SLIRaw +## type [SLIRaw]() SLIRaw is a error ratio SLI already calculated. Normally this will be used when the SLI is already calculated by other recording rule, system... @@ -437,7 +437,7 @@ type SLIRaw struct { } ``` -### func \(\*SLIRaw\) DeepCopy +### func \(\*SLIRaw\) [DeepCopy]() ```go func (in *SLIRaw) DeepCopy() *SLIRaw @@ -445,7 +445,7 @@ func (in *SLIRaw) DeepCopy() *SLIRaw DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SLIRaw. -### func \(\*SLIRaw\) DeepCopyInto +### func \(\*SLIRaw\) [DeepCopyInto]() ```go func (in *SLIRaw) DeepCopyInto(out *SLIRaw) @@ -453,7 +453,7 @@ func (in *SLIRaw) DeepCopyInto(out *SLIRaw) DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non\-nil. -## type SLO +## type [SLO]() SLO is the configuration/declaration of the service level objective of a service. @@ -480,6 +480,9 @@ type SLO struct { // +optional Labels map[string]string `json:"labels,omitempty"` + // Info labels added to the `sloth_slo_info` metric + InfoLabels map[string]string `json:"infoLabels,omitempty"` + // +kubebuilder:validation:Required // // SLI is the indicator (service level indicator) for this specific SLO. @@ -493,7 +496,7 @@ type SLO struct { } ``` -### func \(\*SLO\) DeepCopy +### func \(\*SLO\) [DeepCopy]() ```go func (in *SLO) DeepCopy() *SLO @@ -501,7 +504,7 @@ func (in *SLO) DeepCopy() *SLO DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SLO. -### func \(\*SLO\) DeepCopyInto +### func \(\*SLO\) [DeepCopyInto]() ```go func (in *SLO) DeepCopyInto(out *SLO) diff --git a/pkg/kubernetes/api/sloth/v1/zz_generated.deepcopy.go b/pkg/kubernetes/api/sloth/v1/zz_generated.deepcopy.go index ea5cdfb9..a7380b6b 100644 --- a/pkg/kubernetes/api/sloth/v1/zz_generated.deepcopy.go +++ b/pkg/kubernetes/api/sloth/v1/zz_generated.deepcopy.go @@ -278,6 +278,13 @@ func (in *SLO) DeepCopyInto(out *SLO) { (*out)[key] = val } } + if in.InfoLabels != nil { + in, out := &in.InfoLabels, &out.InfoLabels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } in.SLI.DeepCopyInto(&out.SLI) in.Alerting.DeepCopyInto(&out.Alerting) return diff --git a/pkg/kubernetes/gen/crd/sloth.slok.dev_prometheusservicelevels.yaml b/pkg/kubernetes/gen/crd/sloth.slok.dev_prometheusservicelevels.yaml index 7283e667..107ee882 100644 --- a/pkg/kubernetes/gen/crd/sloth.slok.dev_prometheusservicelevels.yaml +++ b/pkg/kubernetes/gen/crd/sloth.slok.dev_prometheusservicelevels.yaml @@ -148,6 +148,11 @@ spec: description: description: Description is the description of the SLO. type: string + infoLabels: + additionalProperties: + type: string + description: Info labels added to the `sloth_slo_info` metric + type: object labels: additionalProperties: type: string diff --git a/pkg/prometheus/alertwindows/v1/README.md b/pkg/prometheus/alertwindows/v1/README.md index 09544ab2..ba4090f7 100755 --- a/pkg/prometheus/alertwindows/v1/README.md +++ b/pkg/prometheus/alertwindows/v1/README.md @@ -27,7 +27,7 @@ const APIVersion = "sloth.slok.dev/v1" const Kind = "AlertWindows" ``` -## type AlertWindows +## type [AlertWindows]() ```go type AlertWindows struct { @@ -37,7 +37,7 @@ type AlertWindows struct { } ``` -## type PageWindow +## type [PageWindow]() PageWindow represents the configuration for page alerting. @@ -47,7 +47,7 @@ type PageWindow struct { } ``` -## type QuickSlowWindow +## type [QuickSlowWindow]() ```go type QuickSlowWindow struct { @@ -58,7 +58,7 @@ type QuickSlowWindow struct { } ``` -## type Spec +## type [Spec]() Spec represents the root type of the Alerting window. @@ -73,7 +73,7 @@ type Spec struct { } ``` -## type TicketWindow +## type [TicketWindow]() PageWindow represents the configuration for ticket alerting. @@ -83,7 +83,7 @@ type TicketWindow struct { } ``` -## type Window +## type [Window]() ```go type Window struct { diff --git a/pkg/prometheus/api/v1/README.md b/pkg/prometheus/api/v1/README.md index ab419d3d..49846d24 100755 --- a/pkg/prometheus/api/v1/README.md +++ b/pkg/prometheus/api/v1/README.md @@ -68,6 +68,7 @@ slos: - [Constants](<#constants>) - [type Alert](<#type-alert>) - [type Alerting](<#type-alerting>) +- [type Interval](<#type-interval>) - [type SLI](<#type-sli>) - [type SLIEvents](<#type-slievents>) - [type SLIPlugin](<#type-sliplugin>) @@ -82,7 +83,7 @@ slos: const Version = "prometheus/v1" ``` -## type Alert +## type [Alert]() Alert configures specific SLO alert. @@ -99,7 +100,7 @@ type Alert struct { } ``` -## type Alerting +## type [Alerting]() Alerting wraps all the configuration required by the SLO alerts. @@ -119,7 +120,23 @@ type Alerting struct { } ``` -## type SLI +## type [Interval]() + +```go +type Interval struct { + // RuleGroupInterval is an optional value for how often the Prometheus rule_group should be evaluated. + // RuleGroupInterval string `yaml:"rulegroup_interval,omitempty"` + RuleGroupInterval time.Duration `yaml:"all,omitempty"` + // Otherwise, specify custom rule_group intervals for each set of recording rules. + // RuleGroupInterval will "fill-in" for any non-specified individual groups + // but individual group settings override RuleGroupInterval. + SLIErrorRulesInterval time.Duration `yaml:"slierror,omitempty"` + MetadataRulesInterval time.Duration `yaml:"metadata,omitempty"` + AlertRulesInterval time.Duration `yaml:"alert,omitempty"` +} +``` + +## type [SLI]() SLI will tell what is good or bad for the SLO. All SLIs will be get based on time windows, that's why Sloth needs the queries to use \`\{\{.window\}\}\` template variable. @@ -136,7 +153,7 @@ type SLI struct { } ``` -## type SLIEvents +## type [SLIEvents]() SLIEvents is an SLI that is calculated as the division of bad events and total events, giving a ratio SLI. Normally this is the most common ratio type. @@ -153,7 +170,7 @@ type SLIEvents struct { } ``` -## type SLIPlugin +## type [SLIPlugin]() SLIPlugin will use the SLI returned by the SLI plugin selected along with the options. @@ -166,7 +183,7 @@ type SLIPlugin struct { } ``` -## type SLIRaw +## type [SLIRaw]() SLIRaw is a error ratio SLI already calculated. Normally this will be used when the SLI is already calculated by other recording rule, system... @@ -177,7 +194,7 @@ type SLIRaw struct { } ``` -## type SLO +## type [SLO]() SLO is the configuration/declaration of the service level objective of a service. @@ -193,15 +210,20 @@ type SLO struct { // alerting rules for this specific SLO. These labels are merged with the // previous level labels. Labels map[string]string `yaml:"labels,omitempty"` + // Labels appended to `sloth_slo_info` + InfoLabels map[string]string `yaml:"infoLabels,omitempty"` // SLI is the indicator (service level indicator) for this specific SLO. SLI SLI `yaml:"sli"` // Alerting is the configuration with all the things related with the SLO // alerts. Alerting Alerting `yaml:"alerting"` + // Interval is the configuration for all things related to SLO rule_group intervals + // for specific rule groups and all rules. + Interval Interval `yaml:"interval,omitempty"` } ``` -## type Spec +## type [Spec]() Spec represents the root type of the SLOs declaration specification. From 42c4f87c11c7e0b58c4857d6ded483f317e56691 Mon Sep 17 00:00:00 2001 From: Matt Dennison Date: Thu, 31 Oct 2024 14:50:40 -0700 Subject: [PATCH 2/3] chore: examples, chart and image version bump --- CHANGELOG.md | 3 + deploy/kubernetes/helm/sloth/Chart.yaml | 2 +- deploy/kubernetes/helm/sloth/values.yaml | 2 +- examples/_gen/custom_rule_group_interval.yml | 242 +++++++++++++++++++ 4 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 examples/_gen/custom_rule_group_interval.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ecb497..62299484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - Update Mockery from 2.14.0 to 2.46.3 - Run `make go-gen` - Run `make kube-gen` +- Run `make examples-gen` +- Bump Helm Chart version from 0.8.1 to 0.8.2 +- Bump image version from v0.13.0 to v0.13.1 ## [v0.13.0] - 2024-10-31 diff --git a/deploy/kubernetes/helm/sloth/Chart.yaml b/deploy/kubernetes/helm/sloth/Chart.yaml index f4c2a6ab..095d93bc 100644 --- a/deploy/kubernetes/helm/sloth/Chart.yaml +++ b/deploy/kubernetes/helm/sloth/Chart.yaml @@ -4,4 +4,4 @@ description: Base chart for Sloth. type: application home: https://github.com/linode-obs/sloth kubeVersion: ">= 1.19.0-0" -version: 0.8.1 +version: 0.8.2 diff --git a/deploy/kubernetes/helm/sloth/values.yaml b/deploy/kubernetes/helm/sloth/values.yaml index 26b38422..357b83fe 100644 --- a/deploy/kubernetes/helm/sloth/values.yaml +++ b/deploy/kubernetes/helm/sloth/values.yaml @@ -2,7 +2,7 @@ labels: {} image: repository: ghcr.io/linode-obs/sloth - tag: v0.13.0 + tag: v0.13.1 # -- Container resources: requests and limits for CPU, Memory resources: diff --git a/examples/_gen/custom_rule_group_interval.yml b/examples/_gen/custom_rule_group_interval.yml new file mode 100644 index 00000000..d780edc3 --- /dev/null +++ b/examples/_gen/custom_rule_group_interval.yml @@ -0,0 +1,242 @@ + +--- +# Code generated by Sloth (dev): https://github.com/slok/sloth. +# DO NOT EDIT. + +groups: +- name: sloth-slo-sli-recordings-myapp-cpu-availability + interval: 4m + rules: + - record: slo:sli_error:ratio_rate5m + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[5m]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[5m]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 5m + - record: slo:sli_error:ratio_rate30m + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[30m]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[30m]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 30m + - record: slo:sli_error:ratio_rate1h + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[1h]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[1h]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 1h + - record: slo:sli_error:ratio_rate2h + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[2h]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[2h]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 2h + - record: slo:sli_error:ratio_rate6h + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[6h]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[6h]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 6h + - record: slo:sli_error:ratio_rate1d + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[1d]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[1d]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 1d + - record: slo:sli_error:ratio_rate3d + expr: | + (sum( + rate(node_cpu_seconds_total{mode="softirq"}[3d]) + ) + ) + / + (sum( + rate(node_cpu_seconds_total[3d]) + ) + ) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 3d + - record: slo:sli_error:ratio_rate30d + expr: | + sum_over_time(slo:sli_error:ratio_rate5m{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"}[30d]) + / ignoring (sloth_window) + count_over_time(slo:sli_error:ratio_rate5m{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"}[30d]) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + sloth_window: 30d +- name: sloth-slo-meta-recordings-myapp-cpu-availability + interval: 2m + rules: + - record: slo:objective:ratio + expr: vector(0.9998999999999999) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: slo:error_budget:ratio + expr: vector(1-0.9998999999999999) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: slo:time_period:days + expr: vector(30) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: slo:current_burn_rate:ratio + expr: | + slo:sli_error:ratio_rate5m{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} + / on(sloth_id, sloth_slo, sloth_service) group_left + slo:error_budget:ratio{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: slo:period_burn_rate:ratio + expr: | + slo:sli_error:ratio_rate30d{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} + / on(sloth_id, sloth_slo, sloth_service) group_left + slo:error_budget:ratio{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: slo:period_error_budget_remaining:ratio + expr: 1 - slo:period_burn_rate:ratio{sloth_id="myapp-cpu-availability", sloth_service="myapp", + sloth_slo="cpu-availability"} + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_service: myapp + sloth_slo: cpu-availability + - record: sloth_slo_info + expr: vector(1) + labels: + cmd: examplesgen.sh + owner: myteam + sloth_id: myapp-cpu-availability + sloth_mode: cli-gen-prom + sloth_objective: "99.99" + sloth_service: myapp + sloth_slo: cpu-availability + sloth_spec: prometheus/v1 + sloth_version: dev +- name: sloth-slo-alerts-myapp-cpu-availability + interval: 2m + rules: + - alert: MyServiceHighErrorRate + expr: | + ( + max(slo:sli_error:ratio_rate5m{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} > (14.4 * 0.00010000000000005117)) without (sloth_window) + and + max(slo:sli_error:ratio_rate1h{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} > (14.4 * 0.00010000000000005117)) without (sloth_window) + ) + or + ( + max(slo:sli_error:ratio_rate30m{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} > (6 * 0.00010000000000005117)) without (sloth_window) + and + max(slo:sli_error:ratio_rate6h{sloth_id="myapp-cpu-availability", sloth_service="myapp", sloth_slo="cpu-availability"} > (6 * 0.00010000000000005117)) without (sloth_window) + ) + labels: + category: availability + routing_key: myteam + severity: pageteam + sloth_severity: page + annotations: + summary: High error rate on 'myservice' requests responses + title: (page) {{$labels.sloth_service}} {{$labels.sloth_slo}} SLO error budget + burn rate is too fast. From 0fe26031029c3b1d4c43767e0d50043fb0661437 Mon Sep 17 00:00:00 2001 From: Matt Dennison Date: Thu, 31 Oct 2024 14:55:55 -0700 Subject: [PATCH 3/3] fix: fix default version in test --- .../helm/sloth/tests/testdata/output/deployment_default.yaml | 2 +- deploy/kubernetes/raw/sloth-with-common-plugins.yaml | 2 +- deploy/kubernetes/raw/sloth.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy/kubernetes/helm/sloth/tests/testdata/output/deployment_default.yaml b/deploy/kubernetes/helm/sloth/tests/testdata/output/deployment_default.yaml index 1602755a..9425fd59 100644 --- a/deploy/kubernetes/helm/sloth/tests/testdata/output/deployment_default.yaml +++ b/deploy/kubernetes/helm/sloth/tests/testdata/output/deployment_default.yaml @@ -32,7 +32,7 @@ spec: serviceAccountName: sloth containers: - name: sloth - image: ghcr.io/linode-obs/sloth:v0.13.0 + image: ghcr.io/linode-obs/sloth:v0.13.1 args: - kubernetes-controller - --sli-plugins-path=/plugins diff --git a/deploy/kubernetes/raw/sloth-with-common-plugins.yaml b/deploy/kubernetes/raw/sloth-with-common-plugins.yaml index 93ec8c37..dfd0a983 100644 --- a/deploy/kubernetes/raw/sloth-with-common-plugins.yaml +++ b/deploy/kubernetes/raw/sloth-with-common-plugins.yaml @@ -85,7 +85,7 @@ spec: serviceAccountName: sloth containers: - name: sloth - image: ghcr.io/linode-obs/sloth:v0.13.0 + image: ghcr.io/linode-obs/sloth:v0.13.1 args: - kubernetes-controller - --sli-plugins-path=/plugins diff --git a/deploy/kubernetes/raw/sloth.yaml b/deploy/kubernetes/raw/sloth.yaml index 9a8f9a09..84476298 100644 --- a/deploy/kubernetes/raw/sloth.yaml +++ b/deploy/kubernetes/raw/sloth.yaml @@ -85,7 +85,7 @@ spec: serviceAccountName: sloth containers: - name: sloth - image: ghcr.io/linode-obs/sloth:v0.13.0 + image: ghcr.io/linode-obs/sloth:v0.13.1 args: - kubernetes-controller ports: