@@ -44,13 +44,15 @@ import (
4444func main () {
4545 var (
4646 port int
47+ adminPort int
4748 inCluster bool
4849 autoscalerURL string
4950 namespace string
5051 clusterConfigPath string
5152 )
5253
5354 flag .IntVar (& port , "port" , 8000 , "port where the activator server will be exposed" )
55+ flag .IntVar (& adminPort , "admin-port" , 15000 , "port where the admin server will be exposed" )
5456 flag .BoolVar (& inCluster , "in-cluster" , false , "use when autoscaler runs in-cluster" )
5557 flag .StringVar (& autoscalerURL , "autoscaler-url" , "" , "the URL for the cortex autoscaler endpoint" )
5658 flag .StringVar (& namespace , "namespace" , os .Getenv ("CORTEX_NAMESPACE" ),
@@ -114,6 +116,8 @@ func main() {
114116 kubeClient := k8sClient .ClientSet ()
115117 autoscalerClient := autoscaler .NewClient (autoscalerURL )
116118
119+ prometheusStatsReporter := activator .NewPrometheusStatsReporter ()
120+
117121 istioInformerFactory := istioinformers .NewSharedInformerFactoryWithOptions (
118122 istioClient , 10 * time .Second , // TODO: check how much makes sense
119123 istioinformers .WithNamespace (namespace ),
@@ -129,12 +133,29 @@ func main() {
129133 )
130134 deploymentInformer := kubeInformerFactory .Apps ().V1 ().Deployments ().Informer ()
131135
132- act := activator .New (virtualServiceClient , deploymentInformer , virtualServiceInformer , autoscalerClient , log )
136+ act := activator .New (
137+ virtualServiceClient ,
138+ deploymentInformer ,
139+ virtualServiceInformer ,
140+ autoscalerClient ,
141+ prometheusStatsReporter ,
142+ log ,
143+ )
133144
134145 handler := activator .NewHandler (act , log )
135- server := & http.Server {
136- Addr : ":" + strconv .Itoa (port ),
137- Handler : handler ,
146+
147+ adminHandler := http .NewServeMux ()
148+ adminHandler .Handle ("/metrics" , prometheusStatsReporter )
149+
150+ servers := map [string ]* http.Server {
151+ "activator" : {
152+ Addr : ":" + strconv .Itoa (port ),
153+ Handler : handler ,
154+ },
155+ "admin" : {
156+ Addr : ":" + strconv .Itoa (adminPort ),
157+ Handler : adminHandler ,
158+ },
138159 }
139160
140161 stopCh := make (chan struct {})
@@ -145,10 +166,12 @@ func main() {
145166 }()
146167
147168 errCh := make (chan error )
148- go func () {
149- log .Infof ("Starting activator server on %s" , server .Addr )
150- errCh <- server .ListenAndServe ()
151- }()
169+ for name , server := range servers {
170+ go func (name string , server * http.Server ) {
171+ log .Infof ("Starting %s server on %s" , name , server .Addr )
172+ errCh <- server .ListenAndServe ()
173+ }(name , server )
174+ }
152175
153176 sigint := make (chan os.Signal , 1 )
154177 signal .Notify (sigint , os .Interrupt )
@@ -159,10 +182,14 @@ func main() {
159182 case <- sigint :
160183 // We received an interrupt signal, shut down.
161184 log .Info ("Received TERM signal, handling a graceful shutdown..." )
162- log .Info ("Shutting down server" )
163- if err = server .Shutdown (context .Background ()); err != nil {
164- // Error from closing listeners, or context timeout:
165- log .Warnw ("HTTP server Shutdown Error" , zap .Error (err ))
185+
186+ for name , server := range servers {
187+ log .Infof ("Shutting down %s server" , name )
188+ if err = server .Shutdown (context .Background ()); err != nil {
189+ // Error from closing listeners, or context timeout:
190+ log .Warnw ("HTTP server Shutdown Error" , zap .Error (err ))
191+ telemetry .Error (errors .Wrap (err , "HTTP server Shutdown Error" ))
192+ }
166193 }
167194 log .Info ("Shutdown complete, exiting..." )
168195 }
0 commit comments