Skip to content

Commit d4b8c91

Browse files
committed
chore: drop plugin type from types and file
Signed-off-by: zxw <1020938856@qq.com>
1 parent 0b52219 commit d4b8c91

File tree

14 files changed

+142
-140
lines changed

14 files changed

+142
-140
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ go.work.sum
3131
# IDE files
3232
.idea
3333
.vscode
34+
35+
vendor

pkg/plugins/filter/by_label.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ import (
1111
)
1212

1313
const (
14-
// ByLabelFilterType is the type of the ByLabel filter
15-
ByLabelFilterType = "by-label"
14+
// ByLabelType is the type of the ByLabel filter
15+
ByLabelType = "by-label"
1616
)
1717

18-
type byLabelFilterParameters struct {
18+
type byLabelParameters struct {
1919
Label string `json:"label"`
2020
ValidValues []string `json:"validValues"`
2121
AllowsNoLabel bool `json:"allowsNoLabel"`
2222
}
2323

2424
var _ framework.Filter = &ByLabel{} // validate interface conformance
2525

26-
// ByLabelFilterFactory defines the factory function for the ByLabelFilter
27-
func ByLabelFilterFactory(name string, rawParameters json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
28-
parameters := byLabelFilterParameters{}
26+
// ByLabelFactory defines the factory function for the ByLabel filter.
27+
func ByLabelFactory(name string, rawParameters json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
28+
parameters := byLabelParameters{}
2929
if rawParameters != nil {
3030
if err := json.Unmarshal(rawParameters, &parameters); err != nil {
31-
return nil, fmt.Errorf("failed to parse the parameters of the '%s' filter - %w", ByLabelFilterType, err)
31+
return nil, fmt.Errorf("failed to parse the parameters of the '%s' filter - %w", ByLabelType, err)
3232
}
3333
}
3434
return NewByLabel(name, parameters.Label, parameters.AllowsNoLabel, parameters.ValidValues...), nil
@@ -47,7 +47,7 @@ func NewByLabel(name string, labelName string, allowsNoLabel bool, validValues .
4747
}
4848

4949
return &ByLabel{
50-
typedName: plugins.TypedName{Type: ByLabelFilterType, Name: name},
50+
typedName: plugins.TypedName{Type: ByLabelType, Name: name},
5151
labelName: labelName,
5252
allowsNoLabel: allowsNoLabel,
5353
validValues: validValuesMap,

pkg/plugins/filter/by_label_selector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
)
1515

1616
const (
17-
// ByLabelSelectorFilterType is the type of the ByLabelsFilter
18-
ByLabelSelectorFilterType = "by-label-selector"
17+
// ByLabelSelectorType is the type of the ByLabelSelector filter
18+
ByLabelSelectorType = "by-label-selector"
1919
)
2020

2121
// compile-time type assertion
@@ -26,7 +26,7 @@ func ByLabelSelectorFactory(name string, rawParameters json.RawMessage, _ plugin
2626
parameters := metav1.LabelSelector{}
2727
if rawParameters != nil {
2828
if err := json.Unmarshal(rawParameters, &parameters); err != nil {
29-
return nil, fmt.Errorf("failed to parse the parameters of the '%s' filter - %w", ByLabelSelectorFilterType, err)
29+
return nil, fmt.Errorf("failed to parse the parameters of the '%s' filter - %w", ByLabelSelectorType, err)
3030
}
3131
}
3232
return NewByLabelSelector(name, &parameters)
@@ -44,7 +44,7 @@ func NewByLabelSelector(name string, selector *metav1.LabelSelector) (*ByLabelSe
4444
}
4545

4646
return &ByLabelSelector{
47-
typedName: plugins.TypedName{Type: ByLabelSelectorFilterType, Name: name},
47+
typedName: plugins.TypedName{Type: ByLabelSelectorType, Name: name},
4848
selector: labelSelector,
4949
}, nil
5050
}

pkg/plugins/filter/pd_role.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package filter
2+
3+
import (
4+
"encoding/json"
5+
6+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
7+
)
8+
9+
const (
10+
// RoleLabel name
11+
RoleLabel = "llm-d.ai/role"
12+
// RolePrefill set for designated prefill workers
13+
RolePrefill = "prefill"
14+
// RoleDecode set for designated decode workers
15+
RoleDecode = "decode"
16+
// RoleBoth set for workers that can act as both prefill and decode
17+
RoleBoth = "both"
18+
19+
// DecodeRoleType is the type of the DecodeFilter
20+
DecodeRoleType = "decode-filter"
21+
// PrefillRoleType is the type of the PrefillFilter
22+
PrefillRoleType = "prefill-filter"
23+
)
24+
25+
// PrefillRoleFactory defines the factory function for the Prefill filter.
26+
func PrefillRoleFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
27+
return NewPrefillRole().WithName(name), nil
28+
}
29+
30+
// NewPrefillRole creates and returns an instance of the Filter configured for prefill role
31+
func NewPrefillRole() *ByLabel {
32+
return NewByLabel(PrefillRoleType, RoleLabel, false, RolePrefill)
33+
}
34+
35+
// DecodeRoleFactory defines the factory function for the Decode filter.
36+
func DecodeRoleFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
37+
return NewDecodeRole().WithName(name), nil
38+
}
39+
40+
// NewDecodeRole creates and returns an instance of the Filter configured for decode role
41+
func NewDecodeRole() *ByLabel {
42+
return NewByLabel(DecodeRoleType, RoleLabel, true, RoleDecode, RoleBoth)
43+
}

pkg/plugins/filter/pd_role_filter.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

pkg/plugins/register.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212

1313
// RegisterAllPlugins registers the factory functions of all plugins in this repository.
1414
func RegisterAllPlugins() {
15-
plugins.Register(filter.ByLabelFilterType, filter.ByLabelFilterFactory)
16-
plugins.Register(filter.ByLabelSelectorFilterType, filter.ByLabelSelectorFactory)
17-
plugins.Register(filter.DecodeFilterType, filter.DecodeFilterFactory)
18-
plugins.Register(filter.PrefillFilterType, filter.PrefillFilterFactory)
15+
plugins.Register(filter.ByLabelType, filter.ByLabelFactory)
16+
plugins.Register(filter.ByLabelSelectorType, filter.ByLabelSelectorFactory)
17+
plugins.Register(filter.DecodeRoleType, filter.DecodeRoleFactory)
18+
plugins.Register(filter.PrefillRoleType, filter.PrefillRoleFactory)
1919
plugins.Register(prerequest.PrefillHeaderHandlerType, prerequest.PrefillHeaderHandlerFactory)
2020
plugins.Register(profile.PdProfileHandlerType, profile.PdProfileHandlerFactory)
2121
plugins.Register(prefix.PrefixCachePluginType, scorer.PrefixCachePluginFactory)
22-
plugins.Register(scorer.LoadAwareScorerType, scorer.LoadAwareScorerFactory)
23-
plugins.Register(scorer.SessionAffinityScorerType, scorer.SessionAffinityScorerFactory)
24-
plugins.Register(scorer.ActiveRequestScorerType, scorer.ActiveRequestScorerFactory)
22+
plugins.Register(scorer.LoadAwareType, scorer.LoadAwareFactory)
23+
plugins.Register(scorer.SessionAffinityType, scorer.SessionAffinityFactory)
24+
plugins.Register(scorer.ActiveRequestType, scorer.ActiveRequestFactory)
2525
}

pkg/plugins/scorer/active_request.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import (
1818
)
1919

2020
const (
21-
// ActiveRequestScorerType is the type of the ActiveRequestScorer
22-
ActiveRequestScorerType = "active-request-scorer"
21+
// ActiveRequestType is the type of the ActiveRequest scorer.
22+
ActiveRequestType = "active-request-scorer"
2323

2424
// defaultRequestTimeout defines the default timeout for open requests to be
2525
// considered stale and removed from the cache.
2626
defaultRequestTimeout = 2 * time.Minute
2727
)
2828

29-
// ActiveRequestScorerParameters defines the parameters for the
30-
// ActiveRequestScorer.
31-
type ActiveRequestScorerParameters struct {
29+
// ActiveRequestParameters defines the parameters for the
30+
// ActiveRequest.
31+
type ActiveRequestParameters struct {
3232
// RequestTimeout defines the timeout for requests in seconds.
3333
// Once the request is "in-flight" for this duration, it is considered to
3434
// be timed out and dropped.
@@ -48,22 +48,22 @@ func (r *requestEntry) String() string {
4848
}
4949

5050
// compile-time type assertion
51-
var _ framework.Scorer = &ActiveRequestScorer{}
51+
var _ framework.Scorer = &ActiveRequest{}
5252

53-
// ActiveRequestScorerFactory defines the factory function for the ActiveRequestScorer.
54-
func ActiveRequestScorerFactory(name string, rawParameters json.RawMessage, handle plugins.Handle) (plugins.Plugin, error) {
55-
parameters := ActiveRequestScorerParameters{}
53+
// ActiveRequestFactory defines the factory function for the ActiveRequest scorer.
54+
func ActiveRequestFactory(name string, rawParameters json.RawMessage, handle plugins.Handle) (plugins.Plugin, error) {
55+
parameters := ActiveRequestParameters{}
5656
if rawParameters != nil {
5757
if err := json.Unmarshal(rawParameters, &parameters); err != nil {
58-
return nil, fmt.Errorf("failed to parse the parameters of the '%s' scorer - %w", ActiveRequestScorerType, err)
58+
return nil, fmt.Errorf("failed to parse the parameters of the '%s' scorer - %w", ActiveRequestType, err)
5959
}
6060
}
6161

62-
return NewActiveRequestScorer(handle.Context(), &parameters).WithName(name), nil
62+
return NewActiveRequest(handle.Context(), &parameters).WithName(name), nil
6363
}
6464

65-
// NewActiveRequestScorer creates a new ActiveRequestScorer scorer.
66-
func NewActiveRequestScorer(ctx context.Context, params *ActiveRequestScorerParameters) *ActiveRequestScorer {
65+
// NewActiveRequest creates a new ActiveRequest scorer.
66+
func NewActiveRequest(ctx context.Context, params *ActiveRequestParameters) *ActiveRequest {
6767
requestTimeout := defaultRequestTimeout
6868
logger := log.FromContext(ctx)
6969

@@ -83,8 +83,8 @@ func NewActiveRequestScorer(ctx context.Context, params *ActiveRequestScorerPara
8383
ttlcache.WithDisableTouchOnHit[string, *requestEntry](),
8484
)
8585

86-
scorer := &ActiveRequestScorer{
87-
typedName: plugins.TypedName{Type: ActiveRequestScorerType},
86+
scorer := &ActiveRequest{
87+
typedName: plugins.TypedName{Type: ActiveRequestType},
8888
requestCache: requestCache,
8989
podCounts: make(map[string]int),
9090
mutex: &sync.RWMutex{},
@@ -104,9 +104,9 @@ func NewActiveRequestScorer(ctx context.Context, params *ActiveRequestScorerPara
104104
return scorer
105105
}
106106

107-
// ActiveRequestScorer keeps track of individual requests being served
107+
// ActiveRequest keeps track of individual requests being served
108108
// per pod.
109-
type ActiveRequestScorer struct {
109+
type ActiveRequest struct {
110110
typedName plugins.TypedName
111111

112112
// requestCache stores individual request entries with unique composite keys (podName.requestID)
@@ -118,19 +118,19 @@ type ActiveRequestScorer struct {
118118
}
119119

120120
// TypedName returns the typed name of the plugin.
121-
func (s *ActiveRequestScorer) TypedName() plugins.TypedName {
121+
func (s *ActiveRequest) TypedName() plugins.TypedName {
122122
return s.typedName
123123
}
124124

125125
// WithName sets the name of the plugin.
126-
func (s *ActiveRequestScorer) WithName(name string) *ActiveRequestScorer {
126+
func (s *ActiveRequest) WithName(name string) *ActiveRequest {
127127
s.typedName.Name = name
128128
return s
129129
}
130130

131131
// Score scores the given pods based on the number of active requests
132132
// being served by each pod. The score is normalized to a range of 0-1.
133-
func (s *ActiveRequestScorer) Score(ctx context.Context, _ *types.CycleState, _ *types.LLMRequest,
133+
func (s *ActiveRequest) Score(ctx context.Context, _ *types.CycleState, _ *types.LLMRequest,
134134
pods []types.Pod) map[types.Pod]float64 {
135135
scoredPods := make(map[string]int)
136136
maxCount := 0
@@ -164,7 +164,7 @@ func (s *ActiveRequestScorer) Score(ctx context.Context, _ *types.CycleState, _
164164
// PreRequest is called before a request is sent to the target pod.
165165
// It creates a new request entry in the cache with its own TTL and
166166
// increments the pod count for fast lookup.
167-
func (s *ActiveRequestScorer) PreRequest(ctx context.Context, request *types.LLMRequest,
167+
func (s *ActiveRequest) PreRequest(ctx context.Context, request *types.LLMRequest,
168168
schedulingResult *types.SchedulingResult, _ int) {
169169
debugLogger := log.FromContext(ctx).V(logutil.DEBUG)
170170

@@ -190,9 +190,9 @@ func (s *ActiveRequestScorer) PreRequest(ctx context.Context, request *types.LLM
190190
// PostResponse is called after a response is sent to the client.
191191
// It removes the specific request entry from the cache and decrements
192192
// the pod count.
193-
func (s *ActiveRequestScorer) PostResponse(ctx context.Context, request *types.LLMRequest,
193+
func (s *ActiveRequest) PostResponse(ctx context.Context, request *types.LLMRequest,
194194
_ *requestcontrol.Response, targetPod *backend.Pod) {
195-
debugLogger := log.FromContext(ctx).V(logutil.DEBUG).WithName("ActiveRequestScorer.PostResponse")
195+
debugLogger := log.FromContext(ctx).V(logutil.DEBUG).WithName("ActiveRequest.PostResponse")
196196
if targetPod == nil {
197197
debugLogger.Info("Skipping PostResponse because targetPod is nil")
198198
return
@@ -209,7 +209,7 @@ func (s *ActiveRequestScorer) PostResponse(ctx context.Context, request *types.L
209209
}
210210

211211
// incrementPodCount increments the request count for a pod.
212-
func (s *ActiveRequestScorer) incrementPodCount(podName string) {
212+
func (s *ActiveRequest) incrementPodCount(podName string) {
213213
s.mutex.Lock()
214214
defer s.mutex.Unlock()
215215

@@ -218,7 +218,7 @@ func (s *ActiveRequestScorer) incrementPodCount(podName string) {
218218

219219
// decrementPodCount decrements the request count for a pod and removes
220220
// the entry if count reaches zero.
221-
func (s *ActiveRequestScorer) decrementPodCount(podName string) {
221+
func (s *ActiveRequest) decrementPodCount(podName string) {
222222
s.mutex.Lock()
223223
defer s.mutex.Unlock()
224224

0 commit comments

Comments
 (0)