Skip to content

Commit

Permalink
Use tofu.Mid for the enchanced logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed May 7, 2021
1 parent 30990a5 commit cb1e630
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Added
- Add MosaicRasterSourceIO logging [#366](https://github.com/geotrellis/geotrellis-server/pull/366)
- Use tofu.Mid for the enchanced logging [#367](https://github.com/geotrellis/geotrellis-server/pull/367)

## Fixed
- WMS Parent Layer default time should be omitted [#368](https://github.com/geotrellis/geotrellis-server/pull/368)
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ lazy val `stac-example` = project
sttpHttp4s,
refinedCats,
refinedPureconfig,
ansiColors212
ansiColors212,
tofuCore
),
excludeDependencies ++= Seq(
// log4j brought in via uzaygezen is a pain for us
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ object Dependencies {
val refinedPureconfig = "eu.timepit" %% "refined-pureconfig" % refinedVer
val threetenExtra = "org.threeten" % "threeten-extra" % "1.6.0"
val ansiColors212 = "org.backuity" %% "ansi-interpolator" % "1.1.0" % Provided
val tofuCore = "tf.tofu" %% "tofu-core" % "0.10.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ package geotrellis.server.ogc.conf
import cats.{MonadThrow, SemigroupK}
import cats.instances.list._
import cats.syntax.semigroup._

import geotrellis.proj4.CRS
import geotrellis.server.ogc.{ows, OgcSource, OgcSourceRepository, RasterOgcSource}
import geotrellis.server.ogc.wms.WmsParentLayerMeta
import geotrellis.server.ogc.wmts.GeotrellisTileMatrixSet
import geotrellis.server.ogc.stac._
import geotrellis.store.query.{Repository, RepositoryM}

import io.chrisdavenport.log4cats.Logger
import sttp.client3.SttpBackend

/** Each service has its own unique configuration requirements (see the below instances)
Expand All @@ -42,7 +41,7 @@ sealed trait OgcServiceConf {
OgcSourceRepository(rasterLayers ++ mapAlgebraLayers)
}

def layerSources[F[_]: SemigroupK: MonadThrow](
def layerSources[F[_]: SemigroupK: MonadThrow: Logger](
rasterOgcSources: List[RasterOgcSource],
client: SttpBackend[F, Any]
): RepositoryM[F, List, OgcSource] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import geotrellis.server.ogc.conf.{MapAlgebraSourceConf, OgcSourceConf, RasterSo
import geotrellis.store.query
import geotrellis.store.query._
import geotrellis.server.ogc._

import cats.{Functor, MonadThrow}
import cats.syntax.functor._
import cats.syntax.semigroup._
import cats.instances.list._
import io.chrisdavenport.log4cats.Logger
import sttp.client3.SttpBackend

case class MapAlgebraStacOgcRepository[F[_]: Functor](
Expand All @@ -46,7 +46,7 @@ case class MapAlgebraStacOgcRepository[F[_]: Functor](
.widen
}

case class MapAlgebraStacOgcRepositories[F[_]: MonadThrow](
case class MapAlgebraStacOgcRepositories[F[_]: MonadThrow: Logger](
mapAlgebraConfLayers: List[MapAlgebraSourceConf],
ogcLayers: List[OgcSourceConf],
client: SttpBackend[F, Any]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2021 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geotrellis.server.ogc.stac

import com.azavea.stac4s.{StacCollection, StacItem}
import com.azavea.stac4s.api.client.{SearchFilters, StacClient, StacClientF}

import cats.FlatMap
import cats.syntax.flatMap._
import tofu.higherKind.Mid
import eu.timepit.refined.types.string.NonEmptyString
import io.chrisdavenport.log4cats.Logger
import io.circe.syntax._

final class StacClientLoggingMid[F[_]: FlatMap: Logger] extends StacClientF[Mid[F, *], SearchFilters] {
val logger = Logger[F]

def search: Mid[F, List[StacItem]] =
res =>
logger.trace(s"search all endpoint call") >>
res.flatTap(items => logger.trace(s"retrieved items: ${items.asJson}"))

def search(filter: SearchFilters): Mid[F, List[StacItem]] =
res =>
logger.trace(s"search ${filter.asJson} endpoint call") >>
res.flatTap(items => logger.trace(s"retrieved items: ${items.asJson}"))

def collections: Mid[F, List[StacCollection]] =
res =>
logger.trace(s"collections all endpoint call") >>
res.flatTap(collections => logger.trace(s"retrieved collections: ${collections.asJson}"))

def collection(collectionId: NonEmptyString): Mid[F, StacCollection] =
res =>
logger.trace(s"collections collectionId: $collectionId endpoint call") >>
res.flatTap(collection => logger.trace(s"retrieved collection: ${collection.asJson}"))

def items(collectionId: NonEmptyString): Mid[F, List[StacItem]] =
res =>
logger.trace(s"items by collectionId: $collectionId endpoint call") >>
res.flatTap(items => logger.trace(s"retrieved items: ${items.asJson}"))

def item(collectionId: NonEmptyString, itemId: NonEmptyString): Mid[F, StacItem] =
res =>
logger.trace(s"item by collectionId: $collectionId and itemId: $itemId endpoint call") >>
res.flatTap(items => logger.trace(s"retrieved items: ${items.asJson}"))

def itemCreate(collectionId: NonEmptyString, item: StacItem): Mid[F, StacItem] =
res =>
logger.trace(s"itemCreate for collectionId: $collectionId and item: $item") >>
res.flatTap(item => logger.trace(s"created item: ${item.asJson}"))

def collectionCreate(collection: StacCollection): Mid[F, StacCollection] =
res =>
logger.trace(s"collectionCreate of collection: $collection") >>
res.flatTap(collection => logger.trace(s"created collection: ${collection.asJson}"))
}

object StacClientLoggingMid {
def apply[F[_]: FlatMap: Logger]: StacClient[Mid[F, *]] = new StacClientLoggingMid[F]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import geotrellis.raster.{EmptyName, MosaicRasterSource, RasterSource}
import geotrellis.server.ogc.OgcSource
import geotrellis.server.ogc.conf.{OgcSourceConf, StacSourceConf}
import geotrellis.raster.effects.MosaicRasterSourceIO

import sttp.client3.SttpBackend
import sttp.client3.UriContext
import geotrellis.store.query
Expand All @@ -37,10 +36,11 @@ import cats.syntax.option._
import cats.syntax.semigroup._
import cats.instances.list._
import higherkindness.droste.{scheme, Algebra}
import io.chrisdavenport.log4cats.Logger

case class StacOgcRepository[F[_]: Applicative](
stacSourceConf: StacSourceConf,
client: SttpStacClient[F]
client: StacClient[F]
) extends RepositoryM[F, List, OgcSource] {
def store: F[List[OgcSource]] = find(query.all)

Expand Down Expand Up @@ -114,7 +114,7 @@ case class StacOgcRepository[F[_]: Applicative](
}
}

case class StacOgcRepositories[F[_]: MonadThrow](
case class StacOgcRepositories[F[_]: MonadThrow: Logger](
stacLayers: List[StacSourceConf],
client: SttpBackend[F, Any]
) extends RepositoryM[F, List, OgcSource] {
Expand All @@ -128,7 +128,7 @@ case class StacOgcRepositories[F[_]: MonadThrow](
def find(query: Query): F[List[OgcSource]] =
StacOgcRepositories
.eval(query)(stacLayers)
.map { conf => StacOgcRepository(conf, SttpStacClient(client, uri"${conf.source}")) }
.map { conf => StacOgcRepository(conf, StacClientLoggingMid[F] attach SttpStacClient(client, uri"${conf.source}")) }
.fold(RepositoryM.empty[F, List, OgcSource])(_ |+| _)
.find(query)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@ package geotrellis.server.ogc
import geotrellis.stac._
import geotrellis.server.ogc.utils._
import geotrellis.store.query._

import geotrellis.raster.{EmptyName, RasterSource, SourceName, StringName}
import geotrellis.raster.geotiff.GeoTiffPath

import com.azavea.stac4s.{StacAsset, StacExtent}
import com.azavea.stac4s.api.client.{SearchFilters, StacClient, Query => SQuery}
import com.azavea.stac4s.extensions.periodic.PeriodicExtent
import com.azavea.stac4s.syntax._
import io.circe.syntax._
import cats.{Applicative, Foldable, Functor, FunctorFilter, Monad}
import cats.{Applicative, Foldable, Functor, FunctorFilter}
import cats.data.NonEmptyList
import cats.syntax.either._
import cats.syntax.foldable._
import cats.syntax.functor._
import cats.syntax.functorFilter._
import cats.syntax.applicative._
import cats.syntax.functor._
import cats.syntax.option._
import cats.tagless.{ApplyK, Derive}
import eu.timepit.refined.types.string.NonEmptyString

import java.time.ZoneOffset

package object stac {
implicit val stacClientApplyK: ApplyK[StacClient] = Derive.applyK

implicit class StacExtentionOps(val self: StacExtent) extends AnyVal {

/** [[StacExtent]]s with no temporal component are valid. */
Expand Down

0 comments on commit cb1e630

Please sign in to comment.