Skip to content

Commit 385b686

Browse files
authored
api: use consistent naming for cel/extproc (#369)
**Commit Message** This renames some field and constant of API. The first is to rename externalProcess -> externalProcessor where the latter is the official naming in Envoy documentation and API. The second is to rename LLMRequestCost.celExpression -> LLMRequestCost.cel where the short version matches the LLMRequestCostTypeCEL value "CEL" plus the suffix doesn't add any useful context. --------- Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent ab583ca commit 385b686

File tree

20 files changed

+101
-101
lines changed

20 files changed

+101
-101
lines changed

api/v1alpha1/api.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type AIGatewayRouteSpec struct {
9595
// An AI Gateway filter is responsible for the transformation of the request and response
9696
// as well as the routing behavior based on the model name extracted from the request content, etc.
9797
//
98-
// Currently, the filter is only implemented as an external process filter, which might be
98+
// Currently, the filter is only implemented as an external processor filter, which might be
9999
// extended to other types of filters in the future. See https://github.com/envoyproxy/ai-gateway/issues/90
100100
FilterConfig *AIGatewayFilterConfig `json:"filterConfig,omitempty"`
101101

@@ -251,39 +251,39 @@ type AIGatewayRouteRuleMatch struct {
251251
type AIGatewayFilterConfig struct {
252252
// Type specifies the type of the filter configuration.
253253
//
254-
// Currently, only ExternalProcess is supported, and default is ExternalProcess.
254+
// Currently, only ExternalProcessor is supported, and default is ExternalProcessor.
255255
//
256-
// +kubebuilder:default=ExternalProcess
256+
// +kubebuilder:default=ExternalProcessor
257257
Type AIGatewayFilterConfigType `json:"type"`
258258

259-
// ExternalProcess is the configuration for the external process filter.
259+
// ExternalProcessor is the configuration for the external processor filter.
260260
// This is optional, and if not set, the default values of Deployment spec will be used.
261261
//
262262
// +optional
263-
ExternalProcess *AIGatewayFilterConfigExternalProcess `json:"externalProcess,omitempty"`
263+
ExternalProcessor *AIGatewayFilterConfigExternalProcessor `json:"externalProcessor,omitempty"`
264264
}
265265

266266
// AIGatewayFilterConfigType specifies the type of the filter configuration.
267267
//
268-
// +kubebuilder:validation:Enum=ExternalProcess;DynamicModule
268+
// +kubebuilder:validation:Enum=ExternalProcessor;DynamicModule
269269
type AIGatewayFilterConfigType string
270270

271271
const (
272-
AIGatewayFilterConfigTypeExternalProcess AIGatewayFilterConfigType = "ExternalProcess"
273-
AIGatewayFilterConfigTypeDynamicModule AIGatewayFilterConfigType = "DynamicModule" // Reserved for https://github.com/envoyproxy/ai-gateway/issues/90
272+
AIGatewayFilterConfigTypeExternalProcessor AIGatewayFilterConfigType = "ExternalProcessor"
273+
AIGatewayFilterConfigTypeDynamicModule AIGatewayFilterConfigType = "DynamicModule" // Reserved for https://github.com/envoyproxy/ai-gateway/issues/90
274274
)
275275

276-
type AIGatewayFilterConfigExternalProcess struct {
277-
// Replicas is the number of desired pods of the external process deployment.
276+
type AIGatewayFilterConfigExternalProcessor struct {
277+
// Replicas is the number of desired pods of the external processor deployment.
278278
//
279279
// +optional
280280
Replicas *int32 `json:"replicas,omitempty"`
281-
// Resources required by the external process container.
281+
// Resources required by the external processor container.
282282
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
283283
//
284284
// +optional
285285
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
286-
// TODO: maybe adding the option not to deploy the external process filter and let the user deploy it manually?
286+
// TODO: maybe adding the option not to deploy the external processor filter and let the user deploy it manually?
287287
// Not sure if it is worth it as we are migrating to dynamic modules.
288288
}
289289

@@ -509,7 +509,7 @@ type LLMRequestCost struct {
509509
//
510510
// +kubebuilder:validation:Enum=OutputToken;InputToken;TotalToken;CEL
511511
Type LLMRequestCostType `json:"type"`
512-
// CELExpression is the CEL expression to calculate the cost of the request.
512+
// CEL is the CEL expression to calculate the cost of the request.
513513
// The CEL expression must return a signed or unsigned integer. If the
514514
// return value is negative, it will be error.
515515
//
@@ -529,7 +529,7 @@ type LLMRequestCost struct {
529529
// * "input_tokens * output_tokens"
530530
//
531531
// +optional
532-
CELExpression *string `json:"celExpression,omitempty"`
532+
CEL *string `json:"cel,omitempty"`
533533
}
534534

535535
// LLMRequestCostType specifies the type of the LLMRequestCost.

api/v1alpha1/zz_generated.deepcopy.go

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/proposals/001-ai-gateway-proposal/proposal.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Rules []AIGatewayRouteRule `json:"rules"`
124124
// An AI Gateway filter is responsible for the transformation of the request and response
125125
// as well as the routing behavior based on the model name extracted from the request content, etc.
126126
//
127-
// Currently, the filter is only implemented as an external process filter, which might be
127+
// Currently, the filter is only implemented as an external processor filter, which might be
128128
// extended to other types of filters in the future. See https://github.com/envoyproxy/ai-gateway/issues/90
129129
FilterConfig *AIGatewayFilterConfig `json:"filterConfig,omitempty"`
130130

@@ -184,9 +184,9 @@ type LLMRequestCost struct {
184184
MetadataKey string `json:"metadataKey"`
185185
// Type is the kind of the request cost calculation.
186186
Type LLMRequestCostType `json:"type"`
187-
// CELExpression is the CEL expression to calculate the cost of the request.
188-
// This is not empty when the Type is LLMRequestCostTypeCELExpression.
189-
CELExpression string `json:"celExpression,omitempty"`
187+
// CEL is the CEL expression to calculate the cost of the request.
188+
// This is not empty when the Type is LLMRequestCostTypeCEL.
189+
CEL string `json:"cel,omitempty"`
190190
}
191191
```
192192

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This example shows how to insert a custom router in the custom external process using `filterapi` package.
1+
This example shows how to insert a custom router in the custom external processor using `filterapi` package.

examples/token_ratelimit/token_ratelimit.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ spec:
5555
# otherwise it returns 0 (no token usage).
5656
- metadataKey: llm_cel_calculated_token
5757
type: CEL
58-
celExpression: "input_tokens == uint(3) ? 100000000 : 0"
58+
cel: "input_tokens == uint(3) ? 100000000 : 0"
5959
---
6060
apiVersion: aigateway.envoyproxy.io/v1alpha1
6161
kind: AIServiceBackend

filterapi/filterconfig.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ type LLMRequestCost struct {
102102
MetadataKey string `json:"metadataKey"`
103103
// Type is the kind of the request cost calculation.
104104
Type LLMRequestCostType `json:"type"`
105-
// CELExpression is the CEL expression to calculate the cost of the request.
106-
// This is not empty when the Type is LLMRequestCostTypeCELExpression.
107-
CELExpression string `json:"celExpression,omitempty"`
105+
// CEL is the CEL expression to calculate the cost of the request.
106+
// This is not empty when the Type is LLMRequestCostTypeCEL.
107+
CEL string `json:"cel,omitempty"`
108108
}
109109

110110
// LLMRequestCostType specifies the kind of the request cost calculation.
@@ -117,8 +117,8 @@ const (
117117
LLMRequestCostTypeInputToken LLMRequestCostType = "InputToken"
118118
// LLMRequestCostTypeTotalToken specifies that the request cost is calculated from the total token.
119119
LLMRequestCostTypeTotalToken LLMRequestCostType = "TotalToken"
120-
// LLMRequestCostTypeCELExpression specifies that the request cost is calculated from the CEL expression.
121-
LLMRequestCostTypeCELExpression LLMRequestCostType = "CEL"
120+
// LLMRequestCostTypeCEL specifies that the request cost is calculated from the CEL expression.
121+
LLMRequestCostTypeCEL LLMRequestCostType = "CEL"
122122
)
123123

124124
// VersionedAPISchema corresponds to VersionedAPISchema in api/v1alpha1/api.go.

internal/controller/ai_gateway_route.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (c *AIGatewayRouteController) reconcileExtProcExtensionPolicy(ctx context.C
154154
}
155155

156156
// ensuresExtProcConfigMapExists ensures that a configmap exists for the external process.
157-
// This must happen before the external process deployment is created.
157+
// This must happen before the external processor deployment is created.
158158
func (c *AIGatewayRouteController) ensuresExtProcConfigMapExists(ctx context.Context, aiGatewayRoute *aigv1a1.AIGatewayRoute) (err error) {
159159
name := extProcName(aiGatewayRoute)
160160
// Check if a configmap exists for extproc exists, and if not, create one with the default config.
@@ -180,10 +180,10 @@ func extProcName(route *aigv1a1.AIGatewayRoute) string {
180180
}
181181

182182
func applyExtProcDeploymentConfigUpdate(d *appsv1.DeploymentSpec, filterConfig *aigv1a1.AIGatewayFilterConfig) {
183-
if filterConfig == nil || filterConfig.ExternalProcess == nil {
183+
if filterConfig == nil || filterConfig.ExternalProcessor == nil {
184184
return
185185
}
186-
extProc := filterConfig.ExternalProcess
186+
extProc := filterConfig.ExternalProcessor
187187
if resource := extProc.Resources; resource != nil {
188188
d.Template.Spec.Containers[0].Resources = *resource
189189
}
@@ -277,7 +277,7 @@ func (c *AIGatewayRouteController) syncAIGatewayRoute(ctx context.Context, aiGat
277277
return nil
278278
}
279279

280-
// updateExtProcConfigMap updates the external process configmap with the new AIGatewayRoute.
280+
// updateExtProcConfigMap updates the external processor configmap with the new AIGatewayRoute.
281281
func (c *AIGatewayRouteController) updateExtProcConfigMap(ctx context.Context, aiGatewayRoute *aigv1a1.AIGatewayRoute, uuid string) error {
282282
configMap, err := c.kube.CoreV1().ConfigMaps(aiGatewayRoute.Namespace).Get(ctx, extProcName(aiGatewayRoute), metav1.GetOptions{})
283283
if err != nil {
@@ -360,14 +360,14 @@ func (c *AIGatewayRouteController) updateExtProcConfigMap(ctx context.Context, a
360360
case aigv1a1.LLMRequestCostTypeTotalToken:
361361
fc.Type = filterapi.LLMRequestCostTypeTotalToken
362362
case aigv1a1.LLMRequestCostTypeCEL:
363-
fc.Type = filterapi.LLMRequestCostTypeCELExpression
364-
expr := *cost.CELExpression
363+
fc.Type = filterapi.LLMRequestCostTypeCEL
364+
expr := *cost.CEL
365365
// Sanity check the CEL expression.
366366
_, err = llmcostcel.NewProgram(expr)
367367
if err != nil {
368368
return fmt.Errorf("invalid CEL expression: %w", err)
369369
}
370-
fc.CELExpression = expr
370+
fc.CEL = expr
371371
default:
372372
return fmt.Errorf("unknown request cost type: %s", cost.Type)
373373
}

internal/controller/ai_gateway_route_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func Test_applyExtProcDeploymentConfigUpdate(t *testing.T) {
173173
applyExtProcDeploymentConfigUpdate(dep, nil)
174174
applyExtProcDeploymentConfigUpdate(dep, &aigv1a1.AIGatewayFilterConfig{})
175175
applyExtProcDeploymentConfigUpdate(dep, &aigv1a1.AIGatewayFilterConfig{
176-
ExternalProcess: &aigv1a1.AIGatewayFilterConfigExternalProcess{},
176+
ExternalProcessor: &aigv1a1.AIGatewayFilterConfigExternalProcessor{},
177177
})
178178
})
179179
t.Run("update", func(t *testing.T) {
@@ -184,7 +184,7 @@ func Test_applyExtProcDeploymentConfigUpdate(t *testing.T) {
184184
},
185185
}
186186
applyExtProcDeploymentConfigUpdate(dep, &aigv1a1.AIGatewayFilterConfig{
187-
ExternalProcess: &aigv1a1.AIGatewayFilterConfigExternalProcess{
187+
ExternalProcessor: &aigv1a1.AIGatewayFilterConfigExternalProcessor{
188188
Resources: &req,
189189
Replicas: ptr.To[int32](123),
190190
},
@@ -535,9 +535,9 @@ func TestAIGatewayRouteController_updateExtProcConfigMap(t *testing.T) {
535535
MetadataKey: "total-token",
536536
},
537537
{
538-
Type: aigv1a1.LLMRequestCostTypeCEL,
539-
MetadataKey: "cel-token",
540-
CELExpression: ptr.To("model == 'cool_model' ? input_tokens * output_tokens : total_tokens"),
538+
Type: aigv1a1.LLMRequestCostTypeCEL,
539+
MetadataKey: "cel-token",
540+
CEL: ptr.To("model == 'cool_model' ? input_tokens * output_tokens : total_tokens"),
541541
},
542542
},
543543
},
@@ -590,7 +590,7 @@ func TestAIGatewayRouteController_updateExtProcConfigMap(t *testing.T) {
590590
{Type: filterapi.LLMRequestCostTypeOutputToken, MetadataKey: "output-token"},
591591
{Type: filterapi.LLMRequestCostTypeInputToken, MetadataKey: "input-token"},
592592
{Type: filterapi.LLMRequestCostTypeTotalToken, MetadataKey: "total-token"},
593-
{Type: filterapi.LLMRequestCostTypeCELExpression, MetadataKey: "cel-token", CELExpression: "model == 'cool_model' ? input_tokens * output_tokens : total_tokens"},
593+
{Type: filterapi.LLMRequestCostTypeCEL, MetadataKey: "cel-token", CEL: "model == 'cool_model' ? input_tokens * output_tokens : total_tokens"},
594594
},
595595
},
596596
},
@@ -675,8 +675,8 @@ func TestAIGatewayRouteController_syncExtProcDeployment(t *testing.T) {
675675
},
676676
Spec: aigv1a1.AIGatewayRouteSpec{
677677
FilterConfig: &aigv1a1.AIGatewayFilterConfig{
678-
Type: aigv1a1.AIGatewayFilterConfigTypeExternalProcess,
679-
ExternalProcess: &aigv1a1.AIGatewayFilterConfigExternalProcess{
678+
Type: aigv1a1.AIGatewayFilterConfigTypeExternalProcessor,
679+
ExternalProcessor: &aigv1a1.AIGatewayFilterConfigExternalProcessor{
680680
Replicas: ptr.To[int32](123),
681681
Resources: &corev1.ResourceRequirements{
682682
Limits: corev1.ResourceList{
@@ -755,8 +755,8 @@ func TestAIGatewayRouteController_syncExtProcDeployment(t *testing.T) {
755755
corev1.ResourceMemory: resource.MustParse("32Mi"),
756756
},
757757
}
758-
aiGatewayRoute.Spec.FilterConfig.ExternalProcess.Resources = newResourceLimits
759-
aiGatewayRoute.Spec.FilterConfig.ExternalProcess.Replicas = ptr.To[int32](456)
758+
aiGatewayRoute.Spec.FilterConfig.ExternalProcessor.Resources = newResourceLimits
759+
aiGatewayRoute.Spec.FilterConfig.ExternalProcessor.Replicas = ptr.To[int32](456)
760760

761761
require.NoError(t, s.syncExtProcDeployment(t.Context(), aiGatewayRoute))
762762
// Check the deployment is updated.

internal/extproc/chatcompletion_processor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (c *chatCompletionProcessor) maybeBuildDynamicMetadata() (*structpb.Struct,
219219
cost = c.costs.OutputTokens
220220
case filterapi.LLMRequestCostTypeTotalToken:
221221
cost = c.costs.TotalTokens
222-
case filterapi.LLMRequestCostTypeCELExpression:
222+
case filterapi.LLMRequestCostTypeCEL:
223223
costU64, err := llmcostcel.EvaluateProgram(
224224
rc.celProg,
225225
c.requestHeaders[c.config.modelNameHeaderKey],

internal/extproc/chatcompletion_processor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ func TestChatCompletion_ProcessResponseBody(t *testing.T) {
114114
{LLMRequestCost: &filterapi.LLMRequestCost{Type: filterapi.LLMRequestCostTypeInputToken, MetadataKey: "input_token_usage"}},
115115
{
116116
celProg: celProgInt,
117-
LLMRequestCost: &filterapi.LLMRequestCost{Type: filterapi.LLMRequestCostTypeCELExpression, MetadataKey: "cel_int"},
117+
LLMRequestCost: &filterapi.LLMRequestCost{Type: filterapi.LLMRequestCostTypeCEL, MetadataKey: "cel_int"},
118118
},
119119
{
120120
celProg: celProgUint,
121-
LLMRequestCost: &filterapi.LLMRequestCost{Type: filterapi.LLMRequestCostTypeCELExpression, MetadataKey: "cel_uint"},
121+
LLMRequestCost: &filterapi.LLMRequestCost{Type: filterapi.LLMRequestCostTypeCEL, MetadataKey: "cel_uint"},
122122
},
123123
},
124124
}}

internal/extproc/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636

3737
var sensitiveHeaderKeys = []string{"authorization"}
3838

39-
// Server implements the external process server.
39+
// Server implements the external processor server.
4040
type Server struct {
4141
logger *slog.Logger
4242
config *processorConfig
@@ -90,8 +90,8 @@ func (s *Server) LoadConfig(ctx context.Context, config *filterapi.Config) error
9090
for i := range config.LLMRequestCosts {
9191
c := &config.LLMRequestCosts[i]
9292
var prog cel.Program
93-
if c.CELExpression != "" {
94-
prog, err = llmcostcel.NewProgram(c.CELExpression)
93+
if c.CEL != "" {
94+
prog, err = llmcostcel.NewProgram(c.CEL)
9595
if err != nil {
9696
return fmt.Errorf("cannot create CEL program for cost: %w", err)
9797
}

internal/extproc/server_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestServer_LoadConfig(t *testing.T) {
4242
MetadataNamespace: "ns",
4343
LLMRequestCosts: []filterapi.LLMRequestCost{
4444
{MetadataKey: "key", Type: filterapi.LLMRequestCostTypeOutputToken},
45-
{MetadataKey: "cel_key", Type: filterapi.LLMRequestCostTypeCELExpression, CELExpression: "1 + 1"},
45+
{MetadataKey: "cel_key", Type: filterapi.LLMRequestCostTypeCEL, CEL: "1 + 1"},
4646
},
4747
Schema: filterapi.VersionedAPISchema{Name: filterapi.APISchemaOpenAI},
4848
SelectedBackendHeaderKey: "x-ai-eg-selected-backend",
@@ -87,8 +87,8 @@ func TestServer_LoadConfig(t *testing.T) {
8787
require.Len(t, s.config.requestCosts, 2)
8888
require.Equal(t, filterapi.LLMRequestCostTypeOutputToken, s.config.requestCosts[0].Type)
8989
require.Equal(t, "key", s.config.requestCosts[0].MetadataKey)
90-
require.Equal(t, filterapi.LLMRequestCostTypeCELExpression, s.config.requestCosts[1].Type)
91-
require.Equal(t, "1 + 1", s.config.requestCosts[1].CELExpression)
90+
require.Equal(t, filterapi.LLMRequestCostTypeCEL, s.config.requestCosts[1].Type)
91+
require.Equal(t, "1 + 1", s.config.requestCosts[1].CEL)
9292
prog := s.config.requestCosts[1].celProg
9393
require.NotNil(t, prog)
9494
val, err := llmcostcel.EvaluateProgram(prog, "", "", 1, 1, 1)

0 commit comments

Comments
 (0)