From b6e8581609a9e172b72d0fb9477307d43f81c44e Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 11 Sep 2023 17:14:04 +0200 Subject: [PATCH] Reduce log level when querying aggregate views (#4263) Co-authored-by: Simon Dumas --- .../blazegraph/BlazegraphViewsQuery.scala | 2 - .../ElasticSearchViewsQuery.scala | 2 - .../nexus/delta/sdk/views/ViewsStore.scala | 60 +++++-------------- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphViewsQuery.scala b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphViewsQuery.scala index 4cfff1f640..1618e2bd42 100644 --- a/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphViewsQuery.scala +++ b/delta/plugins/blazegraph/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/blazegraph/BlazegraphViewsQuery.scala @@ -105,9 +105,7 @@ object BlazegraphViewsQuery { outgoingWithExternalQuery <- ioContentOf("blazegraph/outgoing_include_external.txt") outgoingScopedQuery <- ioContentOf("blazegraph/outgoing_scoped.txt") viewsStore = ViewsStore[BlazegraphViewRejection, BlazegraphViewState]( - BlazegraphViews.entityType, BlazegraphViewState.serializer, - defaultViewId, views.fetchState, view => IO.raiseWhen(view.deprecated)(ViewIsDeprecated(view.id)).as { diff --git a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewsQuery.scala b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewsQuery.scala index ed47f021de..be2ae2c971 100644 --- a/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewsQuery.scala +++ b/delta/plugins/elasticsearch/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/elasticsearch/ElasticSearchViewsQuery.scala @@ -138,9 +138,7 @@ object ElasticSearchViewsQuery { ): ElasticSearchViewsQuery = new ElasticSearchViewsQueryImpl( ViewsStore[ElasticSearchViewRejection, ElasticSearchViewState]( - ElasticSearchViews.entityType, ElasticSearchViewState.serializer, - defaultViewId, views.fetchState(_, _), view => IO.raiseWhen(view.deprecated)(ViewIsDeprecated(view.id)).as { diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/views/ViewsStore.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/views/ViewsStore.scala index 553b935260..806a892042 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/views/ViewsStore.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/views/ViewsStore.scala @@ -1,17 +1,13 @@ package ch.epfl.bluebrain.nexus.delta.sdk.views import cats.syntax.all._ -import ch.epfl.bluebrain.nexus.delta.kernel.kamon.KamonMetricComponent +import ch.epfl.bluebrain.nexus.delta.kernel.Logger import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri -import ch.epfl.bluebrain.nexus.delta.sdk.implicits._ import ch.epfl.bluebrain.nexus.delta.sdk.model.IdSegmentRef import ch.epfl.bluebrain.nexus.delta.sdk.views.View.{AggregateView, IndexingView} -import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, ProjectRef, Tag} -import ch.epfl.bluebrain.nexus.delta.sourcing.{EntityDependencyStore, Scope, Serializer, Transactors} -import com.typesafe.scalalogging.Logger -import doobie._ -import doobie.implicits._ -import io.circe.{Decoder, Json} +import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef +import ch.epfl.bluebrain.nexus.delta.sourcing.{EntityDependencyStore, Serializer, Transactors} +import io.circe.Decoder import monix.bio.{IO, UIO} trait ViewsStore[Rejection] { @@ -26,14 +22,6 @@ trait ViewsStore[Rejection] { */ def fetch(id: IdSegmentRef, project: ProjectRef): IO[Rejection, View] - /** - * Fetch default views and combine them in an aggregate view - * @param scope - * to get all default view from the system / a given organization / a given project - * @return - */ - def fetchDefaultViews(scope: Scope): UIO[AggregateView] - } object ViewsStore { @@ -43,53 +31,35 @@ object ViewsStore { import ch.epfl.bluebrain.nexus.delta.sourcing.implicits._ def apply[Rejection, Value]( - entityType: EntityType, serializer: Serializer[Iri, Value], - defaultViewId: Iri, fetchValue: (IdSegmentRef, ProjectRef) => IO[Rejection, Value], asView: Value => IO[Rejection, Either[Iri, IndexingView]], xas: Transactors ): ViewsStore[Rejection] = new ViewsStore[Rejection] { - implicit private val kamonComponent: KamonMetricComponent = KamonMetricComponent(s"${entityType.value}ViewsStore") - implicit val stateDecoder: Decoder[Value] = serializer.codec // For embedded views in aggregate view drop intermediate aggregate view and those who raise an error - private def embeddedView(value: Value): UIO[Option[IndexingView]] = asView(value).redeemWith( - rejection => UIO.delay(logger.info(s"View '$value' is skipped because of '$rejection'.")) >> UIO.none, - v => - UIO.delay(logger.debug(s"View '$value' is skipped because it is an intermediate aggregate view.")) >> UIO.pure( - v.toOption - ) - ) + private def embeddedView(project: ProjectRef, id: Iri, value: Value): UIO[Option[IndexingView]] = + asView(value).redeemWith( + rejection => logger.debug(s"View '$id' in project '$project' is skipped because of '$rejection'.") >> UIO.none, + v => + logger.debug( + s"View '$id' in project '$project' is skipped because it is an intermediate aggregate view." + ) >> UIO.pure( + v.toOption + ) + ) override def fetch(id: IdSegmentRef, project: ProjectRef): IO[Rejection, View] = for { res <- fetchValue(id, project).flatMap(asView) singleOrMultiple <- IO.fromEither(res).widen[View].onErrorHandleWith { iri => EntityDependencyStore.decodeRecursiveDependencies[Iri, Value](project, iri, xas).flatMap { - _.traverseFilter(embeddedView).map(AggregateView(_)) + _.traverseFilter(embeddedView(project, iri, _)).map(AggregateView(_)) } } } yield singleOrMultiple - override def fetchDefaultViews(scope: Scope): UIO[AggregateView] = { - (fr"SELECT value FROM scoped_states" ++ - Fragments.whereAndOpt( - Some(fr"type = $entityType"), - scope.asFragment, - Some(fr"tag = ${Tag.Latest.value}"), - Some(fr"id = $defaultViewId"), - Some(fr"deprecated = false") - )) - .query[Json] - .to[List] - .transact(xas.read) - .flatMap { rows => - rows.traverseFilter { r => IO.fromEither(r.as[Value]).hideErrors.flatMap(embeddedView) }.map(AggregateView(_)) - } - .hideErrors - }.span("fetchingDefaultViews") } }