Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
janstenpickle committed Aug 15, 2023
1 parent 6d7f588 commit 4a46ee2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 14 additions & 1 deletion core/src/main/scala/prometheus4cats/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package prometheus4cats.internal
import cats.data.NonEmptyList
import cats.effect.kernel.{Clock, MonadCancelThrow, Resource}
import cats.syntax.all._
import cats.{FlatMap, Functor, Show}
import cats.{Contravariant, FlatMap, Functor, Show}
import prometheus4cats.OutcomeRecorder.Status
import prometheus4cats._

Expand Down Expand Up @@ -143,6 +143,15 @@ object BuildStep {
implicit class LabelsContravariantSyntax[F[_], M[_]: LabelsContravariant, A](bs: BuildStep[F, M[A]]) {
def contramapLabels[B](f: B => A): BuildStep[F, M[B]] = bs.map(LabelsContravariant[M].contramapLabels(_)(f))
}

implicit def auxContravariant[F[_], M[_]: Contravariant]: Contravariant[Aux[F, M, *]] =
new Contravariant[Aux[F, M, *]] {
override def contramap[A, B](fa: Aux[F, M, A])(f: B => A): Aux[F, M, B] = fa.map(_.contramap(f))
}

implicit class ContravariantSyntax[F[_], M[_]: Contravariant, A](bs: BuildStep[F, M[A]]) {
def contramap[B](f: B => A): BuildStep[F, M[B]] = bs.map(_.contramap(f))
}
}

sealed trait CallbackStep[F[_], A] { self =>
Expand Down Expand Up @@ -289,6 +298,8 @@ object MetricDsl {
.map(_.contramapLabels[(Unit, OutcomeRecorder.Status)](_._2))
.map(OutcomeRecorder.fromCounter)
)

def contramap[B](f: B => A): BuildStep[F, Counter[F, B, Unit]] = dsl.map(_.contramap(f))
}

implicit class GaugeSyntax[F[_], A](dsl: MetricDsl[F, A, Gauge]) {
Expand All @@ -299,6 +310,8 @@ object MetricDsl {
.map(_.contramapLabels[(Unit, OutcomeRecorder.Status)](_._2))
.map(OutcomeRecorder.fromGauge(_))
)

def contramap[B](f: B => A): BuildStep[F, Gauge[F, B, Unit]] = dsl.map(_.contramap(f))
}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/interface/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ unsafeLabelledCounter.build.evalMap(_.inc(3.0, labels))
#### Simple Metric

```scala mdoc:silent
val intCounter: Resource[IO, Counter[IO, Int]] = factory
val intCounter: Resource[IO, Counter[IO, Int, Unit]] = factory
.counter("counter_total")
.ofLong
.help("Describe what this metric does")
Expand All @@ -149,7 +149,7 @@ val intCounter: Resource[IO, Counter[IO, Int]] = factory
```

```scala mdoc:silent
val shortCounter: Resource[IO, Counter[IO, Short]] = intCounter.map(_.contramap[Short](_.toInt))
val shortCounter: Resource[IO, Counter[IO, Short, Unit]] = intCounter.map(_.contramap[Short](_.toInt))
```

#### Labelled Metric
Expand Down
12 changes: 6 additions & 6 deletions docs/metrics/derived-metric-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ operations.
#### Obtaining from a `Histogram`

```scala mdoc:silent
val simpleTimerHistogram: Resource[IO, Timer.Aux[IO, Histogram]] = factory
val simpleTimerHistogram: Resource[IO, Timer.Aux[IO, Unit, Histogram]] = factory
.histogram("time")
.ofDouble
.help("Records the how long an opertation took")
Expand All @@ -55,7 +55,7 @@ val labelledTimerHistogram: Resource[IO, Timer.Aux[IO, String, Histogram]] = fac
#### Obtaining from a `Summary`

```scala mdoc:silent
val simpleTimerSummary: Resource[IO, Timer.Aux[IO, Summary]] = factory
val simpleTimerSummary: Resource[IO, Timer.Aux[IO, Unit, Summary]] = factory
.summary("time")
.ofDouble
.help("Records the how long an opertation took")
Expand All @@ -76,7 +76,7 @@ val labelledTimerSummary: Resource[IO, Timer.Aux[IO, String, Summary]] = factory
#### Obtaining from a `Gauge`

```scala mdoc:silent
val simpleTimerGauge: Resource[IO, Timer.Aux[IO, Gauge]] = factory
val simpleTimerGauge: Resource[IO, Timer.Aux[IO, Unit, Gauge]] = factory
.gauge("time")
.ofDouble
.help("Records the how long an opertation took")
Expand All @@ -102,7 +102,7 @@ system time.
#### Obtaining from a `Gauge`

```scala mdoc:silent
val simpleCurrentTimeRecorderGauge: Resource[IO, CurrentTimeRecorder[IO]] = factory
val simpleCurrentTimeRecorderGauge: Resource[IO, CurrentTimeRecorder[IO, Unit]] = factory
.gauge("current_time")
.ofDouble
.help("Records the how long an opertation took")
Expand Down Expand Up @@ -142,7 +142,7 @@ To help disambiguate the difference in behaviour the `OutcomeRecorder` type will
#### Obtaining from a `Counter`

```scala mdoc:silent
val simpleOutcomeCounter: Resource[IO, OutcomeRecorder.Aux[IO, Long, Counter]] = factory
val simpleOutcomeCounter: Resource[IO, OutcomeRecorder.Aux[IO, Long, Unit, Counter]] = factory
.counter("outcome_total")
.ofLong
.help("Records the outcome of some operation")
Expand All @@ -164,7 +164,7 @@ val labelledOutcomeCounter:
#### Obtaining from a `Gauge`

```scala mdoc:silent
val simpleOutcomeGauge: Resource[IO, OutcomeRecorder.Aux[IO, Long, Gauge]] = factory
val simpleOutcomeGauge: Resource[IO, OutcomeRecorder.Aux[IO, Long, Unit, Gauge]] = factory
.gauge("outcome")
.ofLong
.help("Records the outcome of some operation")
Expand Down

0 comments on commit 4a46ee2

Please sign in to comment.