Skip to content

feat(hpa): add customMetrics, selectPolicy, and configurable policies#177

Open
camjay wants to merge 1 commit into
Portkey-AI:mainfrom
camjay:feat/hpa-enhancements
Open

feat(hpa): add customMetrics, selectPolicy, and configurable policies#177
camjay wants to merge 1 commit into
Portkey-AI:mainfrom
camjay:feat/hpa-enhancements

Conversation

@camjay
Copy link
Copy Markdown
Contributor

@camjay camjay commented Apr 2, 2026

Split from #172 per @sk-portkey's feedback — HPA enhancements only, redis.deployLocal removed.

  • Support autoscaling.customMetrics for injecting arbitrary HPA metrics
  • Add selectPolicy (Max/Min/Disabled) for scaleUp and scaleDown behavior
  • Allow full policies override per direction; existing defaults preserved when not specified

Validated with helm lint and helm template (default values + custom overrides).

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.customMetrics to append arbitrary HPA metrics entries.
  • Add selectPolicy support for both scaleUp and scaleDown behavior.
  • 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.

Comment on lines +41 to +44
{{- if .Values.autoscaling.behavior.scaleUp.policies }}
policies:
{{- toYaml .Values.autoscaling.behavior.scaleUp.policies | nindent 8 }}
{{- else }}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 65
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 }}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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 }}

Copilot uses AI. Check for mistakes.
Comment on lines 47 to 51
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 }}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +245 to 256
# selectPolicy: Max
podScaleUpValue: 2
percentScaleUpValue: 100
periodSeconds: 2
# policies:
# - type: Pods
# value: 2
# periodSeconds: 2
scaleDown:
stabilizationWindowSeconds: 300
# selectPolicy: Min
podScaleDownValue: 1
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants