Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
debug settings were not honored by upbanner
  • Loading branch information
gclayburg committed Jun 28, 2021
1 parent 07edfef commit 6ec53fc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public WhatsUpProbes getWhatsUpProbes() {
}

public void dumpAll() {
whatsUpProbes.dumpAll();
if (environment.getProperty("upbanner.debug") != null &&
environment.getProperty("upbanner.debug").equalsIgnoreCase("true")) {
whatsUpProbes.dumpAll();
}
}

private UpbannerSettings createUpbannerSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,44 +308,36 @@ public String getEnvironmentProperty(String key) {
* We attempt to print this information as soon as possible during application startup
*/
public void dumpAll() {
dumpAll(stringBuilder -> {
});
}

public void dumpAll(ExtraLinePrinter extraLinePrinter) {
if (upbannerSettings.isDebug()) {
StringBuilder probe;
if (this.probeResult == null || upbannerSettings.isForceRecompute()) {
probe = new StringBuilder();
section(probe, "\n===== What OS and hardware are we running on =====");
oshiProbe.createReport(probe);
section(probe, "\n===== What OS resources are limited ==============");
dumpCPUlimits(probe);
dumpMemoryLimits(probe);
section(probe, "\n===== What environment are we running with =======");
StringBuilder probe;
if (this.probeResult == null || upbannerSettings.isForceRecompute()) {
probe = new StringBuilder();
section(probe, "\n===== What OS and hardware are we running on =====");
oshiProbe.createReport(probe);
section(probe, "\n===== What OS resources are limited ==============");
dumpCPUlimits(probe);
dumpMemoryLimits(probe);
section(probe, "\n===== What environment are we running with =======");
// dumpSystemProperties(probe);
// dumpENV(probe);
dumpPropertySources(probe);
section(probe, "\n===== How was it built ===========================");
dumpBuildProperties(probe);
section(probe, "\n===== How was it started =========================");
jarProbe.init(probe);
dumpStartupCommandJVMargs(probe);
section(probe, "\n===== What is running ============================");
dumpGitProperties(probe);
jarProbe.createRootManifestReport(probe);
jarProbe.createSnapshotJarReport(probe);
extraLinePrinter.call(probe);
this.probeResult = probe;
} else {
probe = this.probeResult;
}
if (log.isInfoEnabled()) {
log.info("Environment probe:" + System.lineSeparator() + probe);
} else { // the operator wants to show the information. Lets not also force them to enable INFO
log.warn("INFO logging is disabled. showing requested debug info as WARN instead");
log.warn("Environment probe:" + System.lineSeparator() + probe);
}
dumpPropertySources(probe);
section(probe, "\n===== How was it built ===========================");
dumpBuildProperties(probe);
section(probe, "\n===== How was it started =========================");
jarProbe.init(probe);
dumpStartupCommandJVMargs(probe);
section(probe, "\n===== What is running ============================");
dumpGitProperties(probe);
jarProbe.createRootManifestReport(probe);
jarProbe.createSnapshotJarReport(probe);
this.probeResult = probe;
} else {
probe = this.probeResult;
}
if (log.isInfoEnabled()) {
log.info("Environment probe:" + System.lineSeparator() + probe);
} else { // the operator wants to show the information. Lets not also force them to enable INFO
log.warn("INFO logging is disabled. showing requested debug info as WARN instead");
log.warn("Environment probe:" + System.lineSeparator() + probe);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public void dumpOShi() {
UpbannerSettings upbannerSettings = new UpbannerSettings();
upbannerSettings.setDebug(true);
FullOshiProbe fullOshiProbe = new FullOshiProbe();
fullOshiProbe.createReport(new StringBuilder());
StringBuilder probeOut = new StringBuilder();
fullOshiProbe.createReport(probeOut);
log.info("osh probe: " + probeOut);
}

@Test
Expand All @@ -55,15 +57,6 @@ public void dumpBuildProps() {
log.info(probeOut.toString());
}

@Test
public void dumpAll() {
Properties p = new Properties();
p.setProperty("time", "2020-12-08T00:52:19Z");
BuildProperties buildProperties = new BuildProperties(p);
WhatsUpProbes whatsUpProbes = new WhatsUpProbes(null,buildProperties,new FullOshiProbe(),new FileJarDumper(),new UpbannerSettings(), null);
whatsUpProbes.dumpAll();
}

@Test
public void showName() {
Properties p = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public void setUp() {
public void upbannerApplicationIsUP() {
assertTrue(outContent.toString().contains("WebJar1519ApplicationTests is UP!"));
}

@Test
public void upbannerDebugIsOff() {
assertFalse(outContent.toString().contains("Environment probe:"));
}
}
8 changes: 0 additions & 8 deletions webjaroverride/src/main/java/com/example/demo/MyWhatsUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public MyWhatsUp(WhatsUpProbes whatsUpProbes, Environment environment) {
this.environment = environment;
}

@PostConstruct
public void printDebugOnStartup() {
whatsUpProbes.dumpAll(stringBuilder -> stringBuilder
.append(" working directory: ")
.append(whatsUpProbes.getEnvironmentPropertyPrintable("PWD"))
.append(System.lineSeparator()));
}

@Override
public void printBanner() {
//compact banner
Expand Down

0 comments on commit 6ec53fc

Please sign in to comment.