diff --git a/prime-router/build.gradle.kts b/prime-router/build.gradle.kts index c07dbd0c501..65ca5665f3f 100644 --- a/prime-router/build.gradle.kts +++ b/prime-router/build.gradle.kts @@ -48,6 +48,16 @@ plugins { id("io.swagger.core.v3.swagger-gradle-plugin") version "2.2.23" } +// retrieve the current commit hash +val commitId by lazy { + val stdout = ByteArrayOutputStream() + exec { + commandLine("git", "rev-parse", "--short", "HEAD") + standardOutput = stdout + } + stdout.toString(StandardCharsets.UTF_8).trim() +} + group = "gov.cdc.prime.reportstream" version = "0.2-SNAPSHOT" description = "prime-router" @@ -261,6 +271,9 @@ sourceSets.create("testIntegration") { runtimeClasspath += sourceSets["main"].output } +// Add generated version object +sourceSets["main"].java.srcDir("$buildDir/generated-src/version") + val compileTestIntegrationKotlin: KotlinCompile by tasks compileTestIntegrationKotlin.kotlinOptions.jvmTarget = appJvmTarget @@ -340,6 +353,7 @@ tasks.withType().configureEach { } tasks.processResources { + dependsOn("generateVersionObject") // Set the proper build values in the build.properties file filesMatching("build.properties") { val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd") @@ -500,18 +514,32 @@ tasks.azureFunctionsPackage { finalizedBy("copyAzureScripts") } +// TODO: remove after implementation of health check endpoint tasks.register("generateVersionFile") { doLast { - val stdout = ByteArrayOutputStream() - exec { - commandLine("git", "rev-parse", "--short", "HEAD") - standardOutput = stdout - } - val currentCommit = stdout.toString(StandardCharsets.UTF_8).trim() - File(buildDir, "$azureFunctionsDir/$azureAppName/version.json").writeText("{\"commitId\": \"$currentCommit\"}") + file("$buildDir/$azureFunctionsDir/$azureAppName/version.json").writeText("{\"commitId\": \"$commitId\"}") } } +tasks.register("generateVersionObject") { + val sourceDir = file("$buildDir/generated-src/version") + val sourceFile = file("$sourceDir/Version.kt") + sourceDir.mkdirs() + sourceFile.writeText( + """ + package gov.cdc.prime.router.version + + /** + * Supplies information for the current build. + * This file is generated via Gradle task prior to compile time and should always contain the current commit hash. + */ + object Version { + const val commitId = "$commitId" + } + """.trimIndent() + ) +} + val azureResourcesTmpDir = File(buildDir, "$azureFunctionsDir-resources/$azureAppName") val azureResourcesFinalDir = File(buildDir, "$azureFunctionsDir/$azureAppName") tasks.register("gatherAzureResources") { diff --git a/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventData.kt b/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventData.kt index b527e8a1466..8529957dfba 100644 --- a/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventData.kt +++ b/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventData.kt @@ -27,6 +27,7 @@ data class ReportEventData( val blobUrl: String, val pipelineStepName: TaskAction, val timestamp: OffsetDateTime, + val commitId: String, ) /** diff --git a/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventService.kt b/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventService.kt index d8c37ac8ddb..42509ce0748 100644 --- a/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventService.kt +++ b/prime-router/src/main/kotlin/azure/observability/event/ReportStreamEventService.kt @@ -7,6 +7,7 @@ import gov.cdc.prime.router.azure.DatabaseAccess import gov.cdc.prime.router.azure.db.enums.TaskAction import gov.cdc.prime.router.azure.db.tables.pojos.ReportFile import gov.cdc.prime.router.report.ReportService +import gov.cdc.prime.router.version.Version import java.time.OffsetDateTime import java.util.UUID @@ -412,7 +413,8 @@ class ReportStreamEventService( topic, childBodyUrl, pipelineStepName, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ) } diff --git a/prime-router/src/test/kotlin/azure/ActionHistoryTests.kt b/prime-router/src/test/kotlin/azure/ActionHistoryTests.kt index 1d23f1c0356..bb53df0ae33 100644 --- a/prime-router/src/test/kotlin/azure/ActionHistoryTests.kt +++ b/prime-router/src/test/kotlin/azure/ActionHistoryTests.kt @@ -352,7 +352,8 @@ class ActionHistoryTests { Topic.TEST, "http://blobUrl", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + "" ) every { mockReportEventService.sendReportEvent(any(), any(), any(), any()) @@ -452,7 +453,8 @@ class ActionHistoryTests { Topic.TEST, "http://blobUrl", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + "" ) mockkObject(BlobAccess.Companion) mockkObject(BlobUtils) @@ -692,7 +694,8 @@ class ActionHistoryTests { Topic.TEST, "http://blobUrl", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + "" ) mockkObject(BlobAccess.Companion) mockkObject(BlobUtils) diff --git a/prime-router/src/test/kotlin/azure/observability/context/MDCUtilsTest.kt b/prime-router/src/test/kotlin/azure/observability/context/MDCUtilsTest.kt index 5c8cc249993..3d51e2ffac2 100644 --- a/prime-router/src/test/kotlin/azure/observability/context/MDCUtilsTest.kt +++ b/prime-router/src/test/kotlin/azure/observability/context/MDCUtilsTest.kt @@ -94,7 +94,8 @@ class MDCUtilsTest { Topic.FULL_ELR, "", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + "" ), mapOf( ReportStreamEventProperties.FILENAME to "filename" @@ -121,7 +122,8 @@ class MDCUtilsTest { Topic.FULL_ELR, "", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + "" ), ItemEventData( 1, diff --git a/prime-router/src/test/kotlin/azure/observability/event/ReportEventServiceTest.kt b/prime-router/src/test/kotlin/azure/observability/event/ReportEventServiceTest.kt index a625b6c6f55..526c409cc1b 100644 --- a/prime-router/src/test/kotlin/azure/observability/event/ReportEventServiceTest.kt +++ b/prime-router/src/test/kotlin/azure/observability/event/ReportEventServiceTest.kt @@ -12,6 +12,7 @@ import gov.cdc.prime.router.db.ReportStreamTestDatabaseContainer import gov.cdc.prime.router.db.ReportStreamTestDatabaseSetupExtension import gov.cdc.prime.router.history.db.ReportGraph import gov.cdc.prime.router.report.ReportService +import gov.cdc.prime.router.version.Version import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.testcontainers.junit.jupiter.Testcontainers @@ -93,7 +94,8 @@ class ReportEventServiceTest { Topic.FULL_ELR, "", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -136,7 +138,8 @@ class ReportEventServiceTest { Topic.FULL_ELR, "", TaskAction.send, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) diff --git a/prime-router/src/test/kotlin/fhirengine/azure/FHIRConverterIntegrationTests.kt b/prime-router/src/test/kotlin/fhirengine/azure/FHIRConverterIntegrationTests.kt index a7e9795e1cf..69b6dbe7182 100644 --- a/prime-router/src/test/kotlin/fhirengine/azure/FHIRConverterIntegrationTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/azure/FHIRConverterIntegrationTests.kt @@ -69,6 +69,7 @@ import gov.cdc.prime.router.history.DetailedActionLog import gov.cdc.prime.router.metadata.LookupTable import gov.cdc.prime.router.metadata.ObservationMappingConstants import gov.cdc.prime.router.unittest.UnitTestUtils +import gov.cdc.prime.router.version.Version import io.mockk.every import io.mockk.mockkConstructor import io.mockk.mockkObject @@ -357,7 +358,8 @@ class FHIRConverterIntegrationTests { Topic.FULL_ELR, routedReports[1].bodyUrl, TaskAction.convert, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -529,7 +531,8 @@ class FHIRConverterIntegrationTests { Topic.FULL_ELR, routedReports[1].bodyUrl, TaskAction.convert, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -664,7 +667,8 @@ class FHIRConverterIntegrationTests { Topic.MARS_OTC_ELR, "", TaskAction.convert, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) diff --git a/prime-router/src/test/kotlin/fhirengine/azure/FHIRDestinationFilterIntegrationTests.kt b/prime-router/src/test/kotlin/fhirengine/azure/FHIRDestinationFilterIntegrationTests.kt index 0d7aa55ebed..76d52f0b353 100644 --- a/prime-router/src/test/kotlin/fhirengine/azure/FHIRDestinationFilterIntegrationTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/azure/FHIRDestinationFilterIntegrationTests.kt @@ -47,6 +47,7 @@ import gov.cdc.prime.router.history.db.ReportGraph import gov.cdc.prime.router.metadata.LookupTable import gov.cdc.prime.router.report.ReportService import gov.cdc.prime.router.unittest.UnitTestUtils +import gov.cdc.prime.router.version.Version import io.mockk.every import io.mockk.mockkConstructor import io.mockk.mockkObject @@ -349,7 +350,8 @@ class FHIRDestinationFilterIntegrationTests : Logging { Topic.FULL_ELR, routedReport.bodyUrl, TaskAction.destination_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -450,7 +452,8 @@ class FHIRDestinationFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.destination_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ReportEventData::childReportId diff --git a/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverFilterIntegrationTests.kt b/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverFilterIntegrationTests.kt index 7580e6d67bb..6092e53516f 100644 --- a/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverFilterIntegrationTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverFilterIntegrationTests.kt @@ -56,6 +56,7 @@ import gov.cdc.prime.router.metadata.LookupTable import gov.cdc.prime.router.metadata.ObservationMappingConstants import gov.cdc.prime.router.report.ReportService import gov.cdc.prime.router.unittest.UnitTestUtils +import gov.cdc.prime.router.version.Version import io.mockk.every import io.mockk.mockkConstructor import io.mockk.mockkObject @@ -388,7 +389,8 @@ class FHIRReceiverFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.receiver_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) @@ -562,7 +564,8 @@ class FHIRReceiverFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.receiver_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) @@ -749,7 +752,8 @@ class FHIRReceiverFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.receiver_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) @@ -880,7 +884,8 @@ class FHIRReceiverFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.receiver_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) @@ -1163,7 +1168,8 @@ class FHIRReceiverFilterIntegrationTests : Logging { Topic.FULL_ELR, "", TaskAction.receiver_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) diff --git a/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverIntegrationTests.kt b/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverIntegrationTests.kt index 763a1f03a7b..df8c56b8e7b 100644 --- a/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverIntegrationTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/azure/FHIRReceiverIntegrationTests.kt @@ -42,6 +42,7 @@ import gov.cdc.prime.router.fhirengine.engine.FHIRReceiver import gov.cdc.prime.router.history.DetailedActionLog import gov.cdc.prime.router.history.DetailedReport import gov.cdc.prime.router.unittest.UnitTestUtils +import gov.cdc.prime.router.version.Version import io.mockk.clearAllMocks import io.mockk.every import io.mockk.mockkObject @@ -228,7 +229,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -254,7 +256,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -339,7 +342,8 @@ class FHIRReceiverIntegrationTests { null, submissionBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -441,7 +445,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -544,7 +549,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -649,7 +655,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -753,7 +760,8 @@ class FHIRReceiverIntegrationTests { Topic.FULL_ELR, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) @@ -854,7 +862,8 @@ class FHIRReceiverIntegrationTests { null, receiveBlobUrl, TaskAction.receive, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp ) diff --git a/prime-router/src/test/kotlin/fhirengine/engine/FhirDestinationFilterTests.kt b/prime-router/src/test/kotlin/fhirengine/engine/FhirDestinationFilterTests.kt index cac3f90e718..d6546d3eb8f 100644 --- a/prime-router/src/test/kotlin/fhirengine/engine/FhirDestinationFilterTests.kt +++ b/prime-router/src/test/kotlin/fhirengine/engine/FhirDestinationFilterTests.kt @@ -39,6 +39,7 @@ import gov.cdc.prime.router.azure.observability.event.TestSummary import gov.cdc.prime.router.metadata.LookupTable import gov.cdc.prime.router.report.ReportService import gov.cdc.prime.router.unittest.UnitTestUtils +import gov.cdc.prime.router.version.Version import io.mockk.clearAllMocks import io.mockk.every import io.mockk.mockk @@ -338,7 +339,8 @@ class FhirDestinationFilterTests { Topic.FULL_ELR, "test", TaskAction.destination_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp, ) @@ -502,7 +504,8 @@ class FhirDestinationFilterTests { Topic.FULL_ELR, "", TaskAction.destination_filter, - OffsetDateTime.now() + OffsetDateTime.now(), + Version.commitId ), ReportEventData::timestamp )