Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use '--cursor-after' flag to get recent journal messages #51366

Merged
merged 3 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import static org.elasticsearch.packaging.util.Packages.SYSTEMD_SERVICE;
import static org.elasticsearch.packaging.util.Packages.assertInstalled;
import static org.elasticsearch.packaging.util.Packages.assertRemoved;
import static org.elasticsearch.packaging.util.Packages.clearJournal;
import static org.elasticsearch.packaging.util.Packages.installPackage;
import static org.elasticsearch.packaging.util.Packages.remove;
import static org.elasticsearch.packaging.util.Packages.restartElasticsearch;
Expand Down Expand Up @@ -342,10 +341,9 @@ public void test90DoNotCloseStderrWhenQuiet() throws Exception {
append(tempConf.resolve("elasticsearch.yml"), "discovery.zen.ping.unicast.hosts:15172.30.5.3416172.30.5.35, 172.30.5.17]\n");

// Make sure we don't pick up the journal entries for previous ES instances.
clearJournal(sh);
String elasticsearchStartTime = sh.run("sleep 2 && date +\"%Y-%m-%d %H:%M:%S\"").stdout.trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just adjust the since time by 2 seconds instead of sleeping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would guarantee a gap between Elasticsearch journal messages that's wider than the one-second granularity that the --since flag gives us.

If we have test A and test B and both check for the same error message, but test B is broken, we want to make sure that test A and test B's journal messages don't occur in the same second. I'm not sure how to guarantee that except by introducing a pause.

Another approach might be finding a way to tail journal messages to a test-specific file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some versions of journalctl provide for navigating output with a cursor; I'm going to see if that looks like something we'll have on all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a solution that avoids invoking sleep.

runElasticsearchStartCommand();

final Result logs = sh.run("journalctl -u elasticsearch.service");
final Result logs = sh.run("journalctl -u elasticsearch.service --since=\"" + elasticsearchStartTime + "\"");

assertThat(logs.stdout, containsString("Failed to load settings from [elasticsearch.yml]"));
});
Expand Down
26 changes: 0 additions & 26 deletions qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class Packages {

Expand Down Expand Up @@ -280,31 +279,6 @@ public static Shell.Result runElasticsearchStartCommand(Shell sh) throws IOExcep
return sh.runIgnoreExitCode("service elasticsearch start");
}

/**
* Clears the systemd journal. This is intended to clear the <code>journalctl</code> output
* before a test that checks the journal output.
*/
public static void clearJournal(Shell sh) {
if (isSystemd()) {
sh.run("rm -rf /run/log/journal/*");
final Result result = sh.runIgnoreExitCode("systemctl restart systemd-journald");

// Sometimes the restart fails on Debian 10 with:
// Job for systemd-journald.service failed because the control process exited with error code.
// See "systemctl status systemd-journald.service" and "journalctl -xe" for details.]
//
// ...so run these commands in an attempt to figure out what's going on.
if (result.isSuccess() == false) {
logger.error("Failed to restart systemd-journald: " + result);

logger.error(sh.runIgnoreExitCode("systemctl status systemd-journald.service"));
logger.error(sh.runIgnoreExitCode("journalctl -xe"));

fail("Couldn't clear the systemd journal as restarting systemd-journald failed");
}
}
}

public static void assertElasticsearchStarted(Shell sh, Installation installation) throws Exception {
waitForElasticsearch(installation);

Expand Down