Docker-maven-plugin: Allow waiting for a specific number of log occurences

Created on 1 Dec 2016  路  8Comments  路  Source: fabric8io/docker-maven-plugin

Description

Info

  • d-m-p version : 0.17.1
  • Maven version (mvn -v) : 3.3.9
  • Docker version : 1.12.3

Some containers (observed both with postgres:9.5 for example) emit a log message indicating readiness multiple times (probably the db is restarted after initial env setup I assume).
Example:

waiting for server to start....LOG:  database system was shut down at 2016-12-01 09:31:22 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
 done
server started
ALTER ROLE


/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
waiting for server to shut down....LOG:  shutting down
LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

LOG:  database system was shut down at 2016-12-01 09:31:30 UTC
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections

For such cases it would be useful to specify that the plugin should wait for a specific number of occurences of the specified log message pattern.

Something like:

                              <wait>
                                 <log>database system is ready to accept connections</log>
                                 <count>2</count>
                              </wait>

would wait for the second occurrence of the pattern before continuing. This seems it would solve #608 as well.

feature

Most helpful comment

Another idea would be to allow multi-line patterns: When the multiline option is enabled in the pattern (?s), then keep all log lines and try to match on the whole log. Of course this can be a bit more memory intensive, but should be easy to add in the LogWatcher.

Kudos to @michael-simons for the idea ;-)

All 8 comments

+1

looks useful to me. We still would have to think about to introduce the configuration. Simply <count> doesn't work because its on the same level a http checks and so on.

Ideally we would have something like:

<wait>
  <log>
     <pattern>database system is ready to accept connections</pattern>
     <count>2</count>
  </log>
</wait>

however <log> is already _burned_ (for backwards compatibility). Maybe <out> or <stdout> (with then in addition <stderr>, too) would be a good fit as alternative for the extended definition ?

Another idea would be to allow multi-line patterns: When the multiline option is enabled in the pattern (?s), then keep all log lines and try to match on the whole log. Of course this can be a bit more memory intensive, but should be easy to add in the LogWatcher.

Kudos to @michael-simons for the idea ;-)

@miszobi @who I just added multi line matching now, so that you can now wait on this condition like with

"(?s)ready to accept connections.*ready to accept connections"

for happening this line twice. I think this will perfectly fit your use case and is more flexible then a count (and also doesn't require any extension to the log configuration).

If this is good enough for you I would like to close this issue.

@rhuss using a multi-line pattern for this sounds like a good solution to me. Thanks a lot!

Looks good to me! It should solve our particular use case.

Awesome ;-). You can expect a release tomorrow :)

"(?s)ready to accept connections.*ready to accept connections"

It works fine in 0.24.0 but broken in 0.25.2 for me. It just stop and waiting on a pattern line

[INFO] --- docker-maven-plugin:0.25.0:start (start) @ annotations-jooq ---
[INFO] DOCKER> [postgres:9.6]: Start container 9429fe081828
[INFO] DOCKER> Pattern '(?s)ready to accept connections.*ready to accept connections' matched for container 9429fe081828
Was this page helpful?
0 / 5 - 0 ratings