-
Notifications
You must be signed in to change notification settings - Fork 880
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
feat(analysis): Allow analysis arguments to get valueFrom Rollout status (#1242) #1629
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1629 +/- ##
==========================================
- Coverage 81.99% 81.98% -0.01%
==========================================
Files 115 116 +1
Lines 15913 15974 +61
==========================================
+ Hits 13048 13097 +49
- Misses 2196 2204 +8
- Partials 669 673 +4
Continue to review full report at Codecov.
|
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.
Could you provide documentation on this? It's not clear how this will work and how to use it.
go.mod
Outdated
@@ -3,6 +3,7 @@ module github.com/argoproj/argo-rollouts | |||
go 1.16 | |||
|
|||
require ( | |||
github.com/PaesslerAG/jsonpath v0.1.1 |
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.
Hmmm, this library uses "BSD 3-Clause "New" or "Revised" License" which is not what we typically use (Apache 2 or MIT). I'm not sure this is okay to use. Is there something else we can use or write our own?
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.
I tried using a different library called objx
, which was similar. But the problem there was that using a non-existing path (path: "some.none.existing[4].path.in.rollout"
) just returns an empty string. So it's not possible to display an error when the user used an invalid path or not (unless we assume an empty string is always an error).
If you know of any other possible libraries, I'd be happy to give them a shot as well.
I can also write a simple parser by splitting on "."
. I don't think it will be too complicated, given our very specific use-case (specifically with field names that do not contain dots themselves)
I removed the dependency on |
642a571
to
d91a9ed
Compare
var isArray, isMap bool | ||
_, isArray = m.([]interface{}) | ||
_, isMap = m.(map[string]interface{}) | ||
if isArray || isMap { |
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.
what is this check is for? can you provide an example?
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.
If the user puts in something like status.canary.weights.canary
- the resulting value would be a map, and not a primitive value (string/number/bool).
I guess we could support that as well, and just return it as a JSON string, but is it a reasonable usecase? It seems like it might be a future ticket.
@@ -217,3 +227,42 @@ func ValidateMetric(metric v1alpha1.Metric) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func extractValueFromRollout(r *v1alpha1.Rollout, path string) (string, error) { |
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.
can you add negative tests if possible as coverage is red for following chunks
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.
I added some tests for invalid paths.
I also removed the error check after the json.Marshal - I assume that a valid Rollout object can always be marshalled to json.
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
return err if path is inavlid in runtime (don't check in validation time) Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
Signed-off-by: Noam Gal <[email protected]>
5819e64
to
1eab4fd
Compare
go.mod
Outdated
@@ -32,6 +32,7 @@ require ( | |||
github.com/soheilhy/cmux v0.1.4 | |||
github.com/spaceapegames/go-wavefront v1.8.1 | |||
github.com/spf13/cobra v1.1.3 | |||
github.com/stretchr/objx v0.3.0 // indirect |
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.
are we using this library?
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.
you are right. fixing now.
LGTM..except the comment about lib objx |
Signed-off-by: Noam Gal <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
This is exactly what I am looking for, I need to make prometheus queries using Thanks @noam-codefresh! |
@jessesuen can you take another look please ? |
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.
Minor nit about documentation but otherwise LGTM
Analysis arguments also support valueFrom for reading any Rollout fields and passing them as arguments to AnalysisTemplate. | ||
An example would be to reference metadata labels like env and region and passing them along to AnalysisTemplate, or any field | ||
from the Rollout status |
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.
Since we don't have versioned docs yet, could we add a note stating v1.2 supports valueFrom rollout status?
Can this be merged? I have run E2E tests locally and they seem to work well. |
Checklist:
"fix(controller): Updates such and such. Fixes #1234"
.