Skip to content

Autoscaler to scrape pods for metrics #2203

Closed

Description

@josephburnett

Current behavior

Currently the autoscaler gets it's metrics directly from the queue-proxy. (The queue pushes to the autoscaler).

Desired behavior

Instead we want to collect pod metrics for a Prometheus endpoint on the pods (#2202). Either by scraping with Prometheus or directly with the autoscaler.

Example: Prometheus scraping the activator

Activity

  1. added
    kind/feature
    on Oct 10, 2018
  2. added this to the milestone on Oct 10, 2018
  3. self-assigned this
    on Nov 1, 2018
  4. josephburnett commented on Nov 1, 2018

    @josephburnett
    ContributorAuthor

    I'm taking a first stab at this. But instead of having Prometheus scrape the pods, I'm having the Autoscaler scrape them directly. This is because having Prometheus as a hard dependency and critical-path runtime component is a concern.

  5. changed the title [-]Prometheus to scrape pods for metrics[/-] [+]Autoscaler to scrape pods for metrics[/+] on Nov 1, 2018
  6. tcnghia commented on Nov 1, 2018

    @tcnghia
    Contributor

    Scraping pod is hard when sidecar injection / mTLS is enabled I believe. This is a limitation of Istio, and for Prometheus we may have to use the version that comes with Istio to overcome this limitation. Not sure if we can do this for our autoscaler.

    /cc @ZhiminXiang

  7. ZhiminXiang commented on Nov 1, 2018

    @ZhiminXiang

    Istio is working on a feature to support scraping pod from the Prometheus pre-installed by Istio when mTLS is enabled.
    Currently we use our own Prometheus, not the one installed by Istio, which could potentially block scraping pod after mTLS is enabled.
    /cc @mdemirhan

  8. josephburnett commented on Nov 2, 2018

    @josephburnett
    ContributorAuthor

    Scraping pod is hard when sidecar injection / mTLS is enabled

    @tcnghia What makes it hard?

  9. ZhiminXiang commented on Nov 2, 2018

    @ZhiminXiang

    @josephburnett if we want to enable mTLS, then Prometheus is required to have Istio sidecar injected. After injecting sidecar into Prometheus, Prometheus is not able to scrape pod directly as Istio sidecar does not allow accessing Pod by using Pod IP.

  10. josephburnett commented on Nov 2, 2018

    @josephburnett
    ContributorAuthor

    Istio sidecar does not allow accessing Pod by using Pod IP

    What technical reason prevents the Istio sidecar from allowing access by Pod IP? E.g. can we fix this?

  11. tcnghia commented on Nov 2, 2018

    @tcnghia
    Contributor

    One limitation is that all the network graph is replicated in all the Envoy sidecars. Restricting the network nodes to K8s Services, VirtualServices, and similar helps them (a) reduce the graph size, and more than that (b) also reduce how much updates they need to handle.

    There are pending work on Istio side to support incremental network update, but it is still in design phase.

  12. josephburnett commented on Nov 2, 2018

    @josephburnett
    ContributorAuthor

    What I want is to stop injecting knowledge about the autoscaler into the deployment from within the revision controller which is a layering violation (@mattmoor). I just want pods to expose their metrics in the standard Prometheus format and whatever autoscaling implementation is in charge of the PodAutoscaler will go get it.

    The limitations I'm trying to work around are:

    1. The goodies are on individual pods.
    2. Requests from within the mesh cannot access individual Pods.
    3. The Autoscaler is across the network.
    4. Requests across the network must be within the mesh (so they can use mTLS).

    How about this as a way to bootstrap metrics into the mesh? Create a daemonset pusher pair, one within the mesh and one without. The pusher outside (A) scrapes pod metrics and the pusher inside (B) forwards them to the autoscaler over mTLS.

    image

    cc @mattmoor @evankanderson @vaikas-google @mdemirhan @tcnghia

  13. 8 remaining items

  14. josephburnett commented on Nov 6, 2018

    @josephburnett
    ContributorAuthor

    A later sample may correct the problem although the overall effect will be some measure of instability, possibly even under a fairly constant load.

    The affects of a bad sample will be more pronounced in the 6-second panic window (rather than the 60-second stable window). But the panic window is only used to scale when the autoscaler is panicking. And then it never decreases the number of pod, precisely to prevent this kind of flapping (instability).

    With 3 qps, a single bad sample will be averaged with 180 other samples. So the effect of a bad sample will be not so much.

    Additionally, we can add some hysteresis to dampen the noise. This is something I wanted to do anyway because we do see a little bit of hopping between two values.

    @glyn, @jchesterpivotal what do you think about the 3 qps value? That's 3 qps for the whole revision. So the 6-second sample size will always be 18. And the 60-second sample size will always be 180. Even at high scale.

  15. josephburnett commented on Nov 6, 2018

    @josephburnett
    ContributorAuthor

    I'm going to move forward with the proposal to sample a metrics service, owned by the KPA: #2203 (comment)

    We can continue to discuss what the appropriate rate per scale is.

  16. jchesterpivotal commented on Nov 6, 2018

    @jchesterpivotal
    Contributor

    I think 3 samples/sec is fine; we can tune it easily enough with further testing and simulation.

  17. josephburnett commented on Nov 7, 2018

    @josephburnett
    ContributorAuthor

    One interesting point @tcnghia brought up is the accuracy of our scale-to-zero signal when we are sampling metrics (instead of collecting them all). I think we are still okay because 1) requests will be routed through the KBuffer before we turn down the Deployment, and the KBuffer still pushes metrics to the Autoscaler. And 2) because before scale-to-zero, the Deployment will be at low scale (likely 1 or close to it) and we will sample that one pod 3 times per second, so we're unlikely to miss a request. That kind of race condition already existed anyway, that a request comes in after we decide to scale to zero and we miss it. Thus the grace period.

  18. glyn commented on Nov 7, 2018

    @glyn
    Contributor

    @glyn, @jchesterpivotal what do you think about the 3 qps value?

    I have no idea whether this will be sufficient. I think you'll need to try it, or at least model it fairly realistically, to have any confidence. (This feels very much like the problem of performance optimisation and the same dictum probably applies: "Measure, don't guess".)

  19. k4leung4 commented on Nov 29, 2018

    @k4leung4

    /assign @yanweiguo
    as I will be out for the next 2 weeks.

  20. knative-prow-robot commented on Nov 29, 2018

    @knative-prow-robot
    Contributor

    @k4leung4: GitHub didn't allow me to assign the following users: as, I, will, be.

    Note that only knative members and repo collaborators can be assigned.
    For more information please see the contributor guide

    Details

    In response to this:

    /assign @yanweiguo as I will be

    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.

  21. knative-prow-robot commented on Nov 29, 2018

    @knative-prow-robot
    Contributor

    @k4leung4: GitHub didn't allow me to assign the following users: Yanwei, Guo.

    Note that only knative members and repo collaborators can be assigned.
    For more information please see the contributor guide

    Details

    In response to this:

    /assign Yanwei Guo

    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.

  22. k4leung4 commented on Nov 29, 2018

    @k4leung4

    /assign @yanweiguo

  23. josephburnett commented on Nov 30, 2018

    @josephburnett
    ContributorAuthor

    @yanweiguo you might wait until next week to start on this when I'm back in Seattle (Dec 3rd). As part of adding the autoscaling.knative.dev/target annotation (#2205), I'm relayering the KPA metrics interface to allow KPA autoscaler targets to be updated. I want to avoid any massive code merge conflicts. 🙂

    Also, it seems that Envoy ignores ports not mentioned in the K8s Service so you may be able to scrape metrics directly after all. It's worth reconsidering which approach to take (direct or service, sample or exhaustive).

  24. mdemirhan commented on Nov 30, 2018

    @mdemirhan
    Contributor

    I was discussing Prometheus doing the scraping for us with @k4leung4 yesterday and wanted to summarize a couple of cons of that approach in case it is being considered the path to move forward:

    • Prometheus does not scale horizontally and sharding needs to be controlled manually. This can get tricky as the scale of the cluster grows. We have a similar problem with Autoscaler itself, and this can be tied into that somehow.
    • If sampling will be utilized (and seems like that is a strong possibility), Prometheus will not give us the flexibility we want - for example, you might want to sample X pods for Service A and Y pods for Service B, and achieving that level of control via Prometheus can get quite tricky and might require frequent reprogramming Prometheus.
    • Reprogramming Prometheus (i.e. telling it what to scrape) requires updating a config file and restarting Prometheus (afaik) and that is going to be very disruptive if that is going to be done frequently. If we will do sampling based on the size of services, or if we will pick the pods to scrape ourselves, we will need to reprogram very frequently and that will probably cause a very poor experience.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/autoscalekind/feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions