Skip to content

Commit 43ee93e

Browse files
committed
add docs and client use case for external-filter
Signed-off-by: rayneLi <[email protected]>
1 parent d874c56 commit 43ee93e

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

docs/source/features/gateway-plugins.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,38 @@ To set up rate limiting, add the user header in the request, like this:
194194
If rate limit support is required, ensure this `user` header is always set in the request. if you do not need rate limit, you do not need to set this header.
195195

196196

197+
External Filter
198+
===============
199+
The ``external-filter`` header is evaluated **after** the routing strategy selects the optimal Pod set. allows users to dynamically restrict the target Pods using Kubernetes ``labelSelector`` expressions.
200+
201+
The header value follows the Kubernetes label selector syntax:
202+
203+
- ``key=value``
204+
- ``key in (a, b)``
205+
- ``key!=value``
206+
- comma-separated selector list
207+
208+
For label selector syntax reference:
209+
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
210+
211+
.. code-block:: bash
212+
curl -v http://${ENDPOINT}/v1/completions \
213+
-H "Content-Type: application/json" \
214+
-H "routing-strategy: random" \
215+
-H "external-filter: environment=production,tier=frontend" \
216+
-d '{
217+
"model": "deepseek-r1-distill-llama-8b",
218+
"prompt": "San Francisco is a",
219+
"max_tokens": 128,
220+
"temperature": 0
221+
}'
222+
223+
.. note::
224+
1. Filtering happens **after** the routing strategy. It never changes which Pods are considered “optimal” by the routing strategy.
225+
2. It only reduces the eligible Pod set by applying extra label constraints.
226+
3. Same as `no target pod`, If the filter eliminates all Pods, the request will fail with ``no ready pods for routing``.
227+
4. ``external-filter`` is optional. When omitted, no extra filtering is applied.
228+
197229
Headers Explanation
198230
--------------------
199231

@@ -216,7 +248,8 @@ Target Headers & General Error Headers
216248
- Specifies the destination pod selected by the routing algorithm. Useful for verifying routing decisions.
217249
* - ``routing-strategy``
218250
- Defines the routing strategy applied to this request. Ensures correct routing logic is followed.
219-
251+
* - ``external-filter``
252+
- Provides a generic and pluggable mechanism to further filter candidate Pods after routing.
220253

221254
Routing & Error Debugging Headers
222255
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

pkg/plugins/gateway/gateway_req_body.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,19 @@ func (s *Server) HandleRequestBody(ctx context.Context, requestID string, req *e
7474
headers = buildEnvoyProxyHeaders(headers, HeaderModel, model)
7575
klog.InfoS("request start", "requestID", requestID, "requestPath", requestPath, "model", model, "stream", stream)
7676
} else {
77-
// external filter in header
77+
// external-filter in header, value is k8s labelSelector format https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
78+
// like: environment=production,tier=frontend; environment in (production, qa)
79+
// full request example:
80+
// curl -v http://${ENDPOINT}/v1/completions \
81+
// -H "Content-Type: application/json" \
82+
// -H "routing-strategy: random" \
83+
// -H "external-filter: key1=value1,key2=value2" \
84+
// -d '{
85+
// "model": "deepseek-r1-distill-llama-8b",
86+
// "prompt": "San Francisco is a",
87+
// "max_tokens": 128,
88+
// "temperature": 0
89+
// }'
7890
externalFilter := routingCtx.ReqHeaders[HeaderExternalFilter]
7991
klog.InfoS("found external filter", "filter", externalFilter)
8092
targetPodIP, err := s.selectTargetPod(routingCtx, podsArr, externalFilter)

0 commit comments

Comments
 (0)