@@ -11,6 +11,7 @@ import (
1111 "github.com/llm-d-incubation/llm-d-async/pkg/async"
1212 "github.com/llm-d-incubation/llm-d-async/pkg/async/api"
1313 "github.com/llm-d-incubation/llm-d-async/pkg/async/inference/flowcontrol"
14+ "github.com/llm-d-incubation/llm-d-async/pkg/config"
1415 "github.com/llm-d-incubation/llm-d-async/pkg/metrics"
1516 "github.com/llm-d-incubation/llm-d-async/pkg/pubsub"
1617 "github.com/llm-d-incubation/llm-d-async/pkg/redis"
@@ -25,86 +26,66 @@ import (
2526
2627func main () {
2728
28- var loggerVerbosity int
29-
30- var metricsPort int
31- var metricsEndpointAuth bool
32-
33- var concurrency int
34- var requestMergePolicy string
35- var messageQueueImpl string
36-
37- flag .IntVar (& loggerVerbosity , "v" , logging .DEFAULT , "number for the log level verbosity" )
38-
39- flag .IntVar (& metricsPort , "metrics-port" , 9090 , "The metrics port" )
40- flag .BoolVar (& metricsEndpointAuth , "metrics-endpoint-auth" , true , "Enables authentication and authorization of the metrics endpoint" )
41-
42- flag .IntVar (& concurrency , "concurrency" , 8 , "number of concurrent workers" )
43-
44- flag .StringVar (& requestMergePolicy , "request-merge-policy" , "random-robin" , "The request merge policy to use. Supported policies: random-robin" )
45- flag .StringVar (& messageQueueImpl , "message-queue-impl" , "redis-pubsub" , "The message queue implementation to use. Supported implementations: redis-pubsub, redis-sortedset, gcp-pubsub, gcp-pubsub-gated" )
46-
47- var prometheusURL = flag .String ("prometheus-url" , "" , "Prometheus server URL for metric-based gates (e.g., http://localhost:9090)" )
29+ var configFile string
30+ flag .StringVar (& configFile , "config" , "" , "Path to the configuration file" )
4831
4932 opts := zap.Options {
5033 Development : true ,
5134 }
52-
5335 opts .BindFlags (flag .CommandLine )
5436 flag .Parse ()
5537
56- logging .InitLogging (& opts , loggerVerbosity )
38+ cfg , err := config .LoadConfig (configFile )
39+ if err != nil {
40+ fmt .Printf ("failed to load config: %v\n " , err )
41+ os .Exit (1 )
42+ }
43+
44+ logging .InitLogging (& opts , cfg .LogLevel )
5745 defer logging .Sync () // nolint:errcheck
5846
5947 setupLog := ctrl .Log .WithName ("setup" )
6048 setupLog .Info ("Logger initialized" )
6149
62- ////////setupLog.Info("GIE build", "commit-sha", version.CommitSHA, "build-ref", version.BuildRef)
63-
6450 printAllFlags (setupLog )
6551 // Create Gate Factory for per-queue gate instantiation
66- gateFactory := flowcontrol .NewGateFactory (* prometheusURL )
52+ gateFactory := flowcontrol .NewGateFactory (cfg )
6753
6854 var policy api.RequestMergePolicy
69- switch requestMergePolicy {
55+ switch cfg . RequestMergePolicy {
7056 case "random-robin" :
7157 policy = async .NewRandomRobinPolicy ()
7258 default :
73- setupLog .Error (fmt .Errorf ("unknown request merge policy: %s" , requestMergePolicy ), "Unknown request merge policy" , "request-merge-policy" ,
74- requestMergePolicy )
59+ setupLog .Error (fmt .Errorf ("unknown request merge policy: %s" , cfg . RequestMergePolicy ), "Unknown request merge policy" , "request-merge-policy" ,
60+ cfg . RequestMergePolicy )
7561 os .Exit (1 )
7662 }
7763 var impl api.Flow
78- switch messageQueueImpl {
64+ switch cfg . MessageQueueImpl {
7965 case "redis-pubsub" :
80- impl = redis .NewRedisMQFlow ()
66+ impl = redis .NewRedisMQFlow (cfg . Redis )
8167 case "redis-sortedset" :
82- impl = redis .NewRedisSortedSetFlow (redis .WithGateFactory (gateFactory ))
68+ impl = redis .NewRedisSortedSetFlow (cfg . RedisSortedSet , redis .WithGateFactory (gateFactory ))
8369 setupLog .Info ("Using Redis sorted-set flow with per-queue gating" )
8470 case "gcp-pubsub" :
85- impl = pubsub .NewGCPPubSubMQFlow ()
71+ impl = pubsub .NewGCPPubSubMQFlow (cfg . PubSub )
8672 case "gcp-pubsub-gated" :
87- impl = pubsub .NewGCPPubSubMQFlow (pubsub .WithGateFactory (gateFactory ))
73+ impl = pubsub .NewGCPPubSubMQFlow (cfg . PubSub , pubsub .WithGateFactory (gateFactory ))
8874 setupLog .Info ("Using GCP PubSub flow with per-queue gating" )
8975 default :
90- setupLog .Error (fmt .Errorf ("unknown message queue implementation: %s" , messageQueueImpl ), "Unknown message queue implementation" ,
91- "message-queue-impl" , messageQueueImpl )
76+ setupLog .Error (fmt .Errorf ("unknown message queue implementation: %s" , cfg . MessageQueueImpl ), "Unknown message queue implementation" ,
77+ "message-queue-impl" , cfg . MessageQueueImpl )
9278 os .Exit (1 )
9379 }
9480
9581 metrics .Register (metrics .GetAsyncProcessorCollectors (impl .Characteristics ().SupportsMessageLatency )... )
9682
9783 ctx := ctrl .SetupSignalHandler ()
9884
99- // Register metrics handler.
100- // Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
101- // More info:
102- // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/server
103- // - https://book.kubebuilder.io/reference/metrics.html
10485 metricsServerOptions := metricsserver.Options {
105- BindAddress : fmt .Sprintf (":%d" , metricsPort ),
86+ BindAddress : fmt .Sprintf (":%d" , cfg . MetricsPort ),
10687 FilterProvider : func () func (c * rest.Config , httpClient * http.Client ) (metricsserver.Filter , error ) {
107- if metricsEndpointAuth {
88+ if cfg . MetricsEndpointAuth {
10889 return filters .WithAuthenticationAndAuthorization
10990 }
11091
@@ -121,7 +102,7 @@ func main() {
121102 inferenceClient := api .NewHTTPInferenceClient (httpClient )
122103
123104 requestChannel := policy .MergeRequestChannels (impl .RequestChannels ()).Channel
124- for w := 1 ; w <= concurrency ; w ++ {
105+ for w := 1 ; w <= cfg . Concurrency ; w ++ {
125106
126107 go api .Worker (ctx , impl .Characteristics (), inferenceClient , requestChannel , impl .RetryChannel (), impl .ResultChannel ())
127108 }
0 commit comments