@@ -5,9 +5,11 @@ import (
55 "encoding/json"
66 "fmt"
77
8+ "sigs.k8s.io/controller-runtime/pkg/log"
89 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
910 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
1011 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types"
12+ logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
1113)
1214
1315const (
@@ -26,19 +28,24 @@ type loadAwareScorerParameters struct {
2628var _ framework.Scorer = & LoadAwareScorer {}
2729
2830// LoadAwareScorerFactory defines the factory function for the LoadAwareScorer
29- func LoadAwareScorerFactory (name string , rawParameters json.RawMessage , _ plugins.Handle ) (plugins.Plugin , error ) {
31+ func LoadAwareScorerFactory (name string , rawParameters json.RawMessage , handle plugins.Handle ) (plugins.Plugin , error ) {
3032 parameters := loadAwareScorerParameters {Threshold : QueueThresholdDefault }
3133 if rawParameters != nil {
3234 if err := json .Unmarshal (rawParameters , & parameters ); err != nil {
3335 return nil , fmt .Errorf ("failed to parse the parameters of the '%s' scorer - %w" , LoadAwareScorerType , err )
3436 }
3537 }
3638
37- return NewLoadAwareScorer (parameters .Threshold ).WithName (name ), nil
39+ return NewLoadAwareScorer (handle . Context (), parameters .Threshold ).WithName (name ), nil
3840}
3941
4042// NewLoadAwareScorer creates a new load based scorer
41- func NewLoadAwareScorer (queueThreshold int ) * LoadAwareScorer {
43+ func NewLoadAwareScorer (ctx context.Context , queueThreshold int ) * LoadAwareScorer {
44+ if queueThreshold <= 0 {
45+ queueThreshold = QueueThresholdDefault
46+ log .FromContext (ctx ).V (logutil .DEFAULT ).Info (fmt .Sprintf ("queueThreshold %d should be positive, using default queue threshold %d" , queueThreshold , QueueThresholdDefault ))
47+ }
48+
4249 return & LoadAwareScorer {
4350 typedName : plugins.TypedName {Type : LoadAwareScorerType },
4451 queueThreshold : float64 (queueThreshold ),
0 commit comments