Skip to content

Commit

Permalink
Merge branch 'main' into PC-14087-add-slo-status-api-to-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
BSski committed Sep 17, 2024
2 parents dd87a96 + c087415 commit 505da92
Show file tree
Hide file tree
Showing 52 changed files with 1,106 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GOLANGCI_LINT_VERSION := v1.60.1
# renovate datasource=go depName=golang.org/x/vuln/cmd/govulncheck
GOVULNCHECK_VERSION := v1.1.3
# renovate datasource=go depName=golang.org/x/tools/cmd/goimports
GOIMPORTS_VERSION := v0.24.0
GOIMPORTS_VERSION := v0.25.0
# renovate datasource=go depName=github.com/vburenin/ifacemaker
IFACEMAKER_VERSION := v1.2.1

Expand Down
6 changes: 6 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ ignorePaths:
- "docs/mock_example/mocks/*"
words:
- 00u2y4e4atkzaYkXP4x8
- BYHOUR
- BYMINUTE
- BYSECOND
- CONNECTIONFAILURES
- CONNECTIONSESTABLISHED
- CONNECTIONSUCCESSES
- DTSTART
- DzpxcSRh
- MAXRTT
- TIMEMAX
Expand All @@ -51,6 +55,7 @@ words:
- awsiam
- budgetadjustment
- byday
- bysecond
- clientcreds
- codeowners
- consumergroup
Expand All @@ -65,6 +70,7 @@ words:
- devel
- dnssec
- doublestar
- dtstart
- dynatrace
- endef
- enduml
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.22

require (
github.com/BurntSushi/toml v1.4.0
github.com/MicahParks/jwkset v0.5.18
github.com/MicahParks/keyfunc/v3 v3.3.3
github.com/MicahParks/jwkset v0.5.19
github.com/MicahParks/keyfunc/v3 v3.3.5
github.com/aws/aws-sdk-go v1.55.5
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/goccy/go-yaml v1.12.0
Expand All @@ -18,7 +18,7 @@ require (
github.com/teambition/rrule-go v1.8.2
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/sync v0.8.0
golang.org/x/text v0.17.0
golang.org/x/text v0.18.0
golang.org/x/time v0.6.0
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/MicahParks/jwkset v0.5.18 h1:WLdyMngF7rCrnstQxA7mpRoxeaWqGzPM/0z40PJUK4w=
github.com/MicahParks/jwkset v0.5.18/go.mod h1:q8ptTGn/Z9c4MwbcfeCDssADeVQb3Pk7PnVxrvi+2QY=
github.com/MicahParks/keyfunc/v3 v3.3.3 h1:c6j9oSu1YUo0k//KwF1miIQlEMtqNlj7XBFLB8jtEmY=
github.com/MicahParks/keyfunc/v3 v3.3.3/go.mod h1:f/UMyXdKfkZzmBeBFUeYk+zu066J1Fcl48f7Wnl5Z48=
github.com/MicahParks/jwkset v0.5.19 h1:XZCsgJv05DBCvxEHYEHlSafqiuVn5ESG0VRB331Fxhw=
github.com/MicahParks/jwkset v0.5.19/go.mod h1:q8ptTGn/Z9c4MwbcfeCDssADeVQb3Pk7PnVxrvi+2QY=
github.com/MicahParks/keyfunc/v3 v3.3.5 h1:7ceAJLUAldnoueHDNzF8Bx06oVcQ5CfJnYwNt1U3YYo=
github.com/MicahParks/keyfunc/v3 v3.3.5/go.mod h1:SdCCyMJn/bYqWDvARspC6nCT8Sk74MjuAY22C7dCST8=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
Expand Down Expand Up @@ -67,8 +67,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
Expand Down
4 changes: 4 additions & 0 deletions internal/manifest/v1alpha/examples/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func Report() []Example {
},
},
},
Thresholds: report.Thresholds{
RedLessThanOrEqual: ptr(0.8),
GreenGreaterThan: ptr(0.95),
},
},
},
),
Expand Down
8 changes: 4 additions & 4 deletions manifest/v1alpha/annotation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

func validate(p Annotation) *v1alpha.ObjectError {
return v1alpha.ValidateObject(validator, p, manifest.KindAnnotation)
return v1alpha.ValidateObject[Annotation](validator, p, manifest.KindAnnotation)
}

var validator = govy.New(
var validator = govy.New[Annotation](
validationV1Alpha.FieldRuleAPIVersion(func(a Annotation) manifest.Version { return a.APIVersion }),
validationV1Alpha.FieldRuleKind(func(a Annotation) manifest.Kind { return a.Kind }, manifest.KindAnnotation),
govy.For(func(p Annotation) Metadata { return p.Metadata }).
Expand All @@ -25,15 +25,15 @@ var validator = govy.New(
Include(specValidation),
)

var metadataValidation = govy.New(
var metadataValidation = govy.New[Metadata](
validationV1Alpha.FieldRuleMetadataName(func(m Metadata) string { return m.Name }),
govy.For(func(m Metadata) string { return m.Project }).
WithName("metadata.project").
OmitEmpty().
Rules(rules.StringDNSLabel()),
)

var specValidation = govy.New(
var specValidation = govy.New[Spec](
govy.For(func(s Spec) string { return s.Slo }).
WithName("slo").
Required().
Expand Down
40 changes: 33 additions & 7 deletions manifest/v1alpha/budgetadjustment/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package budgetadjustment
import (
"time"

"github.com/pkg/errors"
"github.com/teambition/rrule-go"

"github.com/nobl9/govy/pkg/govy"
Expand All @@ -14,10 +15,10 @@ import (
)

func validate(b BudgetAdjustment) *v1alpha.ObjectError {
return v1alpha.ValidateObject(validator, b, manifest.KindBudgetAdjustment)
return v1alpha.ValidateObject[BudgetAdjustment](validator, b, manifest.KindBudgetAdjustment)
}

var validator = govy.New(
var validator = govy.New[BudgetAdjustment](
validationV1Alpha.FieldRuleAPIVersion(func(b BudgetAdjustment) manifest.Version { return b.APIVersion }),
validationV1Alpha.FieldRuleKind(
func(b BudgetAdjustment) manifest.Kind { return b.Kind },
Expand All @@ -29,12 +30,12 @@ var validator = govy.New(
Include(specValidation),
)

var metadataValidation = govy.New(
var metadataValidation = govy.New[Metadata](
validationV1Alpha.FieldRuleMetadataName(func(m Metadata) string { return m.Name }),
validationV1Alpha.FieldRuleMetadataDisplayName(func(m Metadata) string { return m.DisplayName }),
)

var specValidation = govy.New(
var specValidation = govy.New[Spec](
govy.For(func(s Spec) string { return s.Description }).
WithName("description").
Rules(validationV1Alpha.StringDescription()),
Expand All @@ -46,13 +47,14 @@ var specValidation = govy.New(
Required().
Rules(rules.DurationPrecision(time.Minute)),
govy.Transform(func(s Spec) string { return s.Rrule }, rrule.StrToRRule).
WithName("rrule"),
WithName("rrule").
Rules(atLeastHourlyFreq),
govy.For(func(s Spec) Filters { return s.Filters }).
WithName("filters").
Include(filtersValidationRule),
)

var filtersValidationRule = govy.New(
var filtersValidationRule = govy.New[Filters](
govy.ForSlice(func(f Filters) []SLORef { return f.SLOs }).
WithName("slos").
Rules(rules.SliceMinLength[[]SLORef](1)).
Expand All @@ -62,7 +64,7 @@ var filtersValidationRule = govy.New(
}, "SLOs must be unique")),
)

var sloValidationRule = govy.New(
var sloValidationRule = govy.New[SLORef](
govy.For(func(s SLORef) string { return s.Project }).
WithName("project").
Required().
Expand All @@ -72,3 +74,27 @@ var sloValidationRule = govy.New(
Required().
Rules(rules.StringDNSLabel()),
)

var atLeastHourlyFreq = govy.NewRule(func(rule *rrule.RRule) error {
if rule == nil {
return nil
}

if rule.Options.Count == 1 {
return nil
}

if rule.Options.Freq == rrule.MINUTELY && rule.Options.Interval < 60 {
return errors.New("interval must be at least 60 minutes for minutely frequency")
}

if rule.Options.Freq == rrule.SECONDLY && rule.Options.Interval < 3600 {
return errors.New("interval must be at least 3600 seconds for secondly frequency")
}

if len(rule.Options.Byminute) > 1 || len(rule.Options.Bysecond) > 0 {
return errors.New("byminute and bysecond are not supported")
}

return nil
})
Loading

0 comments on commit 505da92

Please sign in to comment.