Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
436 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/dsl/metrics/Metrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2021-2021 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
package com.snowplowanalytics.snowplow.rdbloader.dsl.metrics | ||
|
||
import java.time.Duration | ||
|
||
import cats.implicits._ | ||
import cats.Functor | ||
|
||
import cats.effect.Clock | ||
|
||
import com.snowplowanalytics.snowplow.rdbloader.common.LoaderMessage | ||
|
||
object Metrics { | ||
|
||
final case class KVMetric(key: String, value: String) | ||
|
||
case class KVMetrics( | ||
countGood: KVMetric, | ||
collectorLatencyMin: Option[KVMetric], | ||
collectorLatencyMax: Option[KVMetric], | ||
shredderStartLatency: KVMetric, | ||
shredderEndLatency: KVMetric | ||
) { | ||
def toList = | ||
List( | ||
Some(countGood), | ||
collectorLatencyMin, | ||
collectorLatencyMax, | ||
Some(shredderStartLatency), | ||
Some(shredderEndLatency) | ||
).unite | ||
|
||
def toHumanReadableString = | ||
s"""${countGood.value} good events were loaded. | ||
| It took minimum ${collectorLatencyMin.map(_.value).getOrElse("unknown")} seconds and maximum | ||
| ${collectorLatencyMax.map(_.value).getOrElse("unknown")} seconds between the collector and Redshift for these events. | ||
| It took ${shredderStartLatency.value} seconds between the start of shredder and Redshift | ||
| and ${shredderEndLatency.value} seconds between the completion of shredder and Redshift | ||
""".stripMargin | ||
} | ||
|
||
def getMetrics[F[_]: Clock: Functor](loaded: LoaderMessage.ShreddingComplete): F[KVMetrics] = | ||
Clock[F].instantNow.map { now => | ||
KVMetrics( | ||
KVMetric(CountGoodName, loaded.count.map(_.good).getOrElse(0).toString), | ||
loaded.timestamps.max.map(max => Duration.between(max, now).toSeconds()).map(l => KVMetric(CollectorLatencyMinName, l.toString)), | ||
loaded.timestamps.min.map(min => Duration.between(min, now).toSeconds()).map(l => KVMetric(CollectorLatencyMaxName, l.toString)), | ||
KVMetric(ShredderStartLatencyName, Duration.between(loaded.timestamps.jobStarted, now).toSeconds().toString), | ||
KVMetric(ShredderEndLatencyName, Duration.between(loaded.timestamps.jobCompleted, now).toSeconds().toString) | ||
) | ||
} | ||
|
||
private[metrics] val CountGoodName = "count.good" | ||
private[metrics] val CollectorLatencyMinName = "latency.collector_to_load.min" | ||
private[metrics] val CollectorLatencyMaxName = "latency.collector_to_load.max" | ||
private[metrics] val ShredderStartLatencyName = "latency.shredder_start_to_load" | ||
private[metrics] val ShredderEndLatencyName = "latency.shredder_end_to_load" | ||
} |
46 changes: 46 additions & 0 deletions
46
...loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/dsl/metrics/Reporter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2021-2021 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
package com.snowplowanalytics.snowplow.rdbloader.dsl.metrics | ||
|
||
import cats.Applicative | ||
|
||
import cats.effect.{Blocker, ContextShift, Sync, Timer} | ||
|
||
import com.snowplowanalytics.snowplow.rdbloader.common.config.Config | ||
import com.snowplowanalytics.snowplow.rdbloader.dsl.Logging | ||
|
||
trait Reporter[F[_]] { | ||
def report(metrics: List[Metrics.KVMetric]): F[Unit] | ||
} | ||
|
||
object Reporter { | ||
def apply[F[_]](implicit ev: Reporter[F]): Reporter[F] = ev | ||
|
||
def build[F[_]: ContextShift: Sync: Timer]( | ||
metricsConfig: Option[Config.Metrics], | ||
logging: Logging[F], | ||
blocker: Blocker | ||
): Reporter[F] = | ||
metricsConfig match { | ||
case Some(statsDConfig: Config.Metrics.StatsD) => | ||
StatsDReporter.build[F](statsDConfig, blocker) | ||
case Some(stdoutConfig: Config.Metrics.Stdout) => | ||
StdoutReporter.build[F](stdoutConfig, logging) | ||
case None => | ||
noop[F] | ||
} | ||
|
||
def noop[F[_]: Applicative]: Reporter[F] = new Reporter[F] { | ||
def report(metrics: List[Metrics.KVMetric]) = Applicative[F].unit | ||
} | ||
} |
Oops, something went wrong.