forked from kubernetes-sigs/gateway-api-inference-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
69 lines (57 loc) · 1.81 KB
/
plugin.go
File metadata and controls
69 lines (57 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package dynamo_inject_workerid
import (
"context"
"encoding/json"
"strings"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
rc "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
schedtypes "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
)
const (
typeString = "dynamo-inject-workerid"
pluginName = "dynamo-inject-workerid"
WorkerIDHeader = "x-worker-instance-id"
injectHintHeader = "x-epp-inject-nvext-worker-instance-id"
TokenDataHeader = "x-epp-inject-nvext-token-data"
)
var _ plugins.Plugin = (*InjectWorkerIDPreRequest)(nil)
var _ rc.PreRequest = (*InjectWorkerIDPreRequest)(nil)
type InjectWorkerIDPreRequest struct {
typedName plugins.TypedName
}
func NewInjectWorkerIDPreRequest() *InjectWorkerIDPreRequest {
return &InjectWorkerIDPreRequest{
typedName: plugins.TypedName{Type: typeString, Name: pluginName},
}
}
func (p *InjectWorkerIDPreRequest) WithName(name string) *InjectWorkerIDPreRequest {
p.typedName.Name = name
return p
}
func InjectWorkerIDPreRequestFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
return NewInjectWorkerIDPreRequest().WithName(name), nil
}
func (p *InjectWorkerIDPreRequest) TypedName() plugins.TypedName { return p.typedName }
func (p *InjectWorkerIDPreRequest) PreRequest(
_ context.Context,
req *schedtypes.LLMRequest,
_ *schedtypes.SchedulingResult,
_ int,
) {
if req == nil {
return
}
if req.Headers == nil {
req.Headers = map[string]string{}
}
wid := strings.TrimSpace(req.Headers[WorkerIDHeader])
if wid == "" {
return
}
req.Headers[WorkerIDHeader] = wid
req.Headers[injectHintHeader] = wid
// Pass through token-data header if scorer set it
if td := strings.TrimSpace(req.Headers[TokenDataHeader]); td != "" {
req.Headers[TokenDataHeader] = td
}
}