Skip to content

Commit

Permalink
feat(lapis): add siloVersion to response info (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer authored Jan 31, 2025
1 parent 44b6a33 commit c1edcf3
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Higher versions will also work if they are not specified in the table.

| LAPIS | SILO |
|--------|--------|
| 0.3.13 | 0.5.2 |
| 0.3.7 | 0.3.0 |
| 0.2.10 | 0.2.14 |
| 0.2.1 | 0.2.0 |
Expand Down
1 change: 1 addition & 0 deletions lapis-e2e/test/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('The info endpoind', () => {

expect(info.dataVersion).to.match(/\d+/);
expect(info.lapisVersion).to.be.not.empty;
expect(info.siloVersion).to.be.not.empty;
expect(info.requestId).to.be.not.empty;
expect(info.requestInfo).to.be.not.empty;
expect(info.reportTo).to.be.not.empty;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.genspectrum.lapis.config

import org.springframework.stereotype.Component

@Component
data class SiloVersion(var version: String? = null)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class InfoController(
lapisVersion = lapisVersion.version,
requestId = requestIdContext.requestId,
requestInfo = lapisInfoFactory.getRequestInfo(),
siloVersion = siloInfo.siloVersion,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ private fun infoResponseSchema() =
"requestInfo" to Schema<String>().type("string").description(REQUEST_INFO_STRING_DESCRIPTION),
"reportTo" to Schema<String>().type("string"),
"lapisVersion" to StringSchema().description(VERSION_DESCRIPTION),
"siloVersion" to StringSchema().description(SILO_VERSION_DESCRIPTION),
),
)
.required(listOf("reportTo"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const val REQUEST_INFO_STRING_DESCRIPTION =

const val VERSION_DESCRIPTION = "The version of LAPIS that processed the request."

const val SILO_VERSION_DESCRIPTION = "The version of SILO that processed the request."

const val DOWNLOAD_AS_FILE_DESCRIPTION =
"""
Set to true to make your browser trigger a download instead of showing the response content by setting the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.genspectrum.lapis.config.DatabaseConfig
import org.genspectrum.lapis.config.LapisVersion
import org.genspectrum.lapis.config.SiloVersion
import org.genspectrum.lapis.logging.RequestIdContext
import org.genspectrum.lapis.silo.DataVersion
import org.springframework.stereotype.Component
Expand All @@ -18,13 +19,15 @@ class LapisInfoFactory(
private val databaseConfig: DatabaseConfig,
private val lapisVersion: LapisVersion,
private val request: HttpServletRequest,
private val siloVersion: SiloVersion,
) {
fun create() =
LapisInfo(
dataVersion = dataVersion.dataVersion,
requestId = requestIdContext.requestId,
requestInfo = getRequestInfo(),
lapisVersion = lapisVersion.version,
siloVersion = siloVersion.version,
)

fun getRequestInfo() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.genspectrum.lapis.openApi.LAPIS_DATA_VERSION_RESPONSE_DESCRIPTION
import org.genspectrum.lapis.openApi.LAPIS_INFO_DESCRIPTION
import org.genspectrum.lapis.openApi.REQUEST_ID_HEADER_DESCRIPTION
import org.genspectrum.lapis.openApi.REQUEST_INFO_STRING_DESCRIPTION
import org.genspectrum.lapis.openApi.SILO_VERSION_DESCRIPTION
import org.genspectrum.lapis.openApi.VERSION_DESCRIPTION
import org.springframework.http.ProblemDetail

Expand Down Expand Up @@ -39,6 +40,11 @@ data class LapisInfo(
example = "1.2.3",
)
val lapisVersion: String? = null,
@Schema(
description = SILO_VERSION_DESCRIPTION,
example = "2.3.4",
)
val siloVersion: String? = null,
)

data class NucleotideMutationResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ data class SequenceData(

data class InfoData(
val dataVersion: String,
val siloVersion: String?,
)

@JsonComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.genspectrum.lapis.scheduler

import mu.KotlinLogging
import org.genspectrum.lapis.config.SiloVersion
import org.genspectrum.lapis.response.InfoData
import org.genspectrum.lapis.silo.CachedSiloClient
import org.genspectrum.lapis.silo.SILO_QUERY_CACHE_NAME
Expand All @@ -16,6 +17,7 @@ private val log = KotlinLogging.logger {}
class DataVersionCacheInvalidator(
private val cachedSiloClient: CachedSiloClient,
private val cacheClearer: CacheClearer,
private val siloVersion: SiloVersion,
) {
private var currentlyCachedDataVersion = "uninitialized"

Expand All @@ -30,6 +32,7 @@ class DataVersionCacheInvalidator(
log.debug { "Caught ${SiloUnavailableException::class.java} $e" }
InfoData(
dataVersion = "currently unavailable",
siloVersion = null,
)
} catch (e: Exception) {
log.debug { "Failed to call info: $e" }
Expand All @@ -42,6 +45,7 @@ class DataVersionCacheInvalidator(
}
cacheClearer.clearCache()
currentlyCachedDataVersion = info.dataVersion
siloVersion.version = info.siloVersion
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ open class CachedSiloClient(
fun callInfo(): InfoData {
val response = send(siloUris.info, BodyHandlers.ofString(), ::tryToReadSiloErrorFromString) { it.GET() }

return InfoData(getDataVersion(response))
return InfoData(
dataVersion = getDataVersion(response),
siloVersion = objectMapper.readValue<SiloInfo>(response.body()).version,
)
}

private fun <ResponseBodyType> send(
Expand Down Expand Up @@ -186,3 +189,7 @@ data class WithDataVersion<ResponseType>(
)

data class SiloErrorResponse(val error: String, val message: String)

data class SiloInfo(
val version: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ class InfoControllerTest(
fun `GET info`() {
every {
siloQueryModelMock.getInfo()
} returns InfoData("1234")
} returns InfoData(
dataVersion = "1234",
siloVersion = "1.2.3",
)

mockMvc.perform(getSample(INFO_ROUTE))
.andExpect(status().isOk)
.andExpect(jsonPath("\$.dataVersion").value("1234"))
.andExpect(jsonPath("\$.lapisVersion").value(matchesPattern(".+")))
.andExpect(jsonPath("\$.siloVersion").value(matchesPattern("1.2.3")))
}

@Test
Expand Down
42 changes: 37 additions & 5 deletions lapis/src/test/kotlin/org/genspectrum/lapis/silo/SiloClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.genspectrum.lapis.silo
import com.fasterxml.jackson.databind.node.DoubleNode
import com.fasterxml.jackson.databind.node.IntNode
import com.fasterxml.jackson.databind.node.TextNode
import org.genspectrum.lapis.config.SiloVersion
import org.genspectrum.lapis.logging.RequestIdContext
import org.genspectrum.lapis.request.Order
import org.genspectrum.lapis.request.OrderByField
Expand Down Expand Up @@ -380,7 +381,10 @@ class SiloClientTest(
@Test
fun `GIVEN an action that should be cached WHEN I send request twice THEN data version is populated`() {
val dataVersionValue = "someDataVersion"
expectInfoCallAndReturnDataVersion(dataVersionValue)
expectInfoCallAndReturnDataVersion(
dataVersion = dataVersionValue,
siloVersion = "1.2.3",
)

expectQueryRequestAndRespondWith(
response()
Expand Down Expand Up @@ -468,6 +472,7 @@ class SiloClientAndCacheInvalidatorTest(
@Autowired private val dataVersionCacheInvalidator: DataVersionCacheInvalidator,
@Autowired private val requestIdContext: RequestIdContext,
@Autowired private val dataVersion: DataVersion,
@Autowired private val siloVersion: SiloVersion,
) {
private lateinit var mockServer: ClientAndServer

Expand All @@ -488,20 +493,34 @@ class SiloClientAndCacheInvalidatorTest(

@Test
fun `GIVEN there is a new data version WHEN the cache invalidator checks THEN the cache should be cleared`() {
expectInfoCallAndReturnDataVersion(firstDataVersion, Times.once())
expectInfoCallAndReturnDataVersion(
dataVersion = firstDataVersion,
siloVersion = "1.2.3",
times = Times.once(),
)
dataVersionCacheInvalidator.invalidateSiloCache()

assertThatResultIsCachedOnSecondRequest()
assertThat(siloVersion.version, `is`("1.2.3"))

expectInfoCallAndReturnDataVersion(secondDataVersion, Times.once())
expectInfoCallAndReturnDataVersion(
dataVersion = secondDataVersion,
siloVersion = "2.3.4",
times = Times.once(),
)
dataVersionCacheInvalidator.invalidateSiloCache()

assertThatCacheIsNotHit()
assertThat(siloVersion.version, `is`("2.3.4"))
}

@Test
fun `GIVEN SILO is restarting WHEN the cache invalidator checks THEN the cache should be cleared`() {
expectInfoCallAndReturnDataVersion(firstDataVersion, Times.once())
expectInfoCallAndReturnDataVersion(
dataVersion = firstDataVersion,
siloVersion = "1.2.3",
times = Times.once(),
)
dataVersionCacheInvalidator.invalidateSiloCache()

assertThatResultIsCachedOnSecondRequest()
Expand All @@ -510,6 +529,7 @@ class SiloClientAndCacheInvalidatorTest(
dataVersionCacheInvalidator.invalidateSiloCache()

assertThatCacheIsNotHit()
assertThat(siloVersion.version, `is`(nullValue()))
}

private fun assertThatResultIsCachedOnSecondRequest() {
Expand Down Expand Up @@ -574,6 +594,7 @@ private fun expectQueryRequestAndRespondWith(

private fun expectInfoCallAndReturnDataVersion(
dataVersion: String,
siloVersion: String,
times: Times = Times.unlimited(),
) {
MockServerClient("localhost", MOCK_SERVER_PORT)
Expand All @@ -583,5 +604,16 @@ private fun expectInfoCallAndReturnDataVersion(
.withPath("/info"),
times,
)
.respond(response().withStatusCode(200).withHeader(DATA_VERSION_HEADER, dataVersion))
.respond(
response()
.withStatusCode(200)
.withHeader(DATA_VERSION_HEADER, dataVersion)
.withBody(
"""
{
"version": "$siloVersion"
}
""".trimIndent(),
),
)
}

0 comments on commit c1edcf3

Please sign in to comment.