Skip to content

Commit

Permalink
Query endpoint now measures and logs time needed to execute a query.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Gasser committed Jan 13, 2024
1 parent 9d0e892 commit 8e80c17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ subprojects {
implementation group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: version_caffeine

/* Logging */
implementation group: 'io.github.oshai', name: 'kotlin-logging-jvm', version: version_kotlinlogging
implementation group: 'org.slf4j', name: 'slf4j-api', version: version_slf4j
implementation group: 'io.github.oshai', name: 'kotlin-logging-jvm', version: version_kotlinlogging
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: version_log4j2
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: version_log4j2
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl', version: version_log4j2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fun configureApiRoutes(config: ApiConfig, manager: SchemaManager, retrievalRunti
path("{exporter}") {
path("{retrievable}") {
post { ctx ->

fetchExportData(ctx, schema)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.vitrivr.engine.server.api.rest.handlers

import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import io.javalin.http.Context
import io.javalin.http.bodyAsClass
import io.javalin.openapi.*
Expand All @@ -9,12 +11,10 @@ import org.vitrivr.engine.query.model.api.InformationNeedDescription
import org.vitrivr.engine.query.model.api.result.QueryResult
import org.vitrivr.engine.server.api.rest.model.ErrorStatus
import org.vitrivr.engine.server.api.rest.model.ErrorStatusException
import kotlin.time.measureTime

private val logger: KLogger = KotlinLogging.logger {}

/**
*
* @author Ralph Gasser
* @version 1.0
*/
@OpenApi(
path = "/api/{schema}/query",
methods = [HttpMethod.POST],
Expand All @@ -31,11 +31,14 @@ import org.vitrivr.engine.server.api.rest.model.ErrorStatusException
]
)
fun executeQuery(ctx: Context, schema: Schema, runtime: RetrievalRuntime) {
val informationNeed = try {
ctx.bodyAsClass<InformationNeedDescription>()
} catch (e: Exception) {
throw ErrorStatusException(400, "Invalid request: ${e.message}")
val duration = measureTime {
val informationNeed = try {
ctx.bodyAsClass<InformationNeedDescription>()
} catch (e: Exception) {
throw ErrorStatusException(400, "Invalid request: ${e.message}")
}
val results = runtime.query(schema, informationNeed)
ctx.json(QueryResult(results))
}
val results = runtime.query(schema, informationNeed)
ctx.json(QueryResult(results))
logger.info { "Executing ${ctx.req().pathInfo} took $duration." }
}

0 comments on commit 8e80c17

Please sign in to comment.