@@ -221,20 +221,22 @@ protected void configure() {
221221 protected void containerIsStarting (final InspectContainerResponse containerInfo ) {
222222 logger ().debug ("Couchbase container is starting, performing configuration." );
223223
224- waitUntilNodeIsOnline ();
225- initializeIsEnterprise ();
226- renameNode ();
227- initializeServices ();
228- configureAdminUser ();
229- configureExternalPorts ();
224+ timePhase ("waitUntilNodeIsOnline" , this ::waitUntilNodeIsOnline );
225+ timePhase ("initializeIsEnterprise" , this ::initializeIsEnterprise );
226+ timePhase ("renameNode" , this ::renameNode );
227+ timePhase ("initializeServices" , this ::initializeServices );
228+ timePhase ("configureAdminUser" , this ::configureAdminUser );
229+ timePhase ("configureExternalPorts" , this ::configureExternalPorts );
230+
230231 if (enabledServices .contains (CouchbaseService .INDEX )) {
231- configureIndexer ( );
232+ timePhase ( "configureIndexer" , this :: configureIndexer );
232233 }
233234 }
234235
235236 @ Override
236237 protected void containerIsStarted (InspectContainerResponse containerInfo ) {
237- createBuckets ();
238+ timePhase ("createBuckets" , this ::createBuckets );
239+
238240 logger ().info ("Couchbase container is ready! UI available at http://{}:{}" , getHost (), getMappedPort (MGMT_PORT ));
239241 }
240242
@@ -389,30 +391,34 @@ private void createBuckets() {
389391
390392 checkSuccessfulResponse (response , "Could not create bucket " + bucket .getName ());
391393
392- new HttpWaitStrategy ()
394+ timePhase ("createBucket:" + bucket .getName () + ":waitForAllServicesEnabled" , () ->
395+ new HttpWaitStrategy ()
393396 .forPath ("/pools/default/b/" + bucket .getName ())
394397 .forPort (MGMT_PORT )
395398 .withBasicCredentials (username , password )
396399 .forStatusCode (200 )
397400 .forResponsePredicate (new AllServicesEnabledPredicate ())
398- .waitUntilReady (this );
401+ .waitUntilReady (this )
402+ );
399403
400404 if (enabledServices .contains (CouchbaseService .QUERY )) {
401405 // If the query service is enabled, make sure that we only proceed if the query engine also
402406 // knows about the bucket in its metadata configuration.
403- Unreliables .retryUntilTrue (1 , TimeUnit .MINUTES , () -> {
404- @ Cleanup Response queryResponse = doHttpRequest (QUERY_PORT , "/query/service" , "POST" , new FormBody .Builder ()
405- .add ("statement" , "SELECT COUNT(*) > 0 as present FROM system:keyspaces WHERE name = \" " + bucket .getName () + "\" " )
406- .build (), true );
407-
408- String body = queryResponse .body () != null ? queryResponse .body ().string () : null ;
409- checkSuccessfulResponse (queryResponse , "Could not poll query service state for bucket: " + bucket .getName ());
410-
411- return Optional .of (MAPPER .readTree (body ))
412- .map (n -> n .at ("/results/0/present" ))
413- .map (JsonNode ::asBoolean )
414- .orElse (false );
415- });
407+ timePhase (
408+ "createBucket:" + bucket .getName () + ":queryKeyspacePresent" ,
409+ () -> Unreliables .retryUntilTrue (1 , TimeUnit .MINUTES , () -> {
410+ @ Cleanup Response queryResponse = doHttpRequest (QUERY_PORT , "/query/service" , "POST" , new FormBody .Builder ()
411+ .add ("statement" , "SELECT COUNT(*) > 0 as present FROM system:keyspaces WHERE name = \" " + bucket .getName () + "\" " )
412+ .build (), true );
413+
414+ String body = queryResponse .body () != null ? queryResponse .body ().string () : null ;
415+ checkSuccessfulResponse (queryResponse , "Could not poll query service state for bucket: " + bucket .getName ());
416+
417+ return Optional .of (MAPPER .readTree (body ))
418+ .map (n -> n .at ("/results/0/present" ))
419+ .map (JsonNode ::asBoolean )
420+ .orElse (false );
421+ }));
416422 }
417423
418424 if (bucket .hasPrimaryIndex ()) {
@@ -501,6 +507,20 @@ private Response doHttpRequest(final int port, final String path, final String m
501507 }
502508 }
503509
510+ /**
511+ * Helper method which times an individual phase and logs it for debugging and optimization purposes.
512+ *
513+ * @param name the name of the phase.
514+ * @param toTime the runnable that should be timed.
515+ */
516+ private void timePhase (final String name , final Runnable toTime ) {
517+ long start = System .nanoTime ();
518+ toTime .run ();
519+ long end = System .nanoTime ();
520+
521+ logger ().debug ("Phase {} took {}ms" , name , TimeUnit .NANOSECONDS .toMillis (end - start ));
522+ }
523+
504524 /**
505525 * In addition to getting a 200, we need to make sure that all services we need are enabled and available on
506526 * the bucket.
0 commit comments