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

Calculate traffic split when N-1 revisions are specified #1483

Merged
merged 8 commits into from
Oct 29, 2021

Conversation

vyasgun
Copy link
Contributor

@vyasgun vyasgun commented Oct 18, 2021

Description

Changes

  • Determine traffic split when N-1 revisions are specified
  • In case @latest is specified, cannot determine the split unless it sums to 100

Reference

Fixes #

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 18, 2021
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vyasgun: 0 warnings.

In response to this:

Description

Changes

  • Determine traffic split when N-1 revisions are specified
  • In case @latest is specified, cannot determine the split unless it sums to 100

Reference

Fixes #

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 18, 2021
@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #1483 (30801ee) into main (62b1f73) will increase coverage by 0.25%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1483      +/-   ##
==========================================
+ Coverage   79.05%   79.30%   +0.25%     
==========================================
  Files         162      162              
  Lines        8454     8495      +41     
==========================================
+ Hits         6683     6737      +54     
+ Misses       1085     1076       -9     
+ Partials      686      682       -4     
Impacted Files Coverage Δ
pkg/kn/commands/service/update.go 81.42% <100.00%> (+0.83%) ⬆️
pkg/kn/traffic/compute.go 100.00% <100.00%> (ø)
pkg/kn/commands/source/ping/update.go 84.00% <0.00%> (-0.62%) ⬇️
pkg/kn/plugin/stat.go 60.00% <0.00%> (ø)
pkg/serving/v1/client.go 82.77% <0.00%> (ø)
pkg/eventing/v1/client.go 87.67% <0.00%> (ø)
pkg/serving/v1alpha1/client.go 86.76% <0.00%> (ø)
pkg/kn/commands/domain/update.go 65.71% <0.00%> (ø)
pkg/kn/commands/trigger/update.go 77.19% <0.00%> (ø)
... and 10 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 62b1f73...30801ee. Read the comment docs.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 18, 2021
@dsimansk
Copy link
Contributor

/retest

@dsimansk
Copy link
Contributor

@vyasgun the test should be OK now, minus go-coverage that's still failing but it isn't required to pass.

@vyasgun
Copy link
Contributor Author

vyasgun commented Oct 19, 2021

thanks, @dsimansk!

return nil
}
}
return errorTrafficDistribution()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this error be tested as well pls?

}
if sum < 100 && revPercents == revisionCount-1 {
if latestNameFound {
return errorTrafficDistribution()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the error could accept a reason param? Just an idea to better explain the failure.

@dsimansk
Copy link
Contributor

dsimansk commented Oct 19, 2021

In addition to the above comments E2E tests with the change would be great.

And there should be an example added to showcase the usage. E.g. https://github.com/knative/client/blob/main/docs/cmd/kn_service_update.md#examples

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution and for adding lots of tests. However, no integration tests. Perhaps adding some could reduce your unit tests and also make it easier to verify this feature? Might worth a try.

/ok-to-test

@@ -260,18 +271,42 @@ func verifyInput(trafficFlags *flags.Traffic) error {
sum += percentInt
}

revPercents := len(trafficFlags.RevisionsPercentages)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave a comment here since not obvious that the length of the array is the revPercents

// verifies if user has repeated @latest field in --tag or --traffic flags
// verifyInput checks:
// - if user has repeated @latest field in --tag or --traffic flags
// - if provided traffic portion are integers
func verifyInput(trafficFlags *flags.Traffic) error {
func verifyInput(trafficFlags *flags.Traffic, revisions []servingv1.Revision) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split this function into smaller private functions. That might make it easier to parse and comprehend. For instance there’s logical helper functions that could be extracted around each of the for loops… as an example

[]string{"@latest"},
[]string{"latest"},
[]int64{100},
name: "assign 'latest' tag to @latest revision",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comment to explain the “matrix” of tests you are doing with the big structure below. This would explain why you have x numbers of tests and what the differences between the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. This test matrix was already present. The change is to include the field names which weren't there before (modified because of the new field existingRevisions being added to the struct)

append(newServiceTraffic([]servingv1.TrafficTarget{}), newTarget("", "", 100, true)),
[]string{"--tag", "@latest="},
"expecting the value format in value1=value2, given @latest=",
name: "repeatedly tagging to @latest revision not allowed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above to add some summary comment to explain the different tests in the array…

@knative-prow-robot knative-prow-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 19, 2021
@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 20, 2021
kn service update gitopstest --env KEY1=VALUE1 --target=/user/knfiles/test.json


# Split 50% traffic to stable, 40% traffic to staging and the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move it above the "offline" mode example to make it appear as a follow-up to the above examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it, thanks

@vyasgun
Copy link
Contributor Author

vyasgun commented Oct 25, 2021

/retest

@dsimansk
Copy link
Contributor

Thanks, looks good to me now. :)

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 26, 2021
docs/cmd/kn_service_update.md Outdated Show resolved Hide resolved
pkg/kn/commands/service/update.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 26, 2021
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/update.go 86.9% 87.5% 0.6

@dsimansk
Copy link
Contributor

Since all the review comments are addressed, lets get it in. :)

Thanks!
/approve
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 29, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dsimansk, vyasgun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 29, 2021
@dsimansk
Copy link
Contributor

/retest

@knative-prow-robot knative-prow-robot merged commit d8d0ee1 into knative:main Oct 29, 2021
@vyasgun
Copy link
Contributor Author

vyasgun commented Oct 30, 2021

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants