Skip to content

Commit 539d5c6

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 68a5612 commit 539d5c6

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
@@ -69,7 +69,7 @@ import (
6969
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
7070
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
7171
testresponsereceived "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol/plugins/test/responsereceived"
72-
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
72+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationcontrol/framework/plugins/staticthresholdcontroller"
7373
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
7474
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
7575
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/slo_aware_router"
@@ -330,7 +330,7 @@ func (r *Runner) Run(ctx context.Context) error {
330330

331331
scheduler := scheduling.NewSchedulerWithConfig(r.schedulerConfig)
332332

333-
saturationDetector := saturationdetector.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
333+
saturationDetector := staticthresholdcontroller.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
334334

335335
// --- Admission Control Initialization ---
336336
var admissionController requestcontrol.AdmissionController
@@ -556,23 +556,23 @@ func (r *Runner) deprecatedConfigurationHelper(cfg *config.Config, logger logr.L
556556
if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
557557
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
558558
cfg.SaturationDetectorConfig.QueueDepthThreshold =
559-
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
559+
env.GetEnvInt(EnvSdQueueDepthThreshold, staticthresholdcontroller.DefaultQueueDepthThreshold, logger)
560560
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
561-
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
561+
cfg.SaturationDetectorConfig.QueueDepthThreshold = staticthresholdcontroller.DefaultQueueDepthThreshold
562562
}
563563
}
564564
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
565565
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
566-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
566+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, staticthresholdcontroller.DefaultKVCacheUtilThreshold, logger)
567567
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
568-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
568+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = staticthresholdcontroller.DefaultKVCacheUtilThreshold
569569
}
570570
}
571571
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
572572
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
573-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
573+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, staticthresholdcontroller.DefaultMetricsStalenessThreshold, logger)
574574
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
575-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
575+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = staticthresholdcontroller.DefaultMetricsStalenessThreshold
576576
}
577577
}
578578
}

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"
@@ -203,11 +203,11 @@ func loadFeatureConfig(gates configapi.FeatureGates) map[string]bool {
203203
return config
204204
}
205205

206-
func buildSaturationConfig(apiConfig *configapi.SaturationDetector) *saturationdetector.Config {
207-
cfg := &saturationdetector.Config{
208-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
209-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
210-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
206+
func buildSaturationConfig(apiConfig *configapi.SaturationDetector) *staticthresholdcontroller.Config {
207+
cfg := &staticthresholdcontroller.Config{
208+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
209+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
210+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
211211
}
212212

213213
if apiConfig != nil {

pkg/epp/config/loader/configloader_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
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/picker"
3737
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
@@ -321,7 +321,7 @@ func TestBuildSaturationConfig(t *testing.T) {
321321
tests := []struct {
322322
name string
323323
input *configapi.SaturationDetector
324-
expected *saturationdetector.Config
324+
expected *staticthresholdcontroller.Config
325325
}{
326326
{
327327
name: "Valid Configuration",
@@ -330,7 +330,7 @@ func TestBuildSaturationConfig(t *testing.T) {
330330
KVCacheUtilThreshold: 0.9,
331331
MetricsStalenessThreshold: metav1.Duration{Duration: 500 * time.Millisecond},
332332
},
333-
expected: &saturationdetector.Config{
333+
expected: &staticthresholdcontroller.Config{
334334
QueueDepthThreshold: 20,
335335
KVCacheUtilThreshold: 0.9,
336336
MetricsStalenessThreshold: 500 * time.Millisecond,
@@ -339,10 +339,10 @@ func TestBuildSaturationConfig(t *testing.T) {
339339
{
340340
name: "Nil Input (Defaults)",
341341
input: nil,
342-
expected: &saturationdetector.Config{
343-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
344-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
345-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
342+
expected: &staticthresholdcontroller.Config{
343+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
344+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
345+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
346346
},
347347
},
348348
{
@@ -352,10 +352,10 @@ func TestBuildSaturationConfig(t *testing.T) {
352352
KVCacheUtilThreshold: 1.5,
353353
MetricsStalenessThreshold: metav1.Duration{Duration: -10 * time.Second},
354354
},
355-
expected: &saturationdetector.Config{
356-
QueueDepthThreshold: saturationdetector.DefaultQueueDepthThreshold,
357-
KVCacheUtilThreshold: saturationdetector.DefaultKVCacheUtilThreshold,
358-
MetricsStalenessThreshold: saturationdetector.DefaultMetricsStalenessThreshold,
355+
expected: &staticthresholdcontroller.Config{
356+
QueueDepthThreshold: staticthresholdcontroller.DefaultQueueDepthThreshold,
357+
KVCacheUtilThreshold: staticthresholdcontroller.DefaultKVCacheUtilThreshold,
358+
MetricsStalenessThreshold: staticthresholdcontroller.DefaultMetricsStalenessThreshold,
359359
},
360360
},
361361
}

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)