Conversation
We want to add these eventually, but they're still under development right now.
79ba918 to
899ca17
Compare
This change adds Kubernetes Horizontal Pod Autoscaler (HPA) support with a custom metrics API implementation for the CloudZero agent. The existing agent relied on manual scaling, which wasn't responsive to actual workload demands and could lead to resource inefficiencies. The implementation exposes a Kubernetes custom metrics API v1beta1 endpoint that serves the `czo_cost_metrics_shipping_progress` metric from the collector. This metric represents the percentage of pending metrics relative to the maximum record limit, allowing HPA to scale the aggregator deployment based on actual workload pressure. Key technical changes include: - Custom metrics API handlers implementing the v1beta1 specification - Discovery endpoints for API resource enumeration - Integration with existing metric collector to expose shipping progress - HPA configuration templates with proper RBAC permissions - Comprehensive test coverage and documentation The approach eliminates external dependencies like Prometheus Adapter by implementing the custom metrics API directly in the collector, creating a self-contained autoscaling solution that scales based on the agent's own internal metrics rather than external observability infrastructure.
| costMetricsShippingProgress = promauto.NewGaugeVec( | ||
| prometheus.GaugeOpts{ | ||
| Name: types.ObservabilityMetric("cost_metrics_shipping_progress"), | ||
| Help: "Progress towards cost metrics shipping goal (ratio of currentPending/targetProgress), where targetProgress = (elapsedTime/costMaxInterval) * maxRecords, 1.0 = 100% of expected rate", |
Contributor
There was a problem hiding this comment.
I'm wondering if we should add a "buffer" or scale factor, eg (currentPending/targetProgress)*1.05
Nevermind, this is handled properly by targetValue: "900m"
Why am I still posting this comment? Not sure, just to say, this all looks great to me. Nice work!
Contributor
Author
There was a problem hiding this comment.
I'm also working on a simplification where we just base it off of metrics/minute on a 2-minute sliding window, which also lets us do some other fun stuff...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
To automatically scale aggregator replicas up/down.
What
This change adds Kubernetes Horizontal Pod Autoscaler (HPA) support with a custom metrics API implementation for the CloudZero agent. The existing agent relied on manual scaling, which wasn't responsive to actual workload demands and could lead to resource inefficiencies.
The implementation exposes a Kubernetes custom metrics API v1beta1 endpoint that serves the
czo_cost_metrics_shipping_progressmetric from the collector. This metric represents the percentage of pending metrics relative to the maximum record limit, allowing HPA to scale the aggregator deployment based on actual workload pressure.Key technical changes include:
The approach eliminates external dependencies like Prometheus Adapter by implementing the custom metrics API directly in the collector, creating a self-contained autoscaling solution that scales based on the agent's own internal metrics rather than external observability infrastructure.
How Tested
Lots of deploying and, and lots and lots of waiting.