Skip to content

Commit a6a78b8

Browse files
committed
Refactor: Relocate SaturationDetector
This commit moves the existing `SaturationDetector` implementation to its new home under the EPP plugin framework structure. This is a preparatory step towards making `SaturationControl` an official EPP extension point. - Renamed `pkg/epp/saturationdetector` to `pkg/epp/saturationcontrol` - Moved files to `.../framework/plugins/staticthresholdcontroller` - Renamed `saturationdetector.go` to `controller.go` - Renamed `saturationdetector_test.go` to `controller_test.go` - Fixed imports No functional changes are included in this commit.
1 parent a1a8cc8 commit a6a78b8

File tree

10 files changed

+45
-45
lines changed

10 files changed

+45
-45
lines changed

cmd/epp/runner/runner.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import (
6767
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
6868
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
6969
testresponsereceived "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol/plugins/test/responsereceived"
70-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
70+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
7171
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
7272
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
7373
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/slo_aware_router"
@@ -326,7 +326,7 @@ func (r *Runner) Run(ctx context.Context) error {
326326

327327
scheduler := scheduling.NewSchedulerWithConfig(r.schedulerConfig)
328328

329-
saturationDetector := saturationdetector.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
329+
saturationDetector := staticthresholdcontroller.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
330330

331331
// --- Admission Control Initialization ---
332332
var admissionController requestcontrol.AdmissionController
@@ -545,23 +545,23 @@ func (r *Runner) deprecatedConfigurationHelper(cfg *config.Config, logger logr.L
545545
if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
546546
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
547547
cfg.SaturationDetectorConfig.QueueDepthThreshold =
548-
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
548+
env.GetEnvInt(EnvSdQueueDepthThreshold, staticthresholdcontroller.DefaultQueueDepthThreshold, logger)
549549
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
550-
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
550+
cfg.SaturationDetectorConfig.QueueDepthThreshold = staticthresholdcontroller.DefaultQueueDepthThreshold
551551
}
552552
}
553553
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
554554
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
555-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
555+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, staticthresholdcontroller.DefaultKVCacheUtilThreshold, logger)
556556
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
557-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
557+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = staticthresholdcontroller.DefaultKVCacheUtilThreshold
558558
}
559559
}
560560
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
561561
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
562-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
562+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, staticthresholdcontroller.DefaultMetricsStalenessThreshold, logger)
563563
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
564-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
564+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = staticthresholdcontroller.DefaultMetricsStalenessThreshold
565565
}
566566
}
567567
}

pkg/epp/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
20+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
2121
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
2222
)
2323

2424
// Config is the configuration loaded from the text based configuration
2525
type Config struct {
2626
SchedulerConfig *scheduling.SchedulerConfig
27-
SaturationDetectorConfig *saturationdetector.Config
27+
SaturationDetectorConfig *staticthresholdcontroller.Config
2828
}

pkg/epp/config/loader/configloader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
3030
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/config"
3131
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
32-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
32+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
3333
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
3434
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
3535
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
@@ -151,20 +151,20 @@ func loadFeatureConfig(featureGates configapi.FeatureGates) map[string]bool {
151151
return featureConfig
152152
}
153153

154-
func loadSaturationDetectorConfig(sd *configapi.SaturationDetector) *saturationdetector.Config {
155-
sdConfig := saturationdetector.Config{}
154+
func loadSaturationDetectorConfig(sd *configapi.SaturationDetector) *staticthresholdcontroller.Config {
155+
sdConfig := staticthresholdcontroller.Config{}
156156

157157
sdConfig.QueueDepthThreshold = sd.QueueDepthThreshold
158158
if sdConfig.QueueDepthThreshold <= 0 {
159-
sdConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
159+
sdConfig.QueueDepthThreshold = staticthresholdcontroller.DefaultQueueDepthThreshold
160160
}
161161
sdConfig.KVCacheUtilThreshold = sd.KVCacheUtilThreshold
162162
if sdConfig.KVCacheUtilThreshold <= 0.0 || sdConfig.KVCacheUtilThreshold >= 1.0 {
163-
sdConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
163+
sdConfig.KVCacheUtilThreshold = staticthresholdcontroller.DefaultKVCacheUtilThreshold
164164
}
165165
sdConfig.MetricsStalenessThreshold = sd.MetricsStalenessThreshold.Duration
166166
if sdConfig.MetricsStalenessThreshold <= 0.0 {
167-
sdConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
167+
sdConfig.MetricsStalenessThreshold = staticthresholdcontroller.DefaultMetricsStalenessThreshold
168168
}
169169

170170
return &sdConfig

pkg/epp/config/loader/configloader_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/config"
3232
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
3333
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
34-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
34+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
3535
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
3636
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
3737
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
@@ -208,8 +208,8 @@ func TestLoadRawConfigurationWithDefaults(t *testing.T) {
208208
},
209209
FeatureGates: configapi.FeatureGates{datalayer.FeatureGate},
210210
SaturationDetector: &configapi.SaturationDetector{
211-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
212-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
211+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
212+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
213213
MetricsStalenessThreshold: metav1.Duration{Duration: 150 * time.Millisecond},
214214
},
215215
}
@@ -249,9 +249,9 @@ func TestLoadRawConfigurationWithDefaults(t *testing.T) {
249249
},
250250
FeatureGates: configapi.FeatureGates{},
251251
SaturationDetector: &configapi.SaturationDetector{
252-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
253-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
254-
MetricsStalenessThreshold: metav1.Duration{Duration: saturationdetector.DefaultMetricsStalenessThreshold},
252+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
253+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
254+
MetricsStalenessThreshold: metav1.Duration{Duration: staticthresholdcontroller.DefaultMetricsStalenessThreshold},
255255
},
256256
}
257257

