You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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
@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.
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.
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:
The goodies are on individual pods.
Requests from within the mesh cannot access individual Pods.
The Autoscaler is across the network.
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.
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.
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.
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".)
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.
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.
@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).
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.
Activity
josephburnett commentedon Nov 1, 2018
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.
[-]Prometheus to scrape pods for metrics[/-][+]Autoscaler to scrape pods for metrics[/+]tcnghia commentedon Nov 1, 2018
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
ZhiminXiang commentedon Nov 1, 2018
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
josephburnett commentedon Nov 2, 2018
@tcnghia What makes it hard?
ZhiminXiang commentedon Nov 2, 2018
@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.
josephburnett commentedon Nov 2, 2018
What technical reason prevents the Istio sidecar from allowing access by Pod IP? E.g. can we fix this?
tcnghia commentedon Nov 2, 2018
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.
josephburnett commentedon Nov 2, 2018
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
PodAutoscalerwill go get it.The limitations I'm trying to work around are:
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.
cc @mattmoor @evankanderson @vaikas-google @mdemirhan @tcnghia
8 remaining items
josephburnett commentedon Nov 6, 2018
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.
josephburnett commentedon Nov 6, 2018
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.
jchesterpivotal commentedon Nov 6, 2018
I think 3 samples/sec is fine; we can tune it easily enough with further testing and simulation.
josephburnett commentedon Nov 7, 2018
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.
glyn commentedon Nov 7, 2018
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".)
k4leung4 commentedon Nov 29, 2018
/assign @yanweiguo
as I will be out for the next 2 weeks.
knative-prow-robot commentedon Nov 29, 2018
@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:
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 commentedon Nov 29, 2018
@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:
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.
k4leung4 commentedon Nov 29, 2018
/assign @yanweiguo
josephburnett commentedon Nov 30, 2018
@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/targetannotation (#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).
mdemirhan commentedon Nov 30, 2018
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: