Improve version logging (#2213)

* Improve version logging

* Add changelog

* Test fixes
This commit is contained in:
James Agnew 2020-12-02 21:19:04 -05:00 committed by GitHub
parent b11f97d9ef
commit 7627a86176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 9 deletions

View File

@ -37,11 +37,16 @@ public class VersionUtil {
private static String ourVersion;
private static String ourBuildNumber;
private static String ourBuildTime;
private static boolean ourSnapshot;
static {
initialize();
}
public static boolean isSnapshot() {
return ourSnapshot;
}
public static String getBuildNumber() {
return ourBuildNumber;
}
@ -65,11 +70,18 @@ public class VersionUtil {
ourVersion = p.getProperty("hapifhir.version");
ourVersion = defaultIfBlank(ourVersion, "(unknown)");
ourBuildNumber = p.getProperty("hapifhir.buildnumber");
ourSnapshot = ourVersion.contains("SNAPSHOT");
ourBuildNumber = StringUtils.left(p.getProperty("hapifhir.buildnumber"), 10);
ourBuildTime = p.getProperty("hapifhir.timestamp");
if (System.getProperty("suppress_hapi_fhir_version_log") == null) {
ourLog.info("HAPI FHIR version {} - Rev {}", ourVersion, StringUtils.right(ourBuildNumber, 10));
String buildNumber = ourBuildNumber;
if (isSnapshot()) {
buildNumber = buildNumber + "/" + getBuildDate();
}
ourLog.info("HAPI FHIR version {} - Rev {}", ourVersion, buildNumber);
}
} catch (Exception e) {
@ -77,4 +89,8 @@ public class VersionUtil {
}
}
public static String getBuildDate() {
return ourBuildTime.substring(0, 10);
}
}

View File

@ -0,0 +1,6 @@
---
type: add
issue: 2213
title: "Non release (i.e. SNAPSHOT) builds of HAPI FHIR will now include the Git revision hash as well as the build date in the
version string that is logged on initialization, and included in the default server X-Powered-By string. Release builds are
not affected by this change."

View File

@ -299,7 +299,11 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
* @see #createPoweredByHeader()
*/
protected String createPoweredByHeaderProductVersion() {
return VersionUtil.getVersion();
String version = VersionUtil.getVersion();
if (VersionUtil.isSnapshot()) {
version = version + "/" + VersionUtil.getBuildNumber() + "/" + VersionUtil.getBuildDate();
}
return version;
}
@Override

View File

@ -110,7 +110,8 @@ public class MetadataConformanceDstu2_1Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<Conformance"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU2_1.getFhirVersionString() + "/DSTU2_1)", status.getFirstHeader("X-Powered-By").getValue());
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("HAPI FHIR " + VersionUtil.getVersion()));
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")"));
} finally {
IOUtils.closeQuietly(status.getEntity().getContent());
}
@ -120,7 +121,7 @@ public class MetadataConformanceDstu2_1Test {
status = ourClient.execute(httpPost);
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(405, status.getStatusLine().getStatusCode());
assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"/metadata request must use HTTP GET\"/></issue></OperationOutcome>", output);
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")"));
} finally {
IOUtils.closeQuietly(status.getEntity().getContent());
}

View File

@ -86,8 +86,8 @@ public class MetadataCapabilityStatementDstu3Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<CapabilityStatement"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3)",
status.getFirstHeader("X-Powered-By").getValue());
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("HAPI FHIR " + VersionUtil.getVersion()));
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")"));
} finally {
IOUtils.closeQuietly(status.getEntity().getContent());
}

View File

@ -108,7 +108,8 @@ public class MetadataConformanceDstu3Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<CapabilityStatement"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3)", status.getFirstHeader("X-Powered-By").getValue());
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("HAPI FHIR " + VersionUtil.getVersion()));
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")"));
}
httpOperation = new HttpOptions("http://localhost:" + ourPort);
@ -116,7 +117,8 @@ public class MetadataConformanceDstu3Test {
output = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(output, containsString("<CapabilityStatement"));
assertEquals("HAPI FHIR " + VersionUtil.getVersion() + " REST Server (FHIR Server; FHIR " + FhirVersionEnum.DSTU3.getFhirVersionString() + "/DSTU3)", status.getFirstHeader("X-Powered-By").getValue());
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("HAPI FHIR " + VersionUtil.getVersion()));
assertThat(status.getFirstHeader("X-Powered-By").getValue(), containsString("REST Server (FHIR Server; FHIR " + ourCtx.getVersion().getVersion().getFhirVersionString() + "/" + ourCtx.getVersion().getVersion().name() + ")"));
}
httpOperation = new HttpPost("http://localhost:" + ourPort + "/metadata");