Skip to content
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

Merged
merged 12 commits into from
Jan 12, 2022

Conversation

noam-codefresh
Copy link
Contributor

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
  • The title of the PR is (a) conventional, (b) states what changed, and (c) suffixes the related issues number. E.g. "fix(controller): Updates such and such. Fixes #1234".
  • I've signed my commits with DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My builds are green. Try syncing with master if they are not.
  • My organization is added to USERS.md.

@codecov
Copy link

codecov bot commented Nov 8, 2021

Codecov Report

Merging #1629 (b35fcb5) into master (6edc9c8) will decrease coverage by 0.00%.
The diff coverage is 83.63%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
rollout/analysis.go 78.90% <25.00%> (-0.70%) ⬇️
rollout/experiment.go 82.69% <25.00%> (-1.29%) ⬇️
utils/analysis/factory.go 94.02% <93.18%> (-0.42%) ⬇️
pkg/apis/rollouts/validation/validation.go 94.06% <100.00%> (ø)
.../apis/rollouts/validation/validation_references.go 85.19% <100.00%> (+0.05%) ⬆️
rollout/trafficrouting/istio/controller.go 50.81% <0.00%> (-1.63%) ⬇️
controller/metrics/metrics.go 100.00% <0.00%> (ø)
utils/conditions/conditions.go 80.76% <0.00%> (ø)
controller/metrics/prommetrics.go 100.00% <0.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6edc9c8...b35fcb5. Read the comment docs.

Copy link
Member

@jessesuen jessesuen left a 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
Copy link
Member

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?

Copy link
Contributor Author

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)

@noam-codefresh
Copy link
Contributor Author

I removed the dependency on jsonPath, and now the code is parsing the path directly. It will support dot notation and array indexers, so something like status.canary.weights.canary.podTemplateHash (the original request), or status.conditions[0].status, but not anything more complex

var isArray, isMap bool
_, isArray = m.([]interface{})
_, isMap = m.(map[string]interface{})
if isArray || isMap {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

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]>
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@harikrongali
Copy link
Contributor

LGTM..except the comment about lib objx

Signed-off-by: Noam Gal <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Nov 21, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
13.6% 13.6% Duplication

@magec
Copy link

magec commented Dec 21, 2021

This is exactly what I am looking for, I need to make prometheus queries using status.currentPodHash, my life would be way easier with this feature. Looking forward for the merge.

Thanks @noam-codefresh!

@alexmt
Copy link
Contributor

alexmt commented Dec 21, 2021

@jessesuen can you take another look please ?

Copy link
Member

@jessesuen jessesuen left a 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

Comment on lines +429 to +431
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
Copy link
Member

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?

@magec
Copy link

magec commented Jan 12, 2022

Can this be merged? I have run E2E tests locally and they seem to work well.

@alexmt alexmt merged commit 4739bcd into argoproj:master Jan 12, 2022
@noam-codefresh noam-codefresh deleted the value_from_status branch February 9, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants