@@ -17,6 +17,7 @@ package main
1717import (
1818 "context"
1919 "os"
20+ "strconv"
2021 "time"
2122
2223 "github.com/aws/amazon-vpc-cni-k8s/pkg/ipamd"
@@ -90,6 +91,9 @@ func startBackgroundAPIServerCheck(ipamContext *ipamd.IPAMContext) {
9091}
9192
9293func _main () int {
94+ // Start measuring full startup duration
95+ startupStartTime := time .Now ()
96+
9397 // Do not add anything before initializing logger
9498 log := logger .Get ()
9599
@@ -105,6 +109,8 @@ func _main() int {
105109 log .Info ("SGP, custom networking or pod annotation feature is in use, waiting for API server connectivity to start IPAMD" )
106110 if err := k8sapi .CheckAPIServerConnectivity (); err != nil {
107111 log .Errorf ("Failed to check API server connectivity: %s" , err )
112+ // Record failed startup
113+ metrics .IpamdStartupDuration .WithLabelValues ("false" , strconv .FormatBool (withApiServer ), "api_server_connectivity" ).Observe (time .Since (startupStartTime ).Seconds ())
108114 return 1
109115 } else {
110116 log .Info ("API server connectivity established." )
@@ -131,12 +137,22 @@ func _main() int {
131137 log .Errorf ("Failed to create event recorder: %s" , err )
132138 log .Warn ("Skipping event recorder initialization" )
133139 }
140+ // Measure AWS initialization duration
141+ awsStartTime := time .Now ()
134142 ipamContext , err := ipamd .New (k8sClient , withApiServer )
143+ awsDuration := time .Since (awsStartTime ).Seconds ()
144+
135145 if err != nil {
136146 log .Errorf ("Initialization failure: %v" , err )
147+ // Record failed AWS initialization and failed startup
148+ metrics .IpamdStartupAwsDuration .WithLabelValues ("false" ).Observe (awsDuration )
149+ metrics .IpamdStartupDuration .WithLabelValues ("false" , strconv .FormatBool (withApiServer ), "aws_initialization" ).Observe (time .Since (startupStartTime ).Seconds ())
137150 return 1
138151 }
139152
153+ // Record successful AWS initialization
154+ metrics .IpamdStartupAwsDuration .WithLabelValues ("true" ).Observe (awsDuration )
155+
140156 // If not connected to API server yet, start background checks
141157 if ! withApiServer {
142158 startBackgroundAPIServerCheck (ipamContext )
@@ -155,7 +171,10 @@ func _main() int {
155171 go ipamContext .ServeIntrospection ()
156172 }
157173
158- // Start the RPC listener
174+ // Record successful startup duration before the blocking RPC handler call
175+ metrics .IpamdStartupDuration .WithLabelValues ("true" , strconv .FormatBool (withApiServer ), "" ).Observe (time .Since (startupStartTime ).Seconds ())
176+
177+ // Start the RPC listener (this is a blocking call)
159178 err = ipamContext .RunRPCHandler (version .Version )
160179 if err != nil {
161180 log .Errorf ("Failed to set up gRPC handler: %v" , err )
0 commit comments