|
68 | 68 | public class Main { |
69 | 69 | private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); |
70 | 70 |
|
| 71 | + // Startup timing field |
| 72 | + private static volatile Instant startupBeginTime; |
| 73 | + |
71 | 74 | private final JsonObject config; |
72 | 75 | private final Vertx vertx; |
73 | 76 | private final ApplicationVersion appVersion; |
@@ -244,7 +247,43 @@ private KeyManager getKeyManager() { |
244 | 247 | return new KeyManager(this.keysetKeyStore, this.keysetProvider); |
245 | 248 | } |
246 | 249 |
|
| 250 | + /** |
| 251 | + * Calculate startup duration following established codebase patterns. |
| 252 | + * @return Duration from startup begin to completion, or null if timing data is invalid |
| 253 | + */ |
| 254 | + private static Duration getStartupDuration() { |
| 255 | + if (startupBeginTime == null) { |
| 256 | + return null; |
| 257 | + } |
| 258 | + return Duration.between(startupBeginTime, Instant.now()); |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * Record startup completion and register startup duration metric. |
| 263 | + * Called when the HTTP server successfully starts listening. |
| 264 | + */ |
| 265 | + public static void recordStartupComplete() { |
| 266 | + final Duration startupDuration = getStartupDuration(); |
| 267 | + |
| 268 | + // Register startup duration metric following existing pattern |
| 269 | + final String version = Optional.ofNullable(System.getenv("IMAGE_VERSION")).orElse("unknown"); |
| 270 | + final double durationSeconds = startupDuration != null ? startupDuration.toMillis() / 1000.0 : -1.0; |
| 271 | + |
| 272 | + Gauge.builder("uid2_operator_startup_duration_seconds", () -> durationSeconds) |
| 273 | + .description("Time taken for operator to start up and begin serving requests") |
| 274 | + .tags("version", version) |
| 275 | + .register(globalRegistry); |
| 276 | + |
| 277 | + if (startupDuration != null) { |
| 278 | + LOGGER.info("UID2 Operator startup completed in {:.3f} seconds", durationSeconds); |
| 279 | + } else { |
| 280 | + LOGGER.warn("UID2 Operator startup completed but timing measurement failed"); |
| 281 | + } |
| 282 | + } |
| 283 | + |
247 | 284 | public static void main(String[] args) throws Exception { |
| 285 | + // Record startup begin time following established patterns |
| 286 | + startupBeginTime = Instant.now(); |
248 | 287 |
|
249 | 288 | java.security.Security.setProperty("networkaddress.cache.ttl" , "60"); |
250 | 289 |
|
|
0 commit comments