Skip to content

Commit

Permalink
feat: log whether request was cached #717
Browse files Browse the repository at this point in the history
and reduce logging noise from data version checker
  • Loading branch information
fengelniederhammer committed Apr 3, 2024
1 parent af38e93 commit 20cfe15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class LapisSpringConfig {
filter.setIncludePayload(true)
filter.setMaxPayloadLength(10000)
filter.setIncludeHeaders(false)
filter.setAfterMessagePrefix("REQUEST DATA: ")
return filter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RequestContext {
var endpoint: String? = null
var filter: CommonSequenceFilters? = null
var responseCode: Int? = null
var cached: Boolean? = null
}

private val log = KotlinLogging.logger {}
Expand Down
20 changes: 17 additions & 3 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/silo/SiloClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import mu.KotlinLogging
import org.genspectrum.lapis.controller.LapisHeaders.REQUEST_ID
import org.genspectrum.lapis.logging.RequestContext
import org.genspectrum.lapis.logging.RequestIdContext
import org.genspectrum.lapis.response.InfoData
import org.springframework.beans.factory.annotation.Value
Expand All @@ -27,14 +28,22 @@ const val SILO_RESPONSE_MAX_LOG_LENGTH = 10_000
class SiloClient(
private val cachedSiloClient: CachedSiloClient,
private val dataVersion: DataVersion,
private val requestContext: RequestContext,
) {
fun <ResponseType> sendQuery(query: SiloQuery<ResponseType>): ResponseType {
val result = cachedSiloClient.sendQuery(query)
dataVersion.dataVersion = result.dataVersion

if (RequestContextHolder.getRequestAttributes() != null && requestContext.cached == null) {
requestContext.cached = true
}

return result.queryResult
}

fun callInfo(): InfoData {
log.info { "Calling SILO info" }

val info = cachedSiloClient.callInfo()
dataVersion.dataVersion = info.dataVersion
return info
Expand All @@ -48,11 +57,16 @@ class CachedSiloClient(
@Value("\${silo.url}") private val siloUrl: String,
private val objectMapper: ObjectMapper,
private val requestIdContext: RequestIdContext,
private val requestContext: RequestContext,
) {
private val httpClient = HttpClient.newHttpClient()

@Cacheable(SILO_QUERY_CACHE_NAME, condition = "#query.action.cacheable && !#query.action.randomize")
fun <ResponseType> sendQuery(query: SiloQuery<ResponseType>): WithDataVersion<ResponseType> {
if (RequestContextHolder.getRequestAttributes() != null) {
requestContext.cached = false
}

val queryJson = objectMapper.writeValueAsString(query)

log.info { "Calling SILO: $queryJson" }
Expand All @@ -74,8 +88,6 @@ class CachedSiloClient(
}

fun callInfo(): InfoData {
log.info { "Calling SILO info" }

val response = send(URI("$siloUrl/info")) { it.GET() }

return InfoData(getDataVersion(response))
Expand All @@ -101,7 +113,9 @@ class CachedSiloClient(
throw RuntimeException(message, exception)
}

log.info { "Response from SILO: ${response.statusCode()}" }
if (!uri.toString().endsWith("info")) {
log.info { "Response from SILO: ${response.statusCode()}" }
}
log.debug {
val body = response.body()
val truncationPostfix = when {
Expand Down

0 comments on commit 20cfe15

Please sign in to comment.