Skip to content

Commit

Permalink
implement generated version object and add to azure report event
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-h-wang committed Sep 19, 2024
1 parent 830b245 commit d3579b8
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 30 deletions.
28 changes: 26 additions & 2 deletions prime-router/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ plugins {
id("io.swagger.core.v3.swagger-gradle-plugin") version "2.2.22"
}

// retrieve the current commit hash
val commitId by lazy {
val stdout = ByteArrayOutputStream()
exec {
Expand All @@ -58,7 +59,7 @@ val commitId by lazy {
}

group = "gov.cdc.prime.reportstream"
version = "0.2-SNAPSHOT-$commitId"
version = "0.2-SNAPSHOT"
description = "prime-router"
val azureAppName = "prime-data-hub-router"
val azureFunctionsDir = "azure-functions"
Expand Down Expand Up @@ -270,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

Expand Down Expand Up @@ -349,6 +353,7 @@ tasks.withType<Test>().configureEach {
}

tasks.processResources {
dependsOn("generateVersionObject")
// Set the proper build values in the build.properties file
filesMatching("build.properties") {
val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd")
Expand Down Expand Up @@ -511,10 +516,29 @@ tasks.azureFunctionsPackage {

tasks.register("generateVersionFile") {
doLast {
File(buildDir, "$azureFunctionsDir/$azureAppName/version.json").writeText("{\"commitId\": \"$commitId\"}")
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<Copy>("gatherAzureResources") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class ReportEventData(
val blobUrl: String,
val pipelineStepName: TaskAction,
val timestamp: OffsetDateTime,
val commitId: String,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -412,7 +413,8 @@ class ReportStreamEventService(
topic,
childBodyUrl,
pipelineStepName,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
)
}

Expand Down
9 changes: 6 additions & 3 deletions prime-router/src/test/kotlin/azure/ActionHistoryTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ class ActionHistoryTests {
Topic.TEST,
"http://blobUrl",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
""
)
every {
mockReportEventService.sendReportEvent(any(), any<ReportFile>(), any(), any())
Expand Down Expand Up @@ -452,7 +453,8 @@ class ActionHistoryTests {
Topic.TEST,
"http://blobUrl",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
""
)
mockkObject(BlobAccess.Companion)
mockkObject(BlobUtils)
Expand Down Expand Up @@ -692,7 +694,8 @@ class ActionHistoryTests {
Topic.TEST,
"http://blobUrl",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
""
)
mockkObject(BlobAccess.Companion)
mockkObject(BlobUtils)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class MDCUtilsTest {
Topic.FULL_ELR,
"",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
""
),
mapOf(
ReportStreamEventProperties.FILENAME to "filename"
Expand All @@ -121,7 +122,8 @@ class MDCUtilsTest {
Topic.FULL_ELR,
"",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
""
),
ItemEventData(
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +94,8 @@ class ReportEventServiceTest {
Topic.FULL_ELR,
"",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -136,7 +138,8 @@ class ReportEventServiceTest {
Topic.FULL_ELR,
"",
TaskAction.send,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -357,7 +358,8 @@ class FHIRConverterIntegrationTests {
Topic.FULL_ELR,
routedReports[1].bodyUrl,
TaskAction.convert,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -529,7 +531,8 @@ class FHIRConverterIntegrationTests {
Topic.FULL_ELR,
routedReports[1].bodyUrl,
TaskAction.convert,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -664,7 +667,8 @@ class FHIRConverterIntegrationTests {
Topic.MARS_OTC_ELR,
"",
TaskAction.convert,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -349,7 +350,8 @@ class FHIRDestinationFilterIntegrationTests : Logging {
Topic.FULL_ELR,
routedReport.bodyUrl,
TaskAction.destination_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -450,7 +452,8 @@ class FHIRDestinationFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.destination_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
ReportEventData::childReportId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -388,7 +389,8 @@ class FHIRReceiverFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.receiver_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
)
Expand Down Expand Up @@ -562,7 +564,8 @@ class FHIRReceiverFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.receiver_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
)
Expand Down Expand Up @@ -749,7 +752,8 @@ class FHIRReceiverFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.receiver_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
)
Expand Down Expand Up @@ -880,7 +884,8 @@ class FHIRReceiverFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.receiver_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
)
Expand Down Expand Up @@ -1163,7 +1168,8 @@ class FHIRReceiverFilterIntegrationTests : Logging {
Topic.FULL_ELR,
"",
TaskAction.receiver_filter,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -228,7 +229,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand All @@ -254,7 +256,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -339,7 +342,8 @@ class FHIRReceiverIntegrationTests {
null,
submissionBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -441,7 +445,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -544,7 +549,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -649,7 +655,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -753,7 +760,8 @@ class FHIRReceiverIntegrationTests {
Topic.FULL_ELR,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down Expand Up @@ -854,7 +862,8 @@ class FHIRReceiverIntegrationTests {
null,
receiveBlobUrl,
TaskAction.receive,
OffsetDateTime.now()
OffsetDateTime.now(),
Version.commitId
),
ReportEventData::timestamp
)
Expand Down
Loading

0 comments on commit d3579b8

Please sign in to comment.