Skip to content

Commit c0da950

Browse files
committed
chore: drop plugin type from types and file
1 parent 7cf35be commit c0da950

File tree

10 files changed

+86
-84
lines changed

10 files changed

+86
-84
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 ByLabelFilter
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 ByLabelsFilter
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+
// DecodeType is the type of the DecodeFilter
20+
DecodeType = "decode-filter"
21+
// PrefillType is the type of the PrefillFilter
22+
PrefillType = "prefill-filter"
23+
)
24+
25+
// PrefillFactory defines the factory function for the PrefillFilter
26+
func PrefillFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
27+
return NewPrefill().WithName(name), nil
28+
}
29+
30+
// NewPrefill creates and returns an instance of the Filter configured for prefill role
31+
func NewPrefill() *ByLabel {
32+
return NewByLabel(PrefillType, RoleLabel, false, RolePrefill)
33+
}
34+
35+
// DecodeFactory defines the factory function for the DecodeFilter
36+
func DecodeFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
37+
return NewDecode().WithName(name), nil
38+
}
39+
40+
// NewDecode creates and returns an instance of the Filter configured for decode role
41+
func NewDecode() *ByLabel {
42+
return NewByLabel(DecodeType, 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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ 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.DecodeType, filter.DecodeFactory)
18+
plugins.Register(filter.PrefillType, filter.PrefillFactory)
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)
22+
plugins.Register(scorer.LoadAwareType, scorer.LoadAwareFactory)
23+
plugins.Register(scorer.SessionAffinityType, scorer.SessionAffinityFactory)
2424
}

pkg/plugins/scorer/load_aware_scorer.go renamed to pkg/plugins/scorer/load_aware.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,58 @@ import (
1313
)
1414

1515
const (
16-
// LoadAwareScorerType is the type of the LoadAwareScorer
17-
LoadAwareScorerType = "load-aware-scorer"
16+
// LoadAwareType is the type of the LoadAware
17+
LoadAwareType = "load-aware-scorer"
1818

1919
// QueueThresholdDefault defines the default queue threshold value
2020
QueueThresholdDefault = 128
2121
)
2222

23-
type loadAwareScorerParameters struct {
23+
type loadAwareParameters struct {
2424
Threshold int `json:"threshold"`
2525
}
2626

2727
// compile-time type assertion
28-
var _ framework.Scorer = &LoadAwareScorer{}
28+
var _ framework.Scorer = &LoadAware{}
2929

30-
// LoadAwareScorerFactory defines the factory function for the LoadAwareScorer
31-
func LoadAwareScorerFactory(name string, rawParameters json.RawMessage, handle plugins.Handle) (plugins.Plugin, error) {
32-
parameters := loadAwareScorerParameters{Threshold: QueueThresholdDefault}
30+
// LoadAwareFactory defines the factory function for the LoadAware
31+
func LoadAwareFactory(name string, rawParameters json.RawMessage, handle plugins.Handle) (plugins.Plugin, error) {
32+
parameters := loadAwareParameters{Threshold: QueueThresholdDefault}
3333
if rawParameters != nil {
3434
if err := json.Unmarshal(rawParameters, &parameters); err != nil {
35-
return nil, fmt.Errorf("failed to parse the parameters of the '%s' scorer - %w", LoadAwareScorerType, err)
35+
return nil, fmt.Errorf("failed to parse the parameters of the '%s' scorer - %w", LoadAwareType, err)
3636
}
3737
}
3838

3939
return NewLoadAwareScorer(handle.Context(), parameters.Threshold).WithName(name), nil
4040
}
4141

4242
// NewLoadAwareScorer creates a new load based scorer
43-
func NewLoadAwareScorer(ctx context.Context, queueThreshold int) *LoadAwareScorer {
43+
func NewLoadAwareScorer(ctx context.Context, queueThreshold int) *LoadAware {
4444
if queueThreshold <= 0 {
4545
queueThreshold = QueueThresholdDefault
4646
log.FromContext(ctx).V(logutil.DEFAULT).Info(fmt.Sprintf("queueThreshold %d should be positive, using default queue threshold %d", queueThreshold, QueueThresholdDefault))
4747
}
4848

49-
return &LoadAwareScorer{
50-
typedName: plugins.TypedName{Type: LoadAwareScorerType},
49+
return &LoadAware{
50+
typedName: plugins.TypedName{Type: LoadAwareType},
5151
queueThreshold: float64(queueThreshold),
5252
}
5353
}
5454

55-
// LoadAwareScorer scorer that is based on load
56-
type LoadAwareScorer struct {
55+
// LoadAware scorer that is based on load
56+
type LoadAware struct {
5757
typedName plugins.TypedName
5858
queueThreshold float64
5959
}
6060

6161
// TypedName returns the typed name of the plugin.
62-
func (s *LoadAwareScorer) TypedName() plugins.TypedName {
62+
func (s *LoadAware) TypedName() plugins.TypedName {
6363
return s.typedName
6464
}
6565

6666
// WithName sets the name of the plugin.
67-
func (s *LoadAwareScorer) WithName(name string) *LoadAwareScorer {
67+
func (s *LoadAware) WithName(name string) *LoadAware {
6868
s.typedName.Name = name
6969
return s
7070
}
@@ -76,7 +76,7 @@ func (s *LoadAwareScorer) WithName(name string) *LoadAwareScorer {
7676
// Pod with requests in the queue will get score between 0.5 and 0.
7777
// Score 0 will get pod with number of requests in the queue equal to the threshold used in load-based filter
7878
// In the future, pods with additional capacity will get score higher than 0.5
79-
func (s *LoadAwareScorer) Score(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, pods []types.Pod) map[types.Pod]float64 {
79+
func (s *LoadAware) Score(_ context.Context, _ *types.CycleState, _ *types.LLMRequest, pods []types.Pod) map[types.Pod]float64 {
8080
scoredPods := make(map[types.Pod]float64)
8181

8282
for _, pod := range pods {

pkg/plugins/scorer/session_affinity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
)
1616

1717
const (
18-
// SessionAffinityScorerType is the type of the SessionAffinityScorer
19-
SessionAffinityScorerType = "session-affinity-scorer"
18+
// SessionAffinityType is the type of the SessionAffinityScorer
19+
SessionAffinityType = "session-affinity-scorer"
2020

2121
sessionTokenHeader = "x-session-token" // name of the session header in request
2222
)
@@ -25,15 +25,15 @@ const (
2525
var _ framework.Scorer = &SessionAffinity{}
2626
var _ requestcontrol.PostResponse = &SessionAffinity{}
2727

28-
// SessionAffinityScorerFactory defines the factory function for SessionAffinityScorer.
29-
func SessionAffinityScorerFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
28+
// SessionAffinityFactory defines the factory function for SessionAffinityScorer.
29+
func SessionAffinityFactory(name string, _ json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
3030
return NewSessionAffinity().WithName(name), nil
3131
}
3232

3333
// NewSessionAffinity returns a scorer
3434
func NewSessionAffinity() *SessionAffinity {
3535
return &SessionAffinity{
36-
typedName: plugins.TypedName{Type: SessionAffinityScorerType},
36+
typedName: plugins.TypedName{Type: SessionAffinityType},
3737
}
3838
}
3939

pkg/scheduling/pd/scheduler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ func TestPDSchedule(t *testing.T) {
198198
prefixScorer := prefix.New(prefix.Config{HashBlockSize: 5, MaxPrefixBlocksToMatch: 256, LRUCapacityPerServer: 31250})
199199

200200
prefillSchedulerProfile := framework.NewSchedulerProfile().
201-
WithFilters(filter.NewPrefillFilter()).
201+
WithFilters(filter.NewPrefill()).
202202
WithPicker(picker.NewMaxScorePicker(picker.DefaultMaxNumOfEndpoints))
203203
err := prefillSchedulerProfile.AddPlugins(framework.NewWeightedScorer(prefixScorer, 50))
204204
assert.NoError(t, err, "SchedulerProfile AddPlugins returned unexpected error")
205205

206206
decodeSchedulerProfile := framework.NewSchedulerProfile().
207-
WithFilters(filter.NewDecodeFilter()).
207+
WithFilters(filter.NewDecode()).
208208
WithScorers(framework.NewWeightedScorer(scorer.NewLoadAwareScorer(ctx, scorer.QueueThresholdDefault), 1)).
209209
WithPicker(picker.NewMaxScorePicker(picker.DefaultMaxNumOfEndpoints))
210210
err = decodeSchedulerProfile.AddPlugins(framework.NewWeightedScorer(prefixScorer, 0))

0 commit comments

Comments
 (0)