Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Port to Cats Effect 3 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
keirlawson authored Jun 3, 2021
1 parent 64f83e6 commit 54dd2b8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ lazy val publishSettings = Seq(

lazy val commonDependencies = Seq(
"org.typelevel" %% "cats-core" % "2.6.0",
"org.typelevel" %% "cats-effect" % "2.5.0",
"org.typelevel" %% "cats-effect" % "3.1.0",
"org.specs2" %% "specs2-core" % "4.8.3" % "test",
"io.micrometer" % "micrometer-core" % "1.4.1",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.1.6",
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/com/ovoenergy/meters4s/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.ovoenergy.meters4s

import cats.effect.{Sync, Concurrent}
import cats.effect.{Sync, Async}
import cats.implicits._
import cats.effect.implicits._
import cats.effect.concurrent.Semaphore
import cats.effect.std.Semaphore
import Reporter.{Counter, Timer, Gauge}
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import io.micrometer.core.instrument.{MeterRegistry, Tag}
Expand Down Expand Up @@ -211,7 +211,7 @@ object Reporter {
* @param c configuration for this reporter
* @return an effect evaluating to an instance of the wrapping reporter
*/
def createSimple[F[_]: Concurrent](
def createSimple[F[_]: Async](
c: MetricsConfig
): F[Reporter[F]] = {
fromRegistry[F](new SimpleMeterRegistry, c)
Expand All @@ -224,7 +224,7 @@ object Reporter {
* @param config configuration for this reporter
* @return an effect evaluating to an instance of the wrapping reporter
*/
def fromRegistry[F[_]: Concurrent](
def fromRegistry[F[_]: Async](
mx: MeterRegistry,
config: MetricsConfig = MetricsConfig()
): F[Reporter[F]] =
Expand Down Expand Up @@ -343,7 +343,7 @@ private class MeterRegistryReporter[F[_]](
val allTags = effectiveTags(tags)
val gaugeKey = new GaugeKey(pname, allTags)

val gaugeValue: F[AtomicInteger] = gaugeSem.withPermit(
val gaugeValue: F[AtomicInteger] = gaugeSem.permit.use(_ =>
activeGauges
.get(gaugeKey)
.fold {
Expand Down
6 changes: 2 additions & 4 deletions core/src/test/scala/com/ovoenergy/meters4s/ReporterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import scala.concurrent.duration.FiniteDuration
import java.util.concurrent.TimeUnit
import io.micrometer.core.instrument.simple.SimpleConfig
import io.micrometer.core.instrument.MockClock
import scala.concurrent.ExecutionContext
import cats.effect.unsafe.implicits.global

class ReporterTest(implicit ec: ExecutionContext) extends Specification {

implicit val cs = IO.contextShift(ec)
class ReporterTest extends Specification {

"counter" >> {
"increment should increment underlying counter" >> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.micrometer.datadog.{DatadogConfig => MmDatadogConfig}
import com.ovoenergy.meters4s.{MetricsConfig, Reporter}

import scala.concurrent.duration.FiniteDuration
import cats.effect.Concurrent
import cats.effect.Async

/**
* Configuration to be passed to the underlying Micrometer DatadogMeterRegistry
Expand Down Expand Up @@ -90,7 +90,7 @@ package object DataDog {
* @param dataDogConfig the configuration for reporting to Datadog
* @param c the generic configuration to be applied to any produced metrics
*/
def createReporter[F[_]: Concurrent](
def createReporter[F[_]: Async](
dataDogConfig: DataDogConfig,
c: MetricsConfig
): Resource[F, Reporter[F]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.ovoenergy.meters4s.statsd

import cats.effect.{Resource, Sync, Concurrent}
import cats.effect.{Resource, Sync, Async}
import com.ovoenergy.meters4s.{MetricsConfig, Reporter}
import io.micrometer.statsd.{StatsdConfig => MmStatsdConfig}
import io.micrometer.core.instrument.MeterRegistry
Expand Down Expand Up @@ -101,7 +101,7 @@ package object StatsD {
* @param config the configuration for reporting to StatsD
* @param c the generic configuration to be applied to any produced metrics
*/
def createReporter[F[_]: Concurrent](
def createReporter[F[_]: Async](
config: StatsdConfig,
c: MetricsConfig
): Resource[F, Reporter[F]] = {
Expand Down

0 comments on commit 54dd2b8

Please sign in to comment.