Skip to content

Conversation

@sukumargaonkar
Copy link
Contributor

@sukumargaonkar sukumargaonkar commented Oct 22, 2025

Description

This commit implements route-level HeaderMutation support for AIGatewayRouteRuleBackendRef. The feature allows users to define header mutations at the route level (per backend reference on AIGatewayRoute) in addition to the existing backend-level HeaderMutation support.

Key Features:

  • Route-level HeaderMutation: New headerMutation field in AIGatewayRouteRuleBackendRef for fine-grained header
    control per route
  • Smart merge logic: When both route-level and backend-level HeaderMutation are defined, they are intelligently combined
    with route-level taking precedence for conflicts
  • Case-insensitive handling: Proper header name normalization and conflict resolution (e.g., X-Custom vs x-custom
    are treated as the same header)
  • Full backward compatibility: Existing backend-level only configurations continue to work unchanged

Use Cases:
GCP Provisioned Throughput [docs [1]]:

  • Unlike bedrock where provisioned-throughput and pay-as-you-go (on-demand) models get different endpoints, in GCP both provisioned-throughput and pay-as-you-go get the same endpoint.
  • whether a request should be counted under provisioned-throughput or pay-as-you-go needs to be controlled via headers.
  • This change will allow configuring custom headers at route-level
apiVersion: aigateway.envoyproxy.io/v1alpha1
kind: AIGatewayRoute
metadata:
  annotations:
  name: gemini-2.5-flash
  namespace: gateway
spec:
  # ... other spec fields ...
  rules:
    - backendRefs:
        # Provisioned Throughput on Region-1
        - modelNameOverride: gemini-2.5-flash
          name: gcp-<region-1>
          priority: 0
          headerMutation:  # <-- New
            set:
              - name: X-Vertex-AI-LLM-Request-Type
                value: "dedicated"
        # Provisioned Throughput on Region-2
        - modelNameOverride: gemini-2.5-flash
          name: gcp-<region-2>
          priority: 0
          headerMutation:  # <-- New
            set:
              - name: X-Vertex-AI-LLM-Request-Type
                value: "dedicated"
        # Pay-As-You-GO on Region-1
        - modelNameOverride: gemini-2.5-flash
          name: gcp-<region-1>
          priority: 1
          headerMutation:  # <-- New
            set:
              - name: X-Vertex-AI-LLM-Request-Type
                value: "shared"
        # Pay-As-You-GO on Region-2
        - modelNameOverride: gemini-2.5-flash
          name: gcp-<region-2>
          priority: 1
          headerMutation:  # <-- New
            set:
              - name: X-Vertex-AI-LLM-Request-Type
                value: "shared"
  # ... other spec fields ...

1: https://cloud.google.com/vertex-ai/generative-ai/docs/provisioned-throughput/use-provisioned-throughput#limitations-of-the-dashboard

@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.67%. Comparing base (3df0a93) to head (835aba0).

❌ Your project status has failed because the head coverage (78.67%) is below the target coverage (86.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1414      +/-   ##
==========================================
+ Coverage   78.64%   78.67%   +0.03%     
==========================================
  Files         140      140              
  Lines       13789    13813      +24     
==========================================
+ Hits        10844    10868      +24     
  Misses       2289     2289              
  Partials      656      656              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mathetake mathetake self-assigned this Oct 23, 2025
…mutation

# Conflicts:
#	manifests/charts/ai-gateway-helm/crds/aigateway.envoyproxy.io_aigatewayroutes.yaml
@sukumargaonkar sukumargaonkar marked this pull request as ready for review October 24, 2025 13:48
@sukumargaonkar sukumargaonkar requested a review from a team as a code owner October 24, 2025 13:48
Copy link
Contributor

@aabchoo aabchoo left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Deferring to Takeshi as he is assigned to this

// Merge Set operations (route-level wins conflicts)
headerMap := make(map[string]gwapiv1.HTTPHeader)

// Add backend-level headers first
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why add comments for the Set logic but not the Remove? Also, add periods at the end of the comments.

Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

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

nit but looks good

@yuzisun yuzisun merged commit 2861c1b into envoyproxy:main Oct 26, 2025
30 checks passed
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.

5 participants