Skip to content

Commit 53579ac

Browse files
authored
refactor: Relocate SaturationDetector (#1976)
This commit moves the existing `SaturationDetector` implementation to its new home under the EPP plugin framework structure. This is a preparatory step towards making `SaturationDetector` an official EPP extension point. - Moved files to `.../framework/plugins/utilizationdetector` - Renamed `saturationdetector.go` to `detector.go` - Renamed `saturationdetector_test.go` to `detector_test.go` - Fixed imports No functional changes are included in this commit.
1 parent 5ec1fa1 commit 53579ac

9 files changed

Lines changed: 41 additions & 40 deletions

File tree

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/saturationdetector/framework/plugins/utilizationdetector"
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"
@@ -285,7 +285,7 @@ func (r *Runner) Run(ctx context.Context) error {
285285

286286
scheduler := scheduling.NewSchedulerWithConfig(r.schedulerConfig)
287287

288-
saturationDetector := saturationdetector.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
288+
saturationDetector := utilizationdetector.NewDetector(eppConfig.SaturationDetectorConfig, setupLog)
289289

290290
// --- Admission Control Initialization ---
291291
var admissionController requestcontrol.AdmissionController
@@ -508,23 +508,23 @@ func (r *Runner) deprecatedConfigurationHelper(cfg *config.Config, logger logr.L
508508
if _, ok := os.LookupEnv(EnvSdQueueDepthThreshold); ok {
509509
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
510510
cfg.SaturationDetectorConfig.QueueDepthThreshold =
511-
env.GetEnvInt(EnvSdQueueDepthThreshold, saturationdetector.DefaultQueueDepthThreshold, logger)
511+
env.GetEnvInt(EnvSdQueueDepthThreshold, utilizationdetector.DefaultQueueDepthThreshold, logger)
512512
if cfg.SaturationDetectorConfig.QueueDepthThreshold <= 0 {
513-
cfg.SaturationDetectorConfig.QueueDepthThreshold = saturationdetector.DefaultQueueDepthThreshold
513+
cfg.SaturationDetectorConfig.QueueDepthThreshold = utilizationdetector.DefaultQueueDepthThreshold
514514
}
515515
}
516516
if _, ok := os.LookupEnv(EnvSdKVCacheUtilThreshold); ok {
517517
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
518-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, saturationdetector.DefaultKVCacheUtilThreshold, logger)
518+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = env.GetEnvFloat(EnvSdKVCacheUtilThreshold, utilizationdetector.DefaultKVCacheUtilThreshold, logger)
519519
if cfg.SaturationDetectorConfig.KVCacheUtilThreshold <= 0 || cfg.SaturationDetectorConfig.KVCacheUtilThreshold >= 1 {
520-
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = saturationdetector.DefaultKVCacheUtilThreshold
520+
cfg.SaturationDetectorConfig.KVCacheUtilThreshold = utilizationdetector.DefaultKVCacheUtilThreshold
521521
}
522522
}
523523
if _, ok := os.LookupEnv(EnvSdMetricsStalenessThreshold); ok {
524524
logger.Info("Configuring Saturation Detector using environment variables is deprecated and will be removed in next version")
525-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, saturationdetector.DefaultMetricsStalenessThreshold, logger)
525+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = env.GetEnvDuration(EnvSdMetricsStalenessThreshold, utilizationdetector.DefaultMetricsStalenessThreshold, logger)
526526
if cfg.SaturationDetectorConfig.MetricsStalenessThreshold <= 0 {
527-
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = saturationdetector.DefaultMetricsStalenessThreshold
527+
cfg.SaturationDetectorConfig.MetricsStalenessThreshold = utilizationdetector.DefaultMetricsStalenessThreshold
528528
}
529529
}
530530
}

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/saturationdetector/framework/plugins/utilizationdetector"
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 *utilizationdetector.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/saturationdetector/framework/plugins/utilizationdetector"
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) *utilizationdetector.Config {
215+
cfg := &utilizationdetector.Config{
216+
QueueDepthThreshold: utilizationdetector.DefaultQueueDepthThreshold,
217+
KVCacheUtilThreshold: utilizationdetector.DefaultKVCacheUtilThreshold,
218+
MetricsStalenessThreshold: utilizationdetector.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/saturationdetector/framework/plugins/utilizationdetector"
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 *utilizationdetector.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: &utilizationdetector.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: &utilizationdetector.Config{
361+
QueueDepthThreshold: utilizationdetector.DefaultQueueDepthThreshold,
362+
KVCacheUtilThreshold: utilizationdetector.DefaultKVCacheUtilThreshold,
363+
MetricsStalenessThreshold: utilizationdetector.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: &utilizationdetector.Config{
374+
QueueDepthThreshold: utilizationdetector.DefaultQueueDepthThreshold,
375+
KVCacheUtilThreshold: utilizationdetector.DefaultKVCacheUtilThreshold,
376+
MetricsStalenessThreshold: utilizationdetector.DefaultMetricsStalenessThreshold,
377377
},
378378
},
379379
}

pkg/epp/saturationdetector/config.go renamed to pkg/epp/saturationdetector/framework/plugins/utilizationdetector/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 utilizationdetector
1718

1819
import (
1920
"time"

pkg/epp/saturationdetector/saturationdetector.go renamed to pkg/epp/saturationdetector/framework/plugins/utilizationdetector/detector.go

Lines changed: 2 additions & 2 deletions
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 implements a mechanism to determine if the
17+
// Package utilizationdetector implements a mechanism to determine if the
1818
// backend model servers are considered saturated based on observed metrics.
1919
//
2020
// The current implementation provides a saturation signal (IsSaturated)
@@ -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 utilizationdetector
3131

3232
import (
3333
"context"

pkg/epp/saturationdetector/saturationdetector_test.go renamed to pkg/epp/saturationdetector/framework/plugins/utilizationdetector/detector_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 utilizationdetector
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/saturationdetector/framework/plugins/utilizationdetector"
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 *utilizationdetector.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/saturationdetector/framework/plugins/utilizationdetector"
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 := &utilizationdetector.Config{
1237+
QueueDepthThreshold: utilizationdetector.DefaultQueueDepthThreshold,
1238+
KVCacheUtilThreshold: utilizationdetector.DefaultKVCacheUtilThreshold,
1239+
MetricsStalenessThreshold: utilizationdetector.DefaultMetricsStalenessThreshold,
12401240
}
1241-
detector := saturationdetector.NewDetector(sdConfig, logger.WithName("saturation-detector"))
1241+
detector := utilizationdetector.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)