Skip to content

Cleanup - organize scheduler plugin by their functionality instead of type #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cmd/epp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics/collectors"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/filter"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/capacity"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/kvcache"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/prefix"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/scorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/queue"
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
envutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/env"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
Expand Down Expand Up @@ -194,11 +195,11 @@ func run() error {

scheduler := scheduling.NewScheduler(datastore)
if schedulerV2 == "true" {
queueScorerWeight := envutil.GetEnvInt("QUEUE_SCORE_WEIGHT", scorer.DefaultQueueScorerWeight, setupLog)
kvCacheScorerWeight := envutil.GetEnvInt("KV_CACHE_SCORE_WEIGHT", scorer.DefaultKVCacheScorerWeight, setupLog)
queueScorerWeight := envutil.GetEnvInt("QUEUE_SCORE_WEIGHT", queue.DefaultQueueScorerWeight, setupLog)
kvCacheScorerWeight := envutil.GetEnvInt("KV_CACHE_SCORE_WEIGHT", kvcache.DefaultKVCacheScorerWeight, setupLog)
scorers := map[plugins.Scorer]int{
&scorer.QueueScorer{}: queueScorerWeight,
&scorer.KVCacheScorer{}: kvCacheScorerWeight,
&queue.QueueScorer{}: queueScorerWeight,
&kvcache.KVCacheScorer{}: kvCacheScorerWeight,
}
schedConfigOpts := []scheduling.ConfigOption{}
if prefixCacheScheduling == "true" {
Expand All @@ -207,7 +208,7 @@ func run() error {
}
schedulerConfig := scheduling.NewSchedulerConfig(
[]plugins.PreSchedule{},
[]plugins.Filter{filter.NewSheddableCapacityFilter()},
[]plugins.Filter{capacity.NewSheddableCapacityFilter()},
scorers,
picker.NewMaxScorePicker(),
[]plugins.PostSchedule{},
Expand Down
85 changes: 85 additions & 0 deletions pkg/epp/scheduling/plugins/capacity/filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package capacity

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
)

func TestFilter(t *testing.T) {
tests := []struct {
name string
req *types.LLMRequest
filter plugins.Filter
input []types.Pod
output []types.Pod
}{
{
name: "SheddableCapacityFilter, sheddable request",
req: &types.LLMRequest{Critical: false},
filter: &SheddableCapacityFilter{queueThreshold: 0, kvCacheThreshold: 0.8},
input: []types.Pod{
&types.PodMetrics{
// This pod should be returned.
MetricsState: &backendmetrics.MetricsState{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0,
},
},
&types.PodMetrics{
// Queue is non zero, despite low kv cache, should not return.
MetricsState: &backendmetrics.MetricsState{
WaitingQueueSize: 1,
KVCacheUsagePercent: 0.3,
},
},
&types.PodMetrics{
// High kv cache despite zero queue, should not return
MetricsState: &backendmetrics.MetricsState{
WaitingQueueSize: 0,
KVCacheUsagePercent: 1.0,
},
},
},
output: []types.Pod{
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
WaitingQueueSize: 0,
KVCacheUsagePercent: 0,
},
},
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := types.NewSchedulingContext(context.Background(), test.req, nil, test.input)
got := test.filter.Filter(ctx, test.input)

if diff := cmp.Diff(test.output, got); diff != "" {
t.Errorf("Unexpected output (-want +got): %v", diff)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package filter
package capacity

import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/config"
Expand Down
89 changes: 89 additions & 0 deletions pkg/epp/scheduling/plugins/kvcache/filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kvcache

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
)

func TestFilter(t *testing.T) {
tests := []struct {
name string
req *types.LLMRequest
filter plugins.Filter
input []types.Pod
output []types.Pod
}{

{
name: "least kv cache empty input",
filter: NewLeastKVCacheFilter(),
input: []types.Pod{},
output: []types.Pod{},
},
{
name: "least kv cache",
filter: NewLeastKVCacheFilter(),
input: []types.Pod{
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
KVCacheUsagePercent: 0,
},
},
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
KVCacheUsagePercent: 0.3,
},
},
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
KVCacheUsagePercent: 1.0,
},
},
},
output: []types.Pod{
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
KVCacheUsagePercent: 0,
},
},
&types.PodMetrics{
MetricsState: &backendmetrics.MetricsState{
KVCacheUsagePercent: 0.3,
},
},
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := types.NewSchedulingContext(context.Background(), test.req, nil, test.input)
got := test.filter.Filter(ctx, test.input)

if diff := cmp.Diff(test.output, got); diff != "" {
t.Errorf("Unexpected output (-want +got): %v", diff)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scorer
package kvcache

import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scorer
package kvcache

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package filter
package kvcache

import (
"math"
Expand Down
Loading