Skip to content

Commit

Permalink
Reduce log level when querying aggregate views (#4263)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Dumas <simon.dumas@epfl.ch>
  • Loading branch information
imsdu and Simon Dumas authored Sep 11, 2023
1 parent 1d19945 commit b6e8581
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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] {
Expand All @@ -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 {
Expand All @@ -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")
}
}

0 comments on commit b6e8581

Please sign in to comment.