Skip to content

Reconcile HPA class PodAutoscalers #2 - #2457

Merged
knative-prow-robot merged 39 commits into
knative:masterfrom
josephburnett:hpa3
Nov 30, 2018
Merged

knative-prow-robot merged 39 commits into
knative:masterfrom
josephburnett:hpa3

Conversation

@josephburnett

@josephburnett josephburnett commented Nov 9, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #2205
Fixes #1928

Proposed Changes

  • Adds a new autoscaling.knative.dev/class annotation.
  • Adds a new reconciler for hpa class PodAutoscalers to a Kubernetes HorizontalPodAutoscaler.
  • Autoscaler annotations are inherited from Service to Configuration to Revision through RevisionTemplate.
  • Renames PodAutoscaler types and files from kpa to just pa (drop the k). The short name kpa is now taken to mean kpa-class PodAutoscalers and hpa to mean hpa-class PodAutoscalers.
  • Add a new autoscaling.knative.dev/metric annotation to choose concurrency or cpu based autoscaling (cpu will default the class to hpa).
  • Add a new autoscaling.knative.dev/target annotation to choose the specific value for metric.
  • The class and metric annotation are immutable on PodAutoscaler, enforced by webhook. Other annotations (target, minScale, maxScale) are mutable.

Release Note

 * New `autoscaling.knative.dev/class` annotation.  Defaults to `kpa`.  Class of `hpa` reconciles to HoriztonalPodAutoscaler.  Other classes are left unreconciled to allow for extension of the PodAutoscaler CRD.  Autoscaler class in inherited from Service to Configuration to Revision.

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2018
@knative-prow-robot knative-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 9, 2018
@josephburnett josephburnett added this to the Scaling: Pluggability and HPA milestone Nov 9, 2018
@josephburnett josephburnett changed the title [WIP] Reconcile HPA class PodAutoscalers (2) [WIP] Reconcile HPA class PodAutoscalers #2 Nov 9, 2018
logger.Info("Updating PA %q", desiredPa.Name)
pa.Spec = desiredPa.Spec
pa.Annotations = desiredPa.Annotations
if _, err := c.updateKPA(ctx, pa); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will update the annotations. We'd discussed making class annotations immutable on the PodAutoscaler (we should probably do this @ Revision as well), which simplifies this a bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. I want the class and metric annotations to be immutable. But I want the others to be reconciled (minScale, maxScale, target).

My plan was to just reconcile all annotations from Revision to PodAutoscaler (for simplicity). And to use the Revision webhook to disallow class and metric changes. That means I will also be adding defaults in the Revision webhook.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After chatting with @mattmoor, I'll make the class annotation immutable on the Revision (enforced through webhook). But if I can't allow metric to change, I'll give an error from the PodAutoscaler webhook or reconciler, so I don't leak implementation-specific annotations into higher layers.

original, err := c.paLister.PodAutoscalers(namespace).Get(name)
if errors.IsNotFound(err) {
logger.Debug("PA no longer exists")
return c.deleteHpa(ctx, key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here and below, I think we should set up the invariants such that a PodAutoscaler never changes classes.

This line is problematic because it could create a requeue spin loop when deletions fail (e.g. on NotFound).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

c.deleteHpa handles NotFound (search for "This is fine"). So think this is okay. Am I missing something else?

@knative knative deleted a comment from knative-prow-robot Nov 30, 2018
@knative knative deleted a comment from knative-prow-robot Nov 30, 2018
@josephburnett

Copy link
Copy Markdown
Contributor Author

So weird. That unit test passes on my machine:

josephburnett@penguin:~/go/src/github.com/knative/serving$ go test ./pkg/reconciler/v1alpha1/route
ok      github.com/knative/serving/pkg/reconciler/v1alpha1/route        0.201s

@markusthoemmes

Copy link
Copy Markdown
Contributor

@josephburnett I think this is one of the flaky unit tests. Might not be related to your PR. See #2443

@josephburnett

Copy link
Copy Markdown
Contributor Author

/test pull-knative-serving-unit-tests

@josephburnett

Copy link
Copy Markdown
Contributor Author

Okay @mattmoor this is ready for another look.

@mattmoor mattmoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/approve
/hold

One thing worth confirming before this goes in, but otherwise this LGTM. thanks!

// PodAutoscaler should attempt to maintain. For example,
// autoscaling.knative.dev/metric: cpu
// autoscaling.knative.dev/target: 75 # target 75% cpu utilizationa
TargetAnnotationKey = GroupName + "/target"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I was saying "No" to was having the Revision controller put containerConcurrency into the annotation instead of a field. I wasn't suggesting we need any change here, just answering @markusthoemmes comment ;-)

Handler: cache.ResourceEventHandlerFuncs{
AddFunc: impl.EnqueueControllerOf,
UpdateFunc: controller.PassNew(impl.EnqueueControllerOf),
DeleteFunc: impl.EnqueueControllerOf,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉 This is looking awesome 🎉

UpdateFunc: controller.PassNew(impl.EnqueueLabelOfNamespaceScopedResource("", autoscaling.KPALabelKey)),
DeleteFunc: impl.EnqueueLabelOfNamespaceScopedResource("", autoscaling.KPALabelKey),
endpointsInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: onlyKpaClass,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure the Kubernetes Endpoints object gets annotations. Can you confirm this works?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does work, but only because I let PodAutoscalers missing the annotation through to the KPA (but not HPA) controller, for backward compatibility.

I've removed the filter since it's useless. Good catch!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(note true in the last parameter to AnnotationFilterFunc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep, that's what I suspected :D

@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. lgtm Indicates that a PR is ready to be merged. labels Nov 30, 2018
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: josephburnett, mattmoor

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 Nov 30, 2018
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2018
@knative-metrics-robot

Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/autoscaler/main.go 4.8% 4.6% -0.2
pkg/apis/autoscaling/v1alpha1/pa_defaults.go Do not exist 100.0%
pkg/apis/autoscaling/v1alpha1/pa_types.go Do not exist 60.6%
pkg/apis/autoscaling/v1alpha1/pa_validation.go Do not exist 76.9%
pkg/reconciler/v1alpha1/autoscaling/hpa/hpa.go Do not exist 60.6%
pkg/reconciler/v1alpha1/autoscaling/hpa/resources/hpa.go Do not exist 0.0%
pkg/reconciler/v1alpha1/autoscaling/kpa/kpa.go Do not exist 88.3%
pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler.go Do not exist 75.0%

@josephburnett josephburnett removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 30, 2018

@mattmoor mattmoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/hold cancel

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2018
@knative-prow-robot
knative-prow-robot merged commit 71a6c2e into knative:master Nov 30, 2018
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/autoscale lgtm Indicates that a PR is ready to be merged. 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.

5 participants