Skip to content

Commit 2e3fb2f

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 ea75633 commit 2e3fb2f

File tree

9 files changed

+40
-39
lines changed

9 files changed

+40
-39
lines changed

cmd/epp/runner/runner.go

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

290290
scheduler := scheduling.NewSchedulerWithConfig(r.schedulerConfig)
291291

292-
saturationDetector := saturationdetector.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
292+
saturationDetector := staticthresholdcontroller.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
293293

294294
// --- Admission Control Initialization ---
295295
var admissionController requestcontrol.AdmissionController
@@ -512,23 +512,23 @@ func (r *Runner) deprecatedConfigurationHelper(cfg *config.Config, logger logr.L
512512
if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
513513
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
514514
cfg.SaturationDetectorConfig.QueueDepthThreshold =
515-
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
515+
env.GetEnvInt(EnvSdQueueDepthThreshold, staticthresholdcontroller.DefaultQueueDepthThreshold, logger)
516516
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
517-
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
517+
cfg.SaturationDetectorConfig.QueueDepthThreshold = staticthresholdcontroller.DefaultQueueDepthThreshold
518518
}
519519
}
520520
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
521521
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
522-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
522+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, staticthresholdcontroller.DefaultKVCacheUtilThreshold, logger)
523523
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
524-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
524+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = staticthresholdcontroller.DefaultKVCacheUtilThreshold
525525
}
526526
}
527527
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
528528
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
529-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
529+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, staticthresholdcontroller.DefaultMetricsStalenessThreshold, logger)
530530
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
531-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
531+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = staticthresholdcontroller.DefaultMetricsStalenessThreshold
532532
}
533533
}
534534
}

pkg/epp/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ package config
1818

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

2525
// Config is the configuration loaded from the text based configuration
2626
type Config struct {
2727
SchedulerConfig *scheduling.SchedulerConfig
28-
SaturationDetectorConfig *saturationdetector.Config
28+
SaturationDetectorConfig *staticthresholdcontroller.Config
2929
DataConfig *datalayer.Config
3030
}

pkg/epp/config/loader/configloader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/config"
3131
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
3232
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
33-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
33+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
3434
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
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/profile"
@@ -211,11 +211,11 @@ func loadFeatureConfig(gates configapi.FeatureGates) map[string]bool {
211211
return config
212212
}
213213

214-
func buildSaturationConfig(apiConfig *configapi.SaturationDetector) *saturationdetector.Config {
215-
cfg := &saturationdetector.Config{
216-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
217-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
218-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
214+
func buildSaturationConfig(apiConfig *configapi.SaturationDetector) *staticthresholdcontroller.Config {
215+
cfg := &staticthresholdcontroller.Config{
216+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
217+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
218+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
219219
}
220220

221221
if apiConfig != nil {

pkg/epp/config/loader/configloader_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
3333
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
3434
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
35-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
35+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
3636
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
3737
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
3838
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
@@ -339,7 +339,7 @@ func TestBuildSaturationConfig(t *testing.T) {
339339
tests := []struct {
340340
name string
341341
input *configapi.SaturationDetector
342-
expected *saturationdetector.Config
342+
expected *staticthresholdcontroller.Config
343343
}{
344344
{
345345
name: "Valid Configuration",
@@ -348,7 +348,7 @@ func TestBuildSaturationConfig(t *testing.T) {
348348
KVCacheUtilThreshold: 0.9,
349349
MetricsStalenessThreshold: metav1.Duration{Duration: 500 * time.Millisecond},
350350
},
351-
expected: &saturationdetector.Config{
351+
expected: &staticthresholdcontroller.Config{
352352
QueueDepthThreshold: 20,
353353
KVCacheUtilThreshold: 0.9,
354354
MetricsStalenessThreshold: 500 * time.Millisecond,
@@ -357,10 +357,10 @@ func TestBuildSaturationConfig(t *testing.T) {
357357
{
358358
name: "Nil Input (Defaults)",
359359
input: nil,
360-
expected: &saturationdetector.Config{
361-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
362-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
363-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
360+
expected: &staticthresholdcontroller.Config{
361+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
362+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
363+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
364364
},
365365
},
366366
{
@@ -370,10 +370,10 @@ func TestBuildSaturationConfig(t *testing.T) {
370370
KVCacheUtilThreshold: 1.5,
371371
MetricsStalenessThreshold: metav1.Duration{Duration: -10 * time.Second},
372372
},
373-
expected: &saturationdetector.Config{
374-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
375-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
376-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
373+
expected: &staticthresholdcontroller.Config{
374+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
375+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
376+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
377377
},
378378
},
379379
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
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+
17+
package staticthresholdcontroller
1718

1819
import (
1920
"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
locator := requestcontrol.NewDatastorePodLocator(serverRunner.Datastore)
12441244
admissionController := requestcontrol.NewLegacyAdmissionController(detector, locator)

0 commit comments

Comments
 (0)