Skip to content

Revision return replicas#11038

Merged
knative-prow-robot merged 13 commits intoknative:mainfrom
leetcope:revision-return-replicas
Apr 7, 2021
Merged

Revision return replicas#11038
knative-prow-robot merged 13 commits intoknative:mainfrom
leetcope:revision-return-replicas

Conversation

@leetcope
Copy link
Contributor

Fixes #10750

Proposed Changes

  • API change to include ActualReplicas and DesiredReplicas in Revision status
  • Assert and use the ActualReplicas and DesiredReplicas in e2e tests

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Mar 26, 2021
@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Mar 26, 2021
@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #11038 (7abff9f) into main (813aa65) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11038      +/-   ##
==========================================
- Coverage   87.74%   87.72%   -0.02%     
==========================================
  Files         190      190              
  Lines        9162     9164       +2     
==========================================
  Hits         8039     8039              
- Misses        870      871       +1     
- Partials      253      254       +1     
Impacted Files Coverage Δ
pkg/apis/serving/v1/revision_lifecycle.go 92.98% <100.00%> (+0.25%) ⬆️
pkg/autoscaler/statforwarder/leases.go 76.97% <0.00%> (-1.44%) ⬇️

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 813aa65...7abff9f. Read the comment docs.

@leetcope leetcope force-pushed the revision-return-replicas branch from fc4f41b to 0a1e6af Compare March 26, 2021 06:14
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 26, 2021
@leetcope
Copy link
Contributor Author

/retest

// Reflect the PA status in our own.
cond := ps.GetCondition(autoscalingv1alpha1.PodAutoscalerConditionReady)
if ps.ActualScale != nil {
rs.ActualReplicas = *ps.ActualScale
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the GetActualScale helper here and avoid the nil check?

if ps.ActualScale != nil {
rs.ActualReplicas = *ps.ActualScale
} else {
rs.ActualReplicas = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this else may be redundant since ActualReplicas defaults to 0 anyway. Might be clearer to drop it.

Copy link
Member

@dprotaso dprotaso Apr 6, 2021

Choose a reason for hiding this comment

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

I think it's fine to guard against the PodAutoscalerStatus and leave this else clause

ie. if in the future PodAutoscalerStatus scale could cycle through the values -1 => some number > 0 => -1 then we'd be fine.

Or alternatively it might be better to have

rs.ActualReplicas := math.Max(ps.GetActualScale(), 0)

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't work, since Math.Max works with float64 only (thanks golang). But we can write our own max (we have a few in the code already).

}

if ps.DesiredScale != nil && *ps.DesiredScale != -1 {
rs.DesiredReplicas = *ps.DesiredScale
Copy link
Contributor

Choose a reason for hiding this comment

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

can use GetDesiredScale() helper here and avoid nil check

ps: autoscalingv1alpha1.PodAutoscalerStatus{
DesiredScale: ptr.Int32(-1),
},
// actualReplicas: 0, desiredReplicas: 0
Copy link
Contributor

@julz julz Mar 26, 2021

Choose a reason for hiding this comment

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

might as well just set the want fields I think (even if theyre technically redundant) if we're going to have the comment here anyway

// +optional
ContainerStatuses []ContainerStatus `json:"containerStatuses,omitempty"`

// Reflects the PodAutoScalerStatus.ActualScale value in RevisionStatus.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Reflects the PodAutoScalerStatus.ActualScale value in RevisionStatus.
// ActualReplicas reflects the PodAutoScalerStatus.ActualScale value in RevisionStatus.


// Reflects the PodAutoScalerStatus.ActualScale value in RevisionStatus.
ActualReplicas int32 `json:"actualReplicas,omitempty"`
// Reflects the PodAutoScalerStatus.DesiredScale value in RevisionStatus.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Reflects the PodAutoScalerStatus.DesiredScale value in RevisionStatus.
// DesiredReplicas reflects the PodAutoScalerStatus.DesiredScale value in RevisionStatus.

} else {
t.Fatalf("Failed to get Service name from Revision label")
}
if val := revision.Status.ActualReplicas; val != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Im wondering why we added this check to this test in particular (seems not particularly related?).

t.Fatalf("The revision %q scaled to %d > %d after not being routable anymore: %v", newRevName, lr, minScale, err)
}

revision, err = clients.ServingClient.Revisions.Get(context.Background(), newRevName, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be flaky if sometimes the revision hasnt quite finished reconciling the PA status? (ie. since I think we're not waiting for that reconcile to complete in waitForDesiredScale might it be possible for waitForDesiredScale to return before ActualScale has bubbled up?)

@leetcope leetcope force-pushed the revision-return-replicas branch from 0a1e6af to a09ae43 Compare March 26, 2021 14:03
@@ -291,22 +290,12 @@ func assertScaleDown(ctx *TestContext) {
func numberOfReadyPods(ctx *TestContext) (float64, error) {
// SKS name matches that of revision.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// SKS name matches that of revision.

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

Do you want to change revision.yaml CRD as well to report the values on k get revision?

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

stylistic issues only.

Comment on lines +708 to +709
wantActualReplicas: -1,
wantDesiredReplicas: -1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want these to surface -1 as long as the pointers are nil? Have we considered making the respective Status on the Revision pointers to ints as well?

@markusthoemmes
Copy link
Contributor

/assign @dprotaso

For an API review.

@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 Mar 29, 2021
@leetcope
Copy link
Contributor Author

/retest

@dprotaso
Copy link
Member

dprotaso commented Mar 29, 2021

So the upgrade tests are failing due to downgrading detecting unrecognizable fields

"Failed to migrate: unable to patch resource serving-tests/pizzaplanet-post-upgrade-service-00001 (gvr: serving.knative.dev/v1, Resource=revisions) - admission webhook "webhook.serving.knative.dev" denied the request: mutation failed: cannot decode incoming new object: json: unknown field "actualReplicas""

We should discuss the options - I've made an issue here: #11065

@dprotaso
Copy link
Member

/hold

API change is pulled out here: #11068

We'll want to land that and wait till after the release before continuing this PR

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 31, 2021
@leetcope leetcope force-pushed the revision-return-replicas branch from de9916b to b2493b8 Compare April 5, 2021 17:35
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 5, 2021
@leetcope
Copy link
Contributor Author

leetcope commented Apr 6, 2021

/test pull-knative-serving-istio-stable-no-mesh

@dprotaso
Copy link
Member

dprotaso commented Apr 6, 2021

/retest

@leetcope leetcope force-pushed the revision-return-replicas branch from d2d28fa to 1aa690f Compare April 6, 2021 18:35
@leetcope leetcope force-pushed the revision-return-replicas branch from 1aa690f to 7abff9f Compare April 6, 2021 19:17
@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 Apr 6, 2021
@leetcope
Copy link
Contributor Author

leetcope commented Apr 6, 2021

/retest

@dprotaso
Copy link
Member

dprotaso commented Apr 7, 2021

/retest
/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso

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

The pull request process is described here

Details 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 Apr 7, 2021
@dprotaso
Copy link
Member

dprotaso commented Apr 7, 2021

/test pull-knative-serving-istio-stable-no-mesh

@dprotaso
Copy link
Member

dprotaso commented Apr 7, 2021

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 7, 2021
@knative-prow-robot knative-prow-robot merged commit 983a307 into knative:main Apr 7, 2021
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. area/API API objects and controllers area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose number of replicas in Revision's status

6 participants