@@ -508,7 +508,7 @@ func TestNewDetector(t *testing.T) {
508508
tests := []struct {
509509
name string
510510
config *configapi.SaturationDetector
511-
expectedConfig saturationdetector.Config
511+
expectedConfig staticthresholdcontroller.Config
512512
}{
513513
{
514514
name: "Valid config",
@@ -517,7 +517,7 @@ func TestNewDetector(t *testing.T) {
517517
KVCacheUtilThreshold: 0.8,
518518
MetricsStalenessThreshold: metav1.Duration{Duration: 100 * time.Millisecond},
519519
},
520-
expectedConfig: saturationdetector.Config{
520+
expectedConfig: staticthresholdcontroller.Config{
521521
QueueDepthThreshold: 10,
522522
KVCacheUtilThreshold: 0.8,
523523
MetricsStalenessThreshold: 100 * time.Millisecond,
@@ -530,10 +530,10 @@ func TestNewDetector(t *testing.T) {
530530
KVCacheUtilThreshold: -5.0,
531531
MetricsStalenessThreshold: metav1.Duration{Duration: 0 * time.Second},
532532
},
533-
expectedConfig: saturationdetector.Config{
534-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
535-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
536-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
533+
expectedConfig: staticthresholdcontroller.Config{
534+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
535+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
536+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
537537
},
538538
},
539539
{
@@ -543,9 +543,9 @@ func TestNewDetector(t *testing.T) {
543543
KVCacheUtilThreshold: 1.5,
544544
MetricsStalenessThreshold: metav1.Duration{Duration: 100 * time.Millisecond},
545545
},
546-
expectedConfig: saturationdetector.Config{
546+
expectedConfig: staticthresholdcontroller.Config{
547547
QueueDepthThreshold: 10,
548-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
548+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
549549
MetricsStalenessThreshold: 100 * time.Millisecond,
550550
},
551551
},

pkg/epp/config/loader/defaults.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
2222
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
23-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
23+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
2424
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
2525
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
2626
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
@@ -63,14 +63,14 @@ func setDefaultsPhaseOne(cfg *configapi.EndpointPickerConfig) {
6363
cfg.SaturationDetector = &configapi.SaturationDetector{}
6464
}
6565
if cfg.SaturationDetector.QueueDepthThreshold == 0 {
66-
cfg.SaturationDetector.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
66+
cfg.SaturationDetector.QueueDepthThreshold = staticthresholdcontroller.DefaultQueueDepthThreshold
6767
}
6868
if cfg.SaturationDetector.KVCacheUtilThreshold == 0.0 {
69-
cfg.SaturationDetector.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
69+
cfg.SaturationDetector.KVCacheUtilThreshold = staticthresholdcontroller.DefaultKVCacheUtilThreshold
7070
}
7171
if cfg.SaturationDetector.MetricsStalenessThreshold.Duration == 0.0 {
7272
cfg.SaturationDetector.MetricsStalenessThreshold =
73-
metav1.Duration{Duration: saturationdetector.DefaultMetricsStalenessThreshold}
73+
metav1.Duration{Duration: staticthresholdcontroller.DefaultMetricsStalenessThreshold}
7474
}
7575
}
7676

pkg/epp/saturationdetector/config.go renamed to pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package saturationdetector
16+
package staticthresholdcontroller
1717

1818
import (
1919
"time"

pkg/epp/saturationdetector/saturationdetector.go renamed to pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ limitations under the License.
2727
// - Predictive saturation based on trends.
2828
// - Hysteresis bands or other smoothing techniques to prevent rapid
2929
// oscillations of the saturation signal.
30-
package saturationdetector
30+
package staticthresholdcontroller
3131

3232
import (
3333
"context"

pkg/epp/saturationdetector/saturationdetector_test.go renamed to pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package saturationdetector
17+
package staticthresholdcontroller
1818

1919
import (
2020
"context"

pkg/epp/server/runserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
4343
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/handlers"
4444
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
45-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
45+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
4646
)
4747

4848
// ExtProcServerRunner provides methods to manage an external process server.
@@ -58,7 +58,7 @@ type ExtProcServerRunner struct {
5858
RefreshPrometheusMetricsInterval time.Duration
5959
MetricsStalenessThreshold time.Duration
6060
Director *requestcontrol.Director
61-
SaturationDetector *saturationdetector.Detector
61+
SaturationDetector *staticthresholdcontroller.Detector
6262
UseExperimentalDatalayerV2 bool // Pluggable data layer feature flag
6363

6464
// This should only be used in tests. We won't need this once we do not inject metrics in the tests.

test/integration/epp/hermetic_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import (
6666
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metadata"
6767
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics"
6868
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
69-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
69+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
7070
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
7171
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
7272
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
@@ -1233,12 +1233,12 @@ func BeforeSuite() func() {
12331233
schedulerConfig := scheduling.NewSchedulerConfig(profileHandler, map[string]*framework.SchedulerProfile{"default": defaultProfile})
12341234
scheduler := scheduling.NewSchedulerWithConfig(schedulerConfig)
12351235

1236-
sdConfig := &saturationdetector.Config{
1237-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
1238-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
1239-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
1236+
sdConfig := &staticthresholdcontroller.Config{
1237+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
1238+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
1239+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
12401240
}
1241-
detector := saturationdetector.NewDetector(sdConfig, logger.WithName("saturation-detector"))
1241+
detector := staticthresholdcontroller.NewDetector(sdConfig, logger.WithName("saturation-detector"))
12421242
serverRunner.SaturationDetector = detector
12431243
admissionController := requestcontrol.NewLegacyAdmissionController(detector)
12441244
locator := requestcontrol.NewDatastorePodLocator(serverRunner.Datastore)

0 commit comments

Comments
 (0)