-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PC-10133: Move SLO into separate package #141
Conversation
ae25dc0
to
1ccc047
Compare
bcccce7
to
f2a61f6
Compare
f273a41
to
6390b6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh Oh! that's another big refactor
I like the new validation. It's very verbose but also very readable and easily adjustable (and testable!)
I also agree with the structure of Rules and Validators.
I didn't check the PR in details though and left just a few comments/questions.
…o-separate-package
…o-separate-package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e9cde51
to
df18924
Compare
…o-separate-package
…o-separate-package
…o-separate-package
This PR introduces:
validation
library, namely:ForPointer
Validator
behaviourNOBL9_SDK_TEST_RECORD_FILE=/home/mh/test-output make test
The error handling after these changes solidifies with the following inter object dependencies:
The following benchmark was run to asses the performance of the solution:
With the following results for erroneous objects (around 240 of them):
$ go test -bench=Validate -benchtime=10s -benchmem goos: linux goarch: amd64 pkg: github.com/nobl9/nobl9-go/manifest/v1alpha cpu: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz BenchmarkValidate-8 7450 1640675 ns/op 2093472 B/op 22081 allocs/op PASS ok github.com/nobl9/nobl9-go/manifest/v1alpha 12.411s
$ go test -bench=Validate -benchtime=10s -benchmem goos: linux goarch: amd64 pkg: github.com/nobl9/nobl9-go/manifest/v1alpha/slo cpu: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz BenchmarkValidate-8 2427 4949896 ns/op 1571118 B/op 35522 allocs/op PASS ok github.com/nobl9/nobl9-go/manifest/v1alpha/slo 12.559s
This is expected, as there's much more function calls and details provided to errors.
Let's compare clean SLO:
$ go test -bench=Validate -benchtime=10s -benchmem goos: linux goarch: amd64 pkg: github.com/nobl9/nobl9-go/manifest/v1alpha cpu: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz BenchmarkValidate-8 534976 21294 ns/op 11483 B/op 48 allocs/op PASS ok github.com/nobl9/nobl9-go/manifest/v1alpha 11.637s
$ go test -bench=Validate -benchtime=10s -benchmem goos: linux goarch: amd64 pkg: github.com/nobl9/nobl9-go/manifest/v1alpha/slo cpu: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz BenchmarkValidate-8 470991 25588 ns/op 9036 B/op 20 allocs/op PASS ok github.com/nobl9/nobl9-go/manifest/v1alpha/slo 12.345s
Here, the difference is not as noticeable anymore, more so, the new code now allocates much less, but that also depends on an integration, I've run it only for
Instana
as it has a fairly complex validation.FAQ:
Question might arise: how to do cross field checks?
Here a second question may appear: what is a cross field check?
Let's say we want to compare a value of a deeply nested field to a value of another field which resides in a different place on a struct properties tree. Say we want to make sure
spec.indicator.metricSource.project
is equal tometadata.project
. The proposed validation DOES NOT allow reverse access to properties, you can only access your children. Hence the only way to achieve that is to simply create a rule on a higher level (in the example, on the topSLO
level), which has the access to the properties in question and useWithName
method to associate it with the downstream path ofspec.indicator.metricSource.project
, alternatively you can also returnPropertyError
from your custom top level validation rule.Due to rebasing shenanigans the commits history is botched...