Skip to content
Open
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
35 changes: 20 additions & 15 deletions cmd/epp/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ import (
testresponsereceived "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol/plugins/test/responsereceived"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/slo_aware_router"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/scorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/kvcacheutilizationscorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/loraaffinityscorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/maxscorepicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/predictedlatencyprofilehandler"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/predictedlatencyscorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/prefixcachescorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/queuescorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/randompicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/singleprofilehandler"
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/weightedrandompicker"
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
"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 @@ -423,17 +428,17 @@ func setupDatastore(setupLog logr.Logger, ctx context.Context, epFactory datalay

// registerInTreePlugins registers the factory functions of all known plugins
func (r *Runner) registerInTreePlugins() {
plugins.Register(prefix.PrefixCachePluginType, prefix.PrefixCachePluginFactory)
plugins.Register(picker.MaxScorePickerType, picker.MaxScorePickerFactory)
plugins.Register(picker.RandomPickerType, picker.RandomPickerFactory)
plugins.Register(picker.WeightedRandomPickerType, picker.WeightedRandomPickerFactory)
plugins.Register(profile.SingleProfileHandlerType, profile.SingleProfileHandlerFactory)
plugins.Register(scorer.KvCacheUtilizationScorerType, scorer.KvCacheUtilizationScorerFactory)
plugins.Register(scorer.QueueScorerType, scorer.QueueScorerFactory)
plugins.Register(scorer.LoraAffinityScorerType, scorer.LoraAffinityScorerFactory)
plugins.Register(prefixcachescorer.PrefixCachePluginType, prefixcachescorer.PrefixCachePluginFactory)
plugins.Register(maxscorepicker.MaxScorePickerType, maxscorepicker.MaxScorePickerFactory)
plugins.Register(randompicker.RandomPickerType, randompicker.RandomPickerFactory)
plugins.Register(weightedrandompicker.WeightedRandomPickerType, weightedrandompicker.WeightedRandomPickerFactory)
plugins.Register(singleprofilehandler.SingleProfileHandlerType, singleprofilehandler.SingleProfileHandlerFactory)
plugins.Register(kvcacheutilizationscorer.KvCacheUtilizationScorerType, kvcacheutilizationscorer.KvCacheUtilizationScorerFactory)
plugins.Register(queuescorer.QueueScorerType, queuescorer.QueueScorerFactory)
plugins.Register(loraaffinityscorer.LoraAffinityScorerType, loraaffinityscorer.LoraAffinityScorerFactory)
// Latency predictor plugins
plugins.Register(slo_aware_router.SLOAwareRouterPluginType, slo_aware_router.SLOAwareRouterFactory)
plugins.Register(profile.SLOAwareProfileHandlerType, profile.SLOAwareProfileHandlerFactory)
plugins.Register(predictedlatencyscorer.SLOAwareRouterPluginType, predictedlatencyscorer.SLOAwareRouterFactory)
plugins.Register(predictedlatencyprofilehandler.SLOAwareProfileHandlerType, predictedlatencyprofilehandler.SLOAwareProfileHandlerFactory)
// register filter for test purpose only (used in conformance tests)
plugins.Register(testfilter.HeaderBasedTestingFilterType, testfilter.HeaderBasedTestingFilterFactory)
// register response received plugin for test purpose only (used in conformance tests)
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def file_extension(filename):
'_output',
'pkg/epp/backend/metrics/pod_metrics_test.go',
'pkg/epp/saturationdetector/config.go',
'pkg/epp/scheduling/framework/plugins/multi/prefix/indexer_test.go',
'pkg/epp/scheduling/framework/plugins/prefixcachescorer/indexer_test.go',
'pkg/epp/util/env/env_test.go',
'staging/src/k8s.io/kubectl/pkg/generated/bindata.go',
'test/e2e/generated/bindata.go',
Expand Down
4 changes: 2 additions & 2 deletions pkg/epp/config/loader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/singleprofilehandler"
)

var scheme = runtime.NewScheme()
Expand Down Expand Up @@ -130,7 +130,7 @@ func loadSchedulerConfig(configProfiles []configapi.SchedulingProfile, handle pl
return nil, errors.New("no profile handler was specified")
}

if profileHandler.TypedName().Type == profile.SingleProfileHandlerType && len(profiles) > 1 {
if profileHandler.TypedName().Type == singleprofilehandler.SingleProfileHandlerType && len(profiles) > 1 {
return nil, errors.New("single profile handler is intended to be used with a single profile, but multiple profiles were specified")
}

Expand Down
26 changes: 14 additions & 12 deletions pkg/epp/config/loader/configloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/maxscorepicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/prefixcachescorer"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/randompicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/singleprofilehandler"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/weightedrandompicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
"sigs.k8s.io/gateway-api-inference-extension/test/utils"
Expand Down Expand Up @@ -226,12 +228,12 @@ func TestLoadRawConfigurationWithDefaults(t *testing.T) {
Parameters: json.RawMessage("{\"threshold\":10}"),
},
{
Name: profile.SingleProfileHandlerType,
Type: profile.SingleProfileHandlerType,
Name: singleprofilehandler.SingleProfileHandlerType,
Type: singleprofilehandler.SingleProfileHandlerType,
},
{
Name: picker.MaxScorePickerType,
Type: picker.MaxScorePickerType,
Name: maxscorepicker.MaxScorePickerType,
Type: maxscorepicker.MaxScorePickerType,
},
},
SchedulingProfiles: []configapi.SchedulingProfile{
Expand Down Expand Up @@ -492,11 +494,11 @@ func registerNeededFeatureGates() {
}

func registerNeededPlgugins() {
plugins.Register(prefix.PrefixCachePluginType, prefix.PrefixCachePluginFactory)
plugins.Register(picker.MaxScorePickerType, picker.MaxScorePickerFactory)
plugins.Register(picker.RandomPickerType, picker.RandomPickerFactory)
plugins.Register(picker.WeightedRandomPickerType, picker.WeightedRandomPickerFactory)
plugins.Register(profile.SingleProfileHandlerType, profile.SingleProfileHandlerFactory)
plugins.Register(prefixcachescorer.PrefixCachePluginType, prefixcachescorer.PrefixCachePluginFactory)
plugins.Register(maxscorepicker.MaxScorePickerType, maxscorepicker.MaxScorePickerFactory)
plugins.Register(randompicker.RandomPickerType, randompicker.RandomPickerFactory)
plugins.Register(weightedrandompicker.WeightedRandomPickerType, weightedrandompicker.WeightedRandomPickerFactory)
plugins.Register(singleprofilehandler.SingleProfileHandlerType, singleprofilehandler.SingleProfileHandlerFactory)
}

func TestNewDetector(t *testing.T) {
Expand Down
15 changes: 8 additions & 7 deletions pkg/epp/config/loader/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/maxscorepicker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/pickershared"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/singleprofilehandler"
)

const (
Expand Down Expand Up @@ -115,10 +116,10 @@ func setDefaultsPhaseTwo(cfg *configapi.EndpointPickerConfig, handle plugins.Han
}
}
if !profileHandlerFound {
handle.AddPlugin(profile.SingleProfileHandlerType, profile.NewSingleProfileHandler())
handle.AddPlugin(singleprofilehandler.SingleProfileHandlerType, singleprofilehandler.NewSingleProfileHandler())
cfg.Plugins = append(cfg.Plugins,
configapi.PluginSpec{Name: profile.SingleProfileHandlerType,
Type: profile.SingleProfileHandlerType,
configapi.PluginSpec{Name: singleprofilehandler.SingleProfileHandlerType,
Type: singleprofilehandler.SingleProfileHandlerType,
})
}
}
Expand All @@ -131,8 +132,8 @@ func setDefaultsPhaseTwo(cfg *configapi.EndpointPickerConfig, handle plugins.Han
}
}
if maxScorePicker == "" {
handle.AddPlugin(picker.MaxScorePickerType, picker.NewMaxScorePicker(picker.DefaultMaxNumOfEndpoints))
maxScorePicker = picker.MaxScorePickerType
handle.AddPlugin(maxscorepicker.MaxScorePickerType, maxscorepicker.NewMaxScorePicker(pickershared.DefaultMaxNumOfEndpoints))
maxScorePicker = maxscorepicker.MaxScorePickerType
cfg.Plugins = append(cfg.Plugins, configapi.PluginSpec{Name: maxScorePicker, Type: maxScorePicker})
}

Expand Down
17 changes: 7 additions & 10 deletions pkg/epp/scheduling/framework/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

This package contains the scheduling plugin implementations.

Plugins are organized by the following rule. Follow this rule when adding a new
plugin.
Plugins are grouped by plugin name to make it easy to find a specific feature.
Each plugin lives in its own directory (for example `prefixcachescorer/`,
`predictedlatencyscorer/`, `maxscorepicker/`). Shared helpers that are used by
multiple plugins live in supporting packages such as `pickershared/`, and test
helpers stay under `test/`.

```
plugins/
|__ filter/(Plugins that implement the Filter interface only.)
|__ scorer/ (Plugins that implement the Scorer interface only.)
|__ picker/(Plugins that implement the Picker interface only.)
|__ multi/ (Plugins that implement multiple plugin interfaces.)
|____prefix/ (Prefix cache aware scheduling plugin.)
```
When adding a new plugin, create a new directory named after the plugin and keep
all of its code and tests inside that directory.
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 kvcacheutilizationscorer

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 scorer
package kvcacheutilizationscorer

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 scorer
package loraaffinityscorer

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 scorer
package loraaffinityscorer

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 picker
package maxscorepicker

import (
"context"
Expand All @@ -26,6 +26,7 @@ import (

"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/pickershared"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
)
Expand All @@ -39,7 +40,7 @@ var _ framework.Picker = &MaxScorePicker{}

// MaxScorePickerFactory defines the factory function for MaxScorePicker.
func MaxScorePickerFactory(name string, rawParameters json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) {
parameters := pickerParameters{MaxNumOfEndpoints: DefaultMaxNumOfEndpoints}
parameters := pickershared.Parameters{MaxNumOfEndpoints: pickershared.DefaultMaxNumOfEndpoints}
if rawParameters != nil {
if err := json.Unmarshal(rawParameters, &parameters); err != nil {
return nil, fmt.Errorf("failed to parse the parameters of the '%s' picker - %w", MaxScorePickerType, err)
Expand All @@ -51,9 +52,7 @@ func MaxScorePickerFactory(name string, rawParameters json.RawMessage, _ plugins

// NewMaxScorePicker initializes a new MaxScorePicker and returns its pointer.
func NewMaxScorePicker(maxNumOfEndpoints int) *MaxScorePicker {
if maxNumOfEndpoints <= 0 {
maxNumOfEndpoints = DefaultMaxNumOfEndpoints // on invalid configuration value, fallback to default value
}
maxNumOfEndpoints = pickershared.NormalizeMaxNumOfEndpoints(maxNumOfEndpoints)

return &MaxScorePicker{
typedName: plugins.TypedName{Type: MaxScorePickerType, Name: MaxScorePickerType},
Expand Down Expand Up @@ -84,7 +83,7 @@ func (p *MaxScorePicker) Pick(ctx context.Context, cycleState *types.CycleState,
"num-of-candidates", len(scoredPods), "scored-pods", scoredPods)

// Shuffle in-place - needed for random tie break when scores are equal
shuffleScoredPods(scoredPods)
pickershared.ShuffleScoredPods(scoredPods)

slices.SortStableFunc(scoredPods, func(i, j *types.ScoredPod) int { // highest score first
if i.Score > j.Score {
Expand Down
Loading