generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 85
Refactor: Externalize Scheduler's saturation logic and criticality-based service differentiation #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LukeAVanDrie
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
LukeAVanDrie:saturation-detector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor: Externalize Scheduler's saturation logic and criticality-based service differentiation #805
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,9 @@ import ( | |
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics/collectors" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/filter" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/multi/prefix" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/picker" | ||
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/scorer" | ||
|
@@ -157,13 +157,19 @@ func run() error { | |
}) | ||
setupLog.Info("Flags processed", "flags", flags) | ||
|
||
// Init runtime. | ||
// --- Load Configurations from Environment Variables --- | ||
// Note: Scheduler config is loaded via its package init currently. We may | ||
// want to load it here explicitly: | ||
sdConfig := saturationdetector.LoadConfigFromEnv() | ||
|
||
// --- Get Kubernetes Config --- | ||
cfg, err := ctrl.GetConfig() | ||
if err != nil { | ||
setupLog.Error(err, "Failed to get rest config") | ||
setupLog.Error(err, "Failed to get Kubernetes rest config") | ||
return err | ||
} | ||
|
||
// --- Setup Manager --- | ||
poolNamespacedName := types.NamespacedName{ | ||
Name: *poolName, | ||
Namespace: *poolNamespace, | ||
|
@@ -174,7 +180,7 @@ func run() error { | |
return err | ||
} | ||
|
||
// Set up mapper for metric scraping. | ||
// --- Setup Datastore --- | ||
mapping, err := backendmetrics.NewMetricMapping( | ||
*totalQueuedRequestsMetric, | ||
*kvCacheUsagePercentageMetric, | ||
|
@@ -185,14 +191,12 @@ func run() error { | |
return err | ||
} | ||
verifyMetricMapping(*mapping, setupLog) | ||
|
||
pmf := backendmetrics.NewPodMetricsFactory(&backendmetrics.PodMetricsClientImpl{MetricMapping: mapping}, *refreshMetricsInterval) | ||
// Setup runner. | ||
ctx := ctrl.SetupSignalHandler() | ||
appDatastore := datastore.NewDatastore(ctx, pmf) | ||
|
||
datastore := datastore.NewDatastore(ctx, pmf) | ||
|
||
scheduler := scheduling.NewScheduler(datastore) | ||
// --- Initialize EPP Components --- | ||
appScheduler := scheduling.NewScheduler(appDatastore) | ||
if schedulerV2 == "true" { | ||
queueScorerWeight := envutil.GetEnvInt("QUEUE_SCORE_WEIGHT", scorer.DefaultQueueScorerWeight, setupLog) | ||
kvCacheScorerWeight := envutil.GetEnvInt("KV_CACHE_SCORE_WEIGHT", scorer.DefaultKVCacheScorerWeight, setupLog) | ||
|
@@ -207,47 +211,62 @@ func run() error { | |
} | ||
schedulerConfig := scheduling.NewSchedulerConfig( | ||
[]plugins.PreSchedule{}, | ||
[]plugins.Filter{filter.NewSheddableCapacityFilter()}, | ||
[]plugins.Filter{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liu-cong I can also do this in the next PR when I actually remove this from the scheduler. Right now, I have only removed it from scheduler v2, not the original decision tree filter. If we want to bundle that together in a single PR, I can revert this line for now. |
||
scorers, | ||
picker.NewMaxScorePicker(), | ||
[]plugins.PostSchedule{}, | ||
[]plugins.PostResponse{}, | ||
schedConfigOpts...) | ||
scheduler = scheduling.NewSchedulerWithConfig(datastore, schedulerConfig) | ||
appScheduler = scheduling.NewSchedulerWithConfig(appDatastore, schedulerConfig) | ||
} | ||
|
||
appSaturationDetector, err := saturationdetector.NewDetector( | ||
*sdConfig, | ||
appDatastore, | ||
ctrl.Log.WithName("saturation-detector"), | ||
) | ||
if err != nil { | ||
setupLog.Error(err, "Failed to create SaturationDetector") | ||
return err | ||
} | ||
|
||
// --- Setup ExtProc Server Runner --- | ||
serverRunner := &runserver.ExtProcServerRunner{ | ||
GrpcPort: *grpcPort, | ||
DestinationEndpointHintMetadataNamespace: *destinationEndpointHintMetadataNamespace, | ||
DestinationEndpointHintKey: *destinationEndpointHintKey, | ||
PoolNamespacedName: poolNamespacedName, | ||
Datastore: datastore, | ||
Datastore: appDatastore, | ||
SecureServing: *secureServing, | ||
CertPath: *certPath, | ||
RefreshPrometheusMetricsInterval: *refreshPrometheusMetricsInterval, | ||
Scheduler: scheduler, | ||
Scheduler: appScheduler, | ||
SaturationDetector: appSaturationDetector, | ||
} | ||
if err := serverRunner.SetupWithManager(ctx, mgr); err != nil { | ||
setupLog.Error(err, "Failed to setup ext-proc controllers") | ||
setupLog.Error(err, "Failed to setup EPP controllers") | ||
return err | ||
} | ||
|
||
// --- Add Runnables to Manager --- | ||
|
||
// Register health server. | ||
if err := registerHealthServer(mgr, ctrl.Log.WithName("health"), datastore, *grpcHealthPort); err != nil { | ||
if err := registerHealthServer(mgr, ctrl.Log.WithName("health"), appDatastore, *grpcHealthPort); err != nil { | ||
return err | ||
} | ||
|
||
// Register ext-proc server. | ||
if err := mgr.Add(serverRunner.AsRunnable(ctrl.Log.WithName("ext-proc"))); err != nil { | ||
setupLog.Error(err, "Failed to register ext-proc gRPC server") | ||
if err := registerExtProcServer(mgr, serverRunner, ctrl.Log.WithName("ext-proc")); err != nil { | ||
return err | ||
} | ||
|
||
// Register metrics handler. | ||
if err := registerMetricsHandler(mgr, *metricsPort, cfg, datastore); err != nil { | ||
if err := registerMetricsHandler(mgr, *metricsPort, cfg, appDatastore); err != nil { | ||
return err | ||
} | ||
|
||
// Start the manager. This blocks until a signal is received. | ||
// --- Start Manager --- | ||
// This blocks until a signal is received. | ||
setupLog.Info("Controller manager starting") | ||
if err := mgr.Start(ctx); err != nil { | ||
setupLog.Error(err, "Error starting controller manager") | ||
|
@@ -275,6 +294,17 @@ func initLogging(opts *zap.Options) { | |
ctrl.SetLogger(logger) | ||
} | ||
|
||
// registerExtProcServer adds the ExtProcServerRunner as a Runnable to the | ||
// manager. | ||
func registerExtProcServer(mgr manager.Manager, runner *runserver.ExtProcServerRunner, logger logr.Logger) error { | ||
if err := mgr.Add(runner.AsRunnable(logger)); err != nil { | ||
setupLog.Error(err, "Failed to register ext-proc gRPC server runnable") | ||
return err | ||
} | ||
setupLog.Info("ExtProc server runner added to manager.") | ||
return nil | ||
} | ||
|
||
// registerHealthServer adds the Health gRPC server as a Runnable to the given manager. | ||
func registerHealthServer(mgr manager.Manager, logger logr.Logger, ds datastore.Datastore, port int) error { | ||
srv := grpc.NewServer() | ||
|
@@ -364,5 +394,4 @@ func verifyMetricMapping(mapping backendmetrics.MetricMapping, logger logr.Logge | |
if mapping.LoraRequestInfo == nil { | ||
logger.Info("Not scraping metric: LoraRequestInfo") | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why appDatastore and appScheduler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this to avoid collisions with the package names. This is not strictly necessary though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps call them
ds
sched