-
Notifications
You must be signed in to change notification settings - Fork 5
Support autoscaling the API on GKE #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brianvans (brianvans)
merged 13 commits into
main
from
brianvans/support-autoscaling-api-on-gke
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d8ded2e
Support autoscaling the API on GKE
brianvans a31c39b
Merge remote-tracking branch 'origin/main' into brianvans/support-aut…
brianvans f592b56
Inline docs for /metrics being added in v2.9.0
brianvans 4458285
Add gke autoscaling docs to README
brianvans fa13407
Force NABLE_PROMETHEUS_METRICS=true if autoscaled
brianvans 86f0fae
bump minReplicas at 4 when autoscaling enabled
brianvans 7acb818
Ensure the autoscaling.gke.io/v1beta1 CRD exists
brianvans 30591d3
Merge main into support-autoscaling-api-on-gke
brianvans a961e67
Closer align the autoscaling max sizes to ECS
brianvans 71da057
Add example values for autoscaling w/ dedicated api pools
brianvans 8405cde
formatting
brianvans d45fb9b
Expand tests and stop using brittle document indexes
brianvans 6148261
Narrow cpu scaling to just api container w/ ContainerResource
brianvans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
braintrust/examples/google-api-isolation-autoscaling/values.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Minimal GKE example with API workload isolation + per-pool autoscaling. | ||
| # | ||
| # Combine this with a normal google-autopilot (or google-standard) values | ||
| # file - only the fields below are specific to this pattern. | ||
| # | ||
| # Sizing: | ||
| # - api.autoscaling is shared by every pool | ||
| # - api.workloadIsolation.<pool>.autoscaling deep-merges on top | ||
| # - With autoscaling enabled, set capacity via minReplicas/maxReplicas | ||
| # (Helm `replicas` is not applied to those Deployments) | ||
| # | ||
| # Also requires GKE 1.35.1+ with AutoscalingMetric, and ingress routes for the | ||
| # isolation contract (see README & files/contracts/api-workload-isolation-routes.yaml). | ||
|
|
||
| api: | ||
| autoscaling: | ||
| enabled: true | ||
| minReplicas: 3 | ||
| maxReplicas: 40 | ||
| # Metric targets (inherited by every pool unless overridden below). | ||
| cpu: | ||
| targetAverageUtilization: 50 | ||
| eventLoopUtilization: | ||
| targetAverageValue: "0.4" # 0-1 ratio (0.4 is 40%) | ||
| eventLoopDelayMean: | ||
| targetAverageValue: "0.05" # seconds (0.05 is 50ms) | ||
| # HPA scale velocity (inherited by every pool unless overridden below). | ||
| behavior: | ||
| scaleDown: | ||
| stabilizationWindowSeconds: 300 | ||
| scaleUp: | ||
| stabilizationWindowSeconds: 60 | ||
| workloadIsolation: | ||
| enabled: true | ||
| ingest: | ||
| autoscaling: | ||
| minReplicas: 3 | ||
| maxReplicas: 60 | ||
| # Example pool-specific overrides: higher ELU target, faster scale-out. | ||
| eventLoopUtilization: | ||
| targetAverageValue: "0.5" # 0-1 ratio (0.5 is 50%) | ||
| behavior: | ||
| scaleUp: | ||
| stabilizationWindowSeconds: 30 | ||
| background: | ||
| autoscaling: | ||
| minReplicas: 3 | ||
| maxReplicas: 50 |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| {{- $root := . -}} | ||
| {{- $pools := include "braintrust.apiPools" . | fromYamlArray -}} | ||
| {{- $validated := false -}} | ||
| {{- $rendered := 0 -}} | ||
| {{- range $pool := $pools -}} | ||
| {{- $api := $pool.config -}} | ||
| {{- if dig "autoscaling" "enabled" false $api -}} | ||
| {{- if not $validated -}} | ||
| {{- include "braintrust.apiAutoscaling.validate" $root -}} | ||
| {{- $validated = true -}} | ||
| {{- end -}} | ||
| {{- if gt $rendered 0 }} | ||
| --- | ||
| {{- end }} | ||
| {{- $poolLabels := dict -}} | ||
| {{- if or $root.Values.api.workloadIsolation.enabled (ne $pool.role "default") -}} | ||
| {{- $_ := set $poolLabels "braintrust.dev/api-pool" $pool.role -}} | ||
| {{- end -}} | ||
| {{- $resourceLabels := mergeOverwrite (deepCopy $root.Values.global.labels) (deepCopy $api.labels) $poolLabels -}} | ||
| apiVersion: autoscaling.gke.io/v1beta1 | ||
| kind: AutoscalingMetric | ||
| metadata: | ||
| name: {{ $api.name }} | ||
| namespace: {{ include "braintrust.namespace" $root }} | ||
| {{- with $resourceLabels }} | ||
| labels: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| {{- with $api.annotations.autoscalingMetric }} | ||
| annotations: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| spec: | ||
| metrics: | ||
| - pod: | ||
| selector: | ||
| matchLabels: | ||
| app: {{ $api.name }} | ||
| containers: | ||
| - endpoint: | ||
| port: {{ $api.healthServer.port }} | ||
| path: {{ $api.autoscaling.metricsPath }} | ||
| metrics: | ||
| - gauge: | ||
| # GKE gauge names must match ^[a-z]([-a-z0-9]*[a-z0-9])? | ||
| name: braintrust-api-event-loop-utilization-ratio | ||
| prometheusMetricName: braintrust_api_event_loop_utilization_ratio | ||
| - gauge: | ||
| name: braintrust-api-event-loop-delay-mean-seconds | ||
| prometheusMetricName: braintrust_api_event_loop_delay_mean_seconds | ||
| {{- $rendered = add1 $rendered -}} | ||
| {{- end -}} | ||
| {{- end }} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| {{- $root := . -}} | ||
| {{- $pools := include "braintrust.apiPools" . | fromYamlArray -}} | ||
| {{- $validated := false -}} | ||
| {{- $rendered := 0 -}} | ||
| {{- range $pool := $pools -}} | ||
| {{- $api := $pool.config -}} | ||
| {{- if dig "autoscaling" "enabled" false $api -}} | ||
| {{- if not $validated -}} | ||
| {{- include "braintrust.apiAutoscaling.validate" $root -}} | ||
| {{- $validated = true -}} | ||
| {{- end -}} | ||
| {{- if gt $rendered 0 }} | ||
| --- | ||
| {{- end }} | ||
| {{- $poolLabels := dict -}} | ||
| {{- if or $root.Values.api.workloadIsolation.enabled (ne $pool.role "default") -}} | ||
| {{- $_ := set $poolLabels "braintrust.dev/api-pool" $pool.role -}} | ||
| {{- end -}} | ||
| {{- $resourceLabels := mergeOverwrite (deepCopy $root.Values.global.labels) (deepCopy $api.labels) $poolLabels -}} | ||
| apiVersion: autoscaling/v2 | ||
| kind: HorizontalPodAutoscaler | ||
| metadata: | ||
| name: {{ $api.name }} | ||
| namespace: {{ include "braintrust.namespace" $root }} | ||
| {{- with $resourceLabels }} | ||
| labels: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| {{- with $api.annotations.hpa }} | ||
| annotations: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| spec: | ||
| scaleTargetRef: | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| name: {{ $api.name }} | ||
| minReplicas: {{ $api.autoscaling.minReplicas }} | ||
| maxReplicas: {{ $api.autoscaling.maxReplicas }} | ||
| metrics: | ||
| # ContainerResource scopes CPU to the api container so sidecars / extraContainers | ||
| # do not skew utilization. Custom Pods metrics are already API-scoped via /metrics. | ||
| - type: ContainerResource | ||
| containerResource: | ||
| name: cpu | ||
| container: api | ||
| target: | ||
| type: Utilization | ||
| averageUtilization: {{ $api.autoscaling.cpu.targetAverageUtilization }} | ||
| - type: Pods | ||
| pods: | ||
| metric: | ||
| name: autoscaling.gke.io|{{ $api.name }}|braintrust-api-event-loop-utilization-ratio | ||
| target: | ||
| type: AverageValue | ||
| averageValue: {{ $api.autoscaling.eventLoopUtilization.targetAverageValue | quote }} | ||
| - type: Pods | ||
| pods: | ||
| metric: | ||
| name: autoscaling.gke.io|{{ $api.name }}|braintrust-api-event-loop-delay-mean-seconds | ||
| target: | ||
| type: AverageValue | ||
| averageValue: {{ $api.autoscaling.eventLoopDelayMean.targetAverageValue | quote }} | ||
| {{- with $api.autoscaling.behavior }} | ||
| behavior: | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| {{- $rendered = add1 $rendered -}} | ||
| {{- end -}} | ||
| {{- end }} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| suite: test API autoscaling CRD requirement | ||
| templates: | ||
| - api-hpa.yaml | ||
| # Do not advertise autoscaling.gke.io here — this suite asserts the fail path. | ||
| tests: | ||
| - it: should fail when AutoscalingMetric API is unavailable | ||
| template: api-hpa.yaml | ||
| values: | ||
| - __fixtures__/base-values.yaml | ||
| set: | ||
| cloud: google | ||
| api.autoscaling.enabled: true | ||
| release: | ||
| namespace: "braintrust" | ||
| asserts: | ||
| - failedTemplate: | ||
| errorPattern: "api\\.autoscaling requires the AutoscalingMetric API \\(autoscaling\\.gke\\.io/v1beta1\\)" |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.