Skip to content

Commit

Permalink
chore: Remove duplicate 'gravsearch' metrics (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Nov 15, 2023
1 parent 224eb3d commit f11dfef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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(_)))
}
Expand Down

0 comments on commit f11dfef

Please sign in to comment.