diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala index 6eb2c23355..626e30a0a2 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala @@ -484,17 +484,11 @@ final case class SearchResponderV2Live( prequerySparql = transformedPrequery.toSparql - start <- Clock.instant.map(_.toEpochMilli) prequeryResponseNotMerged <- triplestore .query(Select(prequerySparql, isGravsearch = true)) .logError(s"Gravsearch timed out for prequery:\n$prequerySparql") - end <- Clock.instant.map(_.toEpochMilli) - duration = (end - start) / 1000.0 - _ = if (duration < 3) logger.debug(s"Prequery took: ${duration}s") - else logger.warn(s"Slow Prequery ($duration):\n$prequerySparql") - pageSizeBeforeFiltering: Int = prequeryResponseNotMerged.results.bindings.size // Merge rows with the same main resource IRI. This could happen if there are unbound variables in a UNION. diff --git a/webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala b/webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala index 4e691ac527..3960106178 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala @@ -5,11 +5,10 @@ package org.knora.webapi.routing.v2 -import org.apache.pekko +import org.apache.pekko.http.scaladsl.server.Directives.* +import org.apache.pekko.http.scaladsl.server.RequestContext +import org.apache.pekko.http.scaladsl.server.Route import zio.* -import zio.metrics.* - -import java.time.temporal.ChronoUnit import dsp.errors.BadRequestException import dsp.valueobjects.Iri @@ -25,11 +24,6 @@ import org.knora.webapi.messages.v2.responder.searchmessages.* import org.knora.webapi.routing.Authenticator import org.knora.webapi.routing.RouteUtilV2 import org.knora.webapi.slice.resourceinfo.domain.IriConverter -import org.knora.webapi.store.triplestore.errors.TriplestoreTimeoutException - -import pekko.http.scaladsl.server.Directives.* -import pekko.http.scaladsl.server.RequestContext -import pekko.http.scaladsl.server.Route /** * Provides a function for API routes that deal with search. @@ -242,27 +236,16 @@ final case class SearchRouteV2(searchValueMinLength: Int)( post(entity(as[String])(query => requestContext => gravsearch(query, requestContext))) } - private val gravsearchDuration = Metric.timer("gravsearch", ChronoUnit.MILLIS, Chunk.iterate(1.0, 17)(_ * 2)) - private val gravsearchDurationSummary = - Metric.summary("gravsearch_summary", 1.day, 100, 0.03d, Chunk(0.01, 0.1, 0.2, 0.5, 0.8, 0.9, 0.99)) - private val gravsearchFailCounter = Metric.counter("gravsearch_fail").fromConst(1) - private val gravsearchTimeoutCounter = Metric.counter("gravsearch_timeout").fromConst(1) - private def gravsearch(query: String, requestContext: RequestContext) = { val constructQuery = GravsearchParser.parseQuery(query) val targetSchemaTask = RouteUtilV2.getOntologySchema(requestContext) val schemaOptionsTask = RouteUtilV2.getSchemaOptions(requestContext) val task = for { - start <- Clock.instant.map(_.toEpochMilli).map(_.toDouble) targetSchema <- targetSchemaTask requestingUser <- Authenticator.getUserADM(requestContext) schemaOptions <- schemaOptionsTask - request = GravsearchRequestV2(constructQuery, targetSchema, schemaOptions, requestingUser) - response <- MessageRelay.ask[KnoraResponseV2](request).tapError { - case _: TriplestoreTimeoutException => ZIO.unit @@ gravsearchTimeoutCounter - case _ => ZIO.unit @@ gravsearchFailCounter - } @@ gravsearchDuration.trackDuration - _ <- Clock.instant.map(_.toEpochMilli).map(_.-(start)) @@ gravsearchDurationSummary + gravsearchReq = GravsearchRequestV2(constructQuery, targetSchema, schemaOptions, requestingUser) + response <- MessageRelay.ask[KnoraResponseV2](gravsearchReq) } yield response RouteUtilV2.completeResponse(task, requestContext, targetSchemaTask, schemaOptionsTask.map(Some(_))) }