Skip to content

Commit

Permalink
feat: include link to GitHub issues in LapisInfo #692
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Apr 4, 2024
1 parent 1acedad commit ea42ac2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ playground/

docker-compose.override.yml

log
log/
logs/
3 changes: 2 additions & 1 deletion lapis2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build/
!**/src/test/**/build/
/lapis-v2-openapi.json
/lapis-v2-openapi-protected.json
log
log/
logs/
1 change: 1 addition & 0 deletions lapis2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation 'org.apache.commons:commons-csv:1.10.0'
implementation 'com.github.luben:zstd-jni:1.5.6-1'
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0"

testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: "org.mockito"
Expand Down
41 changes: 36 additions & 5 deletions lapis2/src/main/kotlin/org/genspectrum/lapis/request/LapisInfo.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.genspectrum.lapis.request

import io.swagger.v3.oas.annotations.media.Schema
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.genspectrum.lapis.config.DatabaseConfig
import org.genspectrum.lapis.controller.LapisErrorResponse
import org.genspectrum.lapis.controller.LapisHeaders.LAPIS_DATA_VERSION
import org.genspectrum.lapis.controller.LapisResponse
Expand All @@ -19,20 +23,36 @@ import org.springframework.http.server.ServerHttpResponse
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice

private const val REPORT_TO =
"Please report to https://github.com/GenSpectrum/LAPIS/issues in case you encounter any unexpected issues. " +
"Please include the request ID and the requestInfo in your report."

@Schema(description = LAPIS_INFO_DESCRIPTION)
data class LapisInfo(
@Schema(
description = LAPIS_DATA_VERSION_RESPONSE_DESCRIPTION,
example = LAPIS_DATA_VERSION_EXAMPLE,
) var dataVersion: String? = null,
@Schema(description = REQUEST_ID_HEADER_DESCRIPTION)
)
var dataVersion: String? = null,
@Schema(
description = REQUEST_ID_HEADER_DESCRIPTION,
example = "dfb342ea-3607-4caf-b35e-9aba75d06f81",
)
var requestId: String? = null,
@Schema(
description = "Some information about the request in human readable form. Intended for debugging.",
example = "my_instance on my.server.com at 2024-01-01T12:00:00.0000",
)
var requestInfo: String? = null,
@Schema(example = REPORT_TO)
val reportTo: String = REPORT_TO,
)

@ControllerAdvice
class ResponseBodyAdviceDataVersion(
private val dataVersion: DataVersion,
private val requestIdContext: RequestIdContext,
private val databaseConfig: DatabaseConfig,
) : ResponseBodyAdvice<Any> {
override fun beforeBodyWrite(
body: Any?,
Expand All @@ -46,15 +66,26 @@ class ResponseBodyAdviceDataVersion(

val isDownload = response.headers.getFirst(HttpHeaders.CONTENT_DISPOSITION)?.startsWith("attachment") ?: false

request.uri.host

return when {
body is LapisResponse<*> && isDownload -> body.data
body is LapisResponse<*> -> LapisResponse(body.data, getLapisInfo())
body is LapisErrorResponse -> LapisErrorResponse(body.error, getLapisInfo())
body is LapisResponse<*> -> LapisResponse(body.data, getLapisInfo(request))
body is LapisErrorResponse -> LapisErrorResponse(body.error, getLapisInfo(request))
else -> body
}
}

private fun getLapisInfo() = LapisInfo(dataVersion.dataVersion, requestIdContext.requestId)
private fun getLapisInfo(request: ServerHttpRequest) =
LapisInfo(
dataVersion = dataVersion.dataVersion,
requestId = requestIdContext.requestId,
requestInfo = "${databaseConfig.schema.instanceName} on ${request.uri.host} at ${now()}",
)

private fun now(): String {
return Clock.System.now().toLocalDateTime(TimeZone.UTC).toString()
}

override fun supports(
returnType: MethodParameter,
Expand Down

0 comments on commit ea42ac2

Please sign in to comment.