feat(hpa): add customMetrics, selectPolicy, and configurable policies#177
feat(hpa): add customMetrics, selectPolicy, and configurable policies#177camjay wants to merge 1 commit into
Conversation
Support custom metrics injection, per-direction selectPolicy, and full policy override for HPA scaleUp/scaleDown behavior. Existing defaults are preserved when custom policies are not specified.
There was a problem hiding this comment.
Pull request overview
This PR enhances the portkey-gateway Helm chart’s HPA support by allowing users to inject arbitrary HPA metrics and more fully configure autoscaling behavior policies.
Changes:
- Add
autoscaling.customMetricsto append arbitrary HPAmetricsentries. - Add
selectPolicysupport for bothscaleUpandscaleDownbehavior. - Allow overriding
behavior.scaleUp.policies/behavior.scaleDown.policies, while keeping existing defaults when not provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| charts/portkey-gateway/values.yaml | Adds commented examples for customMetrics, selectPolicy, and policies overrides. |
| charts/portkey-gateway/templates/gateway/hpa.yaml | Renders custom metrics and configurable selectPolicy / policies in the HPA spec. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {{- if .Values.autoscaling.behavior.scaleUp.policies }} | ||
| policies: | ||
| {{- toYaml .Values.autoscaling.behavior.scaleUp.policies | nindent 8 }} | ||
| {{- else }} |
There was a problem hiding this comment.
policies override is gated by a truthy check. If a user explicitly sets autoscaling.behavior.scaleUp.policies: [] (or wants to intentionally render an empty list), Helm treats an empty list as false and this block will fall back to the chart defaults. Consider switching to a presence check (e.g., hasKey on the scaleUp map) so that explicitly-provided empty lists are honored, and defaults are only used when the key is absent.
| scaleDown: | ||
| stabilizationWindowSeconds: {{ .Values.autoscaling.behavior.scaleDown.stabilizationWindowSeconds | default 300 }} | ||
| {{- if .Values.autoscaling.behavior.scaleDown.selectPolicy }} | ||
| selectPolicy: {{ .Values.autoscaling.behavior.scaleDown.selectPolicy }} | ||
| {{- end }} | ||
| {{- if .Values.autoscaling.behavior.scaleDown.policies }} | ||
| policies: | ||
| {{- toYaml .Values.autoscaling.behavior.scaleDown.policies | nindent 8 }} | ||
| {{- else }} | ||
| policies: | ||
| - type: Pods | ||
| value: {{ .Values.autoscaling.behavior.scaleDown.podScaleDownValue | default 1 }} | ||
| periodSeconds: {{ .Values.autoscaling.behavior.scaleDown.periodSeconds | default 60 }} |
There was a problem hiding this comment.
Same issue as scaleUp: if .Values.autoscaling.behavior.scaleDown.policies won’t distinguish between an absent key and an explicitly empty list, so policies: [] can’t be used to override/clear the defaults. Use a presence check (e.g., hasKey on the scaleDown map) to honor an explicit empty list and only apply defaults when the key is not set.
| scaleDown: | |
| stabilizationWindowSeconds: {{ .Values.autoscaling.behavior.scaleDown.stabilizationWindowSeconds | default 300 }} | |
| {{- if .Values.autoscaling.behavior.scaleDown.selectPolicy }} | |
| selectPolicy: {{ .Values.autoscaling.behavior.scaleDown.selectPolicy }} | |
| {{- end }} | |
| {{- if .Values.autoscaling.behavior.scaleDown.policies }} | |
| policies: | |
| {{- toYaml .Values.autoscaling.behavior.scaleDown.policies | nindent 8 }} | |
| {{- else }} | |
| policies: | |
| - type: Pods | |
| value: {{ .Values.autoscaling.behavior.scaleDown.podScaleDownValue | default 1 }} | |
| periodSeconds: {{ .Values.autoscaling.behavior.scaleDown.periodSeconds | default 60 }} | |
| {{- $scaleDown := .Values.autoscaling.behavior.scaleDown | default dict }} | |
| scaleDown: | |
| stabilizationWindowSeconds: {{ $scaleDown.stabilizationWindowSeconds | default 300 }} | |
| {{- if $scaleDown.selectPolicy }} | |
| selectPolicy: {{ $scaleDown.selectPolicy }} | |
| {{- end }} | |
| {{- if hasKey $scaleDown "policies" }} | |
| policies: | |
| {{- toYaml $scaleDown.policies | nindent 8 }} | |
| {{- else }} | |
| policies: | |
| - type: Pods | |
| value: {{ $scaleDown.podScaleDownValue | default 1 }} | |
| periodSeconds: {{ $scaleDown.periodSeconds | default 60 }} |
| value: {{ .Values.autoscaling.behavior.scaleUp.podScaleUpValue | default 4 }} | ||
| periodSeconds: {{ .Values.autoscaling.behavior.scaleUp.periodSeconds | default 15 }} | ||
| - type: Percent | ||
| value: {{ .Values.autoscaling.behavior.scaleUp.percentScaleUpValue | default 100 }} | ||
| periodSeconds: {{ .Values.autoscaling.behavior.scaleUp.periodSeconds | default 15 }} |
There was a problem hiding this comment.
The template fallbacks for scaleUp don’t match the chart’s defaults in values.yaml (values.yaml sets podScaleUpValue: 2 and periodSeconds: 2, but the template defaults to 4 and 15). Align these defaults (or drop the | default here if you expect values.yaml to always define them) to avoid surprising behavior when users partially override autoscaling.behavior.scaleUp.
| # selectPolicy: Max | ||
| podScaleUpValue: 2 | ||
| percentScaleUpValue: 100 | ||
| periodSeconds: 2 | ||
| # policies: | ||
| # - type: Pods | ||
| # value: 2 | ||
| # periodSeconds: 2 | ||
| scaleDown: | ||
| stabilizationWindowSeconds: 300 | ||
| # selectPolicy: Min | ||
| podScaleDownValue: 1 |
There was a problem hiding this comment.
selectPolicy examples here only show Max/Min, but the feature description mentions Disabled as well. Consider updating these commented examples to include/mention Disabled so users discover the full allowed set.
Split from #172 per @sk-portkey's feedback — HPA enhancements only, redis.deployLocal removed.
autoscaling.customMetricsfor injecting arbitrary HPA metricsselectPolicy(Max/Min/Disabled) for scaleUp and scaleDown behaviorpoliciesoverride per direction; existing defaults preserved when not specifiedValidated with
helm lintandhelm template(default values + custom overrides).