Skip to content

Commit

Permalink
Add MosaicRasterSourceIO logging (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin authored May 6, 2021
1 parent 2298a02 commit eebf538
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added
- Add MosaicRasterSourceIO logging [#366](https://github.com/geotrellis/geotrellis-server/pull/366)

## [4.4.0] - 2021-04-30

## Fixed
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ lazy val effects = project
geotrellisRaster,
geotrellisStore,
cats.value,
catsEffect.value
catsEffect.value,
log4cats
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package geotrellis.raster.effects

import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger

import geotrellis.raster.{MosaicRasterSource => MosaicRasterSourceS, _}
import geotrellis.vector._
import geotrellis.raster.resample._
import geotrellis.proj4.CRS
import geotrellis.raster.io.geotiff.OverviewStrategy
import cats.implicits._
import cats.syntax.parallel._
import cats.syntax.flatMap._
import cats.data.NonEmptyList
import cats.effect.{ContextShift, IO}
import geotrellis.store.util.BlockingThreadPool
Expand All @@ -38,6 +42,7 @@ import geotrellis.store.util.BlockingThreadPool
abstract class MosaicRasterSourceIO extends RasterSource {

implicit lazy val cs: ContextShift[IO] = IO.contextShift(BlockingThreadPool.executionContext)
implicit val logger: Logger[IO] = Slf4jLogger.getLogger

def sources: NonEmptyList[RasterSource]
lazy val sourcesIO: NonEmptyList[IO[RasterSource]] = sources.map(cs.shift >> IO(_))
Expand All @@ -58,7 +63,11 @@ abstract class MosaicRasterSourceIO extends RasterSource {

def cellType: CellType =
sourcesIO
.parTraverse(_.map(_.cellType))
.parTraverse(_.flatMap { rs =>
logger
.trace(s"${rs.name}::cellType: ${Thread.currentThread().getName}")
.as(rs.cellType)
})
.map(_.toList.reduce(_ union _))
.unsafeRunSync()

Expand All @@ -73,7 +82,15 @@ abstract class MosaicRasterSourceIO extends RasterSource {
*
* @see [[geotrellis.raster.RasterSource.resolutions]]
*/
def resolutions: List[CellSize] = sourcesIO.parTraverse(_.map(_.resolutions)).map(_.reduce).unsafeRunSync()
def resolutions: List[CellSize] =
sourcesIO
.parTraverse(_.flatMap { rs =>
logger
.trace(s"${rs.name}::resolutions: ${Thread.currentThread().getName}")
.as(rs.resolutions)
})
.map(_.reduce)
.unsafeRunSync()

/** Create a new MosaicRasterSourceFixed with sources transformed according to the provided
* crs, options, and strategy, and a new crs
Expand All @@ -96,7 +113,13 @@ abstract class MosaicRasterSourceIO extends RasterSource {

def read(extent: Extent, bands: Seq[Int]): Option[Raster[MultibandTile]] =
sourcesIO
.parTraverse { _.map { _.read(extent, bands) } }
.parTraverse {
_.flatMap { rs =>
logger
.trace(s"${rs.name}::read($extent, $bands): ${Thread.currentThread().getName}")
.as(rs.read(extent, bands))
}
}
.map(_.reduce)
.unsafeRunSync()

Expand Down Expand Up @@ -127,7 +150,13 @@ abstract class MosaicRasterSourceIO extends RasterSource {
}

sourcesIO
.parTraverse { _.map(rs => rs.read(relativeGridBounds(bounds, rs.extent), bands)) }
.parTraverse {
_.flatMap { rs =>
logger
.trace(s"${rs.name}::read($bounds, $bands): ${Thread.currentThread().getName}")
.as(rs.read(relativeGridBounds(bounds, rs.extent), bands))
}
}
.map(_.reduce)
.unsafeRunSync()
}
Expand Down
1 change: 1 addition & 0 deletions stac-example/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<logger name="org.http4s" level="${HTTP4S_LOG_LEVEL:-WARN}"/>
<logger name="org.http4s.blaze.channel.nio1" level="${BLAZE_NIO_LOG_LEVEL:-WARN}"/>
<logger name="software.amazon.awssdk" level="${AWS_SDK_LOG_LEVEL:-WARN}"/>
<logger name="geotrellis.raster.effects" level="${GT_MOSAIC_LOG_LEVEL:-DEBUG}" />

<root level="DEBUG">
<appender-ref ref="STDOUT" />
Expand Down

0 comments on commit eebf538

Please sign in to comment.