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

Allow to set QP resources per service #14038

Merged
merged 6 commits into from Jun 28, 2023

Conversation

skonto
Copy link
Contributor

@skonto skonto commented May 31, 2023

Part of the work for #13861.

Proposed Changes

  • Adds an annotation per resource type. Here is a sample ksvc:
apiVersion: serving.knative.dev/v1
kind: Service
spec:
  template:
    metadata:
      labels:
        app: helloworld-go
      annotations:
        queue.sidecar.serving.knative.dev/cpu-resource-request: "1"
        queue.sidecar.serving.knative.dev/cpu-resource-limit: "2"
        queue.sidecar.serving.knative.dev/memory-resource-request: "1Gi"
        queue.sidecar.serving.knative.dev/memory-resource-limit: "2Gi"
        queue.sidecar.serving.knative.dev/ephemeral-storage-resource-request: "400Mi"
        queue.sidecar.serving.knative.dev/ephemeral-storage-resource-limit: "450Mi"
    spec:
 ...
  • The values passed by the user have higher priority compared to the percentage annotation.
  • Tests added.

Release Note

Queue proxy resources can be configured via annotations at the service level.  The resource percentage annotation is now deprecated.

@skonto skonto requested a review from dprotaso May 31, 2023 08:46
@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers labels May 31, 2023
@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.03 ⚠️

Comparison is base (c12c917) 86.22% compared to head (278a5e4) 86.19%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14038      +/-   ##
==========================================
- Coverage   86.22%   86.19%   -0.03%     
==========================================
  Files         199      199              
  Lines       14767    14795      +28     
==========================================
+ Hits        12733    12753      +20     
- Misses       1732     1737       +5     
- Partials      302      305       +3     
Impacted Files Coverage Δ
pkg/apis/serving/v1/revision_validation.go 91.56% <100.00%> (+0.77%) ⬆️
pkg/reconciler/revision/resources/queue.go 98.36% <100.00%> (+0.12%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@skonto skonto changed the title Allow to set QP resources per service [wip] Allow to set QP resources per service May 31, 2023
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 31, 2023
@skonto skonto changed the title [wip] Allow to set QP resources per service Allow to set QP resources per service Jun 1, 2023
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 1, 2023
@skonto
Copy link
Contributor Author

skonto commented Jun 6, 2023

/assign @dprotaso

Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

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

Should we deprecate the % knob?

@@ -162,6 +180,30 @@ var (
QueueSidecarResourcePercentageAnnotationKey,
"queue.sidecar." + GroupName + "/resourcePercentage",
}
QueueSidecarCPUResourceRequestAnnotation = kmap.KeyPriority{
QueueSidecarCPUResourceRequestAnnotationKey,
"queue.sidecar." + GroupName + "/CPUResourceRequest",
Copy link
Member

Choose a reason for hiding this comment

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

don't need the alternate casing for new annotations

Copy link
Contributor Author

@skonto skonto Jun 12, 2023

Choose a reason for hiding this comment

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

@dprotaso You mean s/CPUResourceRequest /cpuesourcerequest? Wouldnt that be a bit misaligned compared to the resourcePercentage?

Copy link
Member

@dprotaso dprotaso Jun 16, 2023

Choose a reason for hiding this comment

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

resourcePercentage is present here because it was the old casing that we supported. We didn't want to break old deployments

For new keys we should just use kebab-casing only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok then I will fix.

pkg/apis/serving/register.go Outdated Show resolved Hide resolved
@dprotaso
Copy link
Member

dprotaso commented Jun 7, 2023

I was mixed on whether this should be exposed to users but ultimately if they can set their own request/limits on the user container then it's no different from setting it on the sidecar (in terms of abusing it)

@ReToCode
Copy link
Member

ReToCode commented Jun 8, 2023

LGTM.

@skonto
Copy link
Contributor Author

skonto commented Jun 12, 2023

Should we deprecate the % knob?

Yeah I think it makes sense.

@skonto
Copy link
Contributor Author

skonto commented Jun 13, 2023

Hi @dprotaso gentle ping. I deprecated the resource percentage (should be done at docs side too), now it prints:

Warning: Queue proxy resource percentage annotation is deprecated. Please use the available annotations to explicitly set resource values per service: 
service.serving.knative.dev/helloworld-go configured

Also replied to the comments above.

@skonto
Copy link
Contributor Author

skonto commented Jun 20, 2023

@dprotaso gentle ping, I removed the redundant key.

@@ -188,14 +188,15 @@ func validateQueueSidecarAnnotation(m map[string]string) *apis.FieldError {
if !ok {
return nil
}
errs := apis.ErrGeneric("Queue proxy resource percentage annotation is deprecated. Please use the available annotations to explicitly set resource values per service").ViaKey(k).At(apis.WarningLevel)
Copy link
Member

@dprotaso dprotaso Jun 20, 2023

Choose a reason for hiding this comment

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

We should validate the new annotations here by attempting to parse them. Then it will fail when we create/update/apply vs. silently dropping it later on when creating the deployment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok will add it.

@skonto
Copy link
Contributor Author

skonto commented Jun 21, 2023

@dprotaso thanks for reviewing, I added the validation part:

Error from server (BadRequest): error when creating "qp_resource_anno_service.yaml": admission webhook "validation.webhook.serving.knative.dev" denied the request: validation failed: invalid value: 450Mxx: spec.template.metadata.annotations.[queue.sidecar.serving.knative.dev/ephemeral-storage-resource-limit]

Comment on lines 202 to 207
validate := func(k, v string) *apis.FieldError {
if _, err := resource.ParseQuantity(v); err != nil {
return errs.Also(apis.ErrInvalidValue(v, apis.CurrentField).ViaKey(k))
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we just move this into the loop below? so we're not creating a closure on every validate invocation?

Comment on lines 218 to 220
if ok {
errs = errs.Also(validate(k, v))
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ok {
errs = errs.Also(validate(k, v))
}
if !ok {
continue
}
... // add code above here

@skonto
Copy link
Contributor Author

skonto commented Jun 26, 2023

@dprotaso gentle ping.

@skonto
Copy link
Contributor Author

skonto commented Jun 27, 2023

@dprotaso hi should we merge this? I will add the docs.

@dprotaso
Copy link
Member

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2023
@knative-prow
Copy link

knative-prow bot commented Jun 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, skonto

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 knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 27, 2023
@skonto
Copy link
Contributor Author

skonto commented Jun 28, 2023

/retest

@knative-prow knative-prow bot merged commit 63fa389 into knative:main Jun 28, 2023
62 checks passed
skonto added a commit to skonto/serving that referenced this pull request Oct 5, 2023
* allow to set qp resources per service

* add ephemeral storage

* deprecate resource percentage

* remove the old casing

* add proper validation

* fix loop
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 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.

None yet

3 participants