Skip to content

Commit

Permalink
Target 2.0 with bin-incompat changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janstenpickle committed Aug 1, 2023
1 parent 45ee5e5 commit 1242f98
Show file tree
Hide file tree
Showing 9 changed files with 676 additions and 1,027 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import laika.rewrite.link._
import org.typelevel.sbt.site.TypelevelProject

// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "1.0" // your current series x.y
ThisBuild / tlBaseVersion := "2.0" // your current series x.y

ThisBuild / organization := "com.permutive"
ThisBuild / organizationName := "Permutive"
Expand Down
13 changes: 1 addition & 12 deletions core/src/main/scala/prometheus4cats/Counter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,7 @@ object Counter {

def make[F[_]: FlatMap: prometheus4cats.Exemplar, A](_inc: (A, Option[prometheus4cats.Exemplar.Labels]) => F[Unit])(
implicit A: Numeric[A]
): Exemplar[F, A] =
make(A.one, _inc)

private[prometheus4cats] def fromCounter[F[_], A](counter: Counter[F, A]) = new Exemplar[F, A] {
override def inc: F[Unit] = counter.inc

override def inc(n: A): F[Unit] = counter.inc(n)

override def incWithExemplar: F[Unit] = inc

override def incWithExemplar(n: A): F[Unit] = inc(n)
}
): Counter.Exemplar[F, A] = make(A.one, _inc)

def noop[F[_]: Applicative, A]: Exemplar[F, A] = new Exemplar[F, A] {
override def inc: F[Unit] = Applicative[F].unit
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/scala/prometheus4cats/Histogram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ object Histogram {
override def observeWithExemplar(n: A): F[Unit] = prometheus4cats.Exemplar[F].get.flatMap(_observe(n, _))
}

private[prometheus4cats] def fromHistogram[F[_], A](histogram: Histogram[F, A]): Exemplar[F, A] =
new Exemplar[F, A] {
override def observe(n: A): F[Unit] = histogram.observe(n)

override def observeWithExemplar(n: A): F[Unit] = histogram.observe(n)
}

def noop[F[_]: Applicative, A]: Exemplar[F, A] =
new Exemplar[F, A] {
override def observe(n: A): F[Unit] = Applicative[F].unit
Expand Down
119 changes: 17 additions & 102 deletions core/src/main/scala/prometheus4cats/MetricFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ sealed abstract class MetricFactory[F[_]](
val commonLabels: CommonLabels
) {

protected def exemplarRegistry: Option[MetricRegistry.WithExemplars[F]] = metricRegistry match {
case exemplars: MetricRegistry.WithExemplars[F] => Some(exemplars)
case _ => None
}

/** Given a natural transformation from `F` to `G`, transforms this [[MetricFactory]] from effect `F` to effect `G`.
* The G constraint can also be satisfied by requiring a Functor[G].
*/
def mapK[G[_]](fk: F ~> G)(implicit F: MonadCancel[F, _], G: MonadCancel[G, _]): MetricFactory[G] =
new MetricFactory[G](
exemplarRegistry.fold(metricRegistry.mapK(fk))(_.mapK(fk)),
metricRegistry.mapK(fk),
prefix,
commonLabels
) {}
Expand Down Expand Up @@ -138,39 +133,23 @@ sealed abstract class MetricFactory[F[_]](
new TypeStep[ExemplarCounterDsl[MetricDsl, *]](
new HelpStep(help =>
new MetricDsl(
exemplarRegistry.fold[Resource[F, Counter.Exemplar[F, Long]]](
metricRegistry
.createAndRegisterLongCounter(prefix, name, help, commonLabels)
.map(Counter.Exemplar.fromCounter)
)(_.createAndRegisterLongExemplarCounter(prefix, name, help, commonLabels)),
metricRegistry.createAndRegisterLongExemplarCounter(prefix, name, help, commonLabels),
new LabelledMetricPartiallyApplied[F, Long, Counter.Labelled.Exemplar] {
override def apply[B](
labels: IndexedSeq[Label.Name]
)(f: B => IndexedSeq[String]): Resource[F, Counter.Labelled.Exemplar[F, Long, B]] =
exemplarRegistry.fold[Resource[F, Counter.Labelled.Exemplar[F, Long, B]]](
metricRegistry
.createAndRegisterLabelledLongCounter(prefix, name, help, commonLabels, labels)(f)
.map(Counter.Labelled.Exemplar.fromCounter)
)(_.createAndRegisterLabelledLongExemplarCounter(prefix, name, help, commonLabels, labels)(f))
metricRegistry.createAndRegisterLabelledLongExemplarCounter(prefix, name, help, commonLabels, labels)(f)
}
)
),
new HelpStep(help =>
new MetricDsl(
exemplarRegistry.fold[Resource[F, Counter.Exemplar[F, Double]]](
metricRegistry
.createAndRegisterDoubleCounter(prefix, name, help, commonLabels)
.map(Counter.Exemplar.fromCounter)
)(_.createAndRegisterDoubleExemplarCounter(prefix, name, help, commonLabels)),
metricRegistry.createAndRegisterDoubleExemplarCounter(prefix, name, help, commonLabels),
new LabelledMetricPartiallyApplied[F, Double, Counter.Labelled.Exemplar] {
override def apply[B](
labels: IndexedSeq[Label.Name]
)(f: B => IndexedSeq[String]): Resource[F, Counter.Labelled.Exemplar[F, Double, B]] =
exemplarRegistry.fold[Resource[F, Counter.Labelled.Exemplar[F, Double, B]]](
metricRegistry
.createAndRegisterLabelledDoubleCounter(prefix, name, help, commonLabels, labels)(f)
.map(Counter.Labelled.Exemplar.fromCounter)
)(_.createAndRegisterLabelledDoubleExemplarCounter(prefix, name, help, commonLabels, labels)(f))
metricRegistry.createAndRegisterLabelledDoubleExemplarCounter(prefix, name, help, commonLabels, labels)(f)
}
)
)
Expand Down Expand Up @@ -245,47 +224,33 @@ sealed abstract class MetricFactory[F[_]](
new HelpStep(help =>
new BucketDsl[MetricDsl[F, Long, Histogram.Exemplar, Histogram.Labelled.Exemplar], Long](buckets =>
new MetricDsl(
exemplarRegistry.fold[Resource[F, Histogram.Exemplar[F, Long]]](
metricRegistry
.createAndRegisterLongHistogram(prefix, name, help, commonLabels, buckets)
.map(Histogram.Exemplar.fromHistogram)
)(_.createAndRegisterLongExemplarHistogram(prefix, name, help, commonLabels, buckets)),
metricRegistry.createAndRegisterLongExemplarHistogram(prefix, name, help, commonLabels, buckets),
new LabelledMetricPartiallyApplied[F, Long, Histogram.Labelled.Exemplar] {
override def apply[B](
labels: IndexedSeq[Label.Name]
)(f: B => IndexedSeq[String]): Resource[F, Histogram.Labelled.Exemplar[F, Long, B]] =
exemplarRegistry.fold[Resource[F, Histogram.Labelled.Exemplar[F, Long, B]]](
metricRegistry
.createAndRegisterLabelledLongHistogram(prefix, name, help, commonLabels, labels, buckets)(f)
.map(Histogram.Labelled.Exemplar.fromHistogram)
)(
_.createAndRegisterLabelledLongExemplarHistogram(prefix, name, help, commonLabels, labels, buckets)(f)
)
metricRegistry
.createAndRegisterLabelledLongExemplarHistogram(prefix, name, help, commonLabels, labels, buckets)(f)
}
)
)
),
new HelpStep(help =>
new BucketDsl[MetricDsl[F, Double, Histogram.Exemplar, Histogram.Labelled.Exemplar], Double](buckets =>
new MetricDsl(
exemplarRegistry.fold[Resource[F, Histogram.Exemplar[F, Double]]](
metricRegistry
.createAndRegisterDoubleHistogram(prefix, name, help, commonLabels, buckets)
.map(Histogram.Exemplar.fromHistogram)
)(_.createAndRegisterDoubleExemplarHistogram(prefix, name, help, commonLabels, buckets)),
metricRegistry.createAndRegisterDoubleExemplarHistogram(prefix, name, help, commonLabels, buckets),
new LabelledMetricPartiallyApplied[F, Double, Histogram.Labelled.Exemplar] {
override def apply[B](
labels: IndexedSeq[Label.Name]
)(f: B => IndexedSeq[String]): Resource[F, Histogram.Labelled.Exemplar[F, Double, B]] =
exemplarRegistry.fold[Resource[F, Histogram.Labelled.Exemplar[F, Double, B]]](
metricRegistry
.createAndRegisterLabelledDoubleHistogram(prefix, name, help, commonLabels, labels, buckets)(f)
.map(Histogram.Labelled.Exemplar.fromHistogram)
)(
_.createAndRegisterLabelledDoubleExemplarHistogram(prefix, name, help, commonLabels, labels, buckets)(
f
)
)
metricRegistry.createAndRegisterLabelledDoubleExemplarHistogram(
prefix,
name,
help,
commonLabels,
labels,
buckets
)(f)
}
)
)
Expand Down Expand Up @@ -756,23 +721,9 @@ object MetricFactory {
* @return
* a new [[MetricFactory]] instance
*/
@deprecated(
"please provide a MetricRegistry.WithExemplars[F] instead, otherwise any exemplar labels you set won't be displayed",
"1.1.0"
)
def build[F[_]](metricRegistry: MetricRegistry[F]): MetricFactory[F] =
new MetricFactory[F](metricRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from a [[MetricRegistry]]
*
* @param metricRegistry
* [[MetricRegistry.WithExemplars]] with which to register new metrics created by the built [[MetricFactory]]
* @return
* a new [[MetricFactory]] instance
*/
def build[F[_]](metricRegistry: MetricRegistry.WithExemplars[F]): MetricFactory[F] =
new MetricFactory[F](metricRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from a [[MetricRegistry]] and separate [[CallbackRegistry]]
*
* @param metricRegistry
Expand All @@ -782,31 +733,12 @@ object MetricFactory {
* @return
* a new [[MetricFactory.WithCallbacks]] instance
*/
@deprecated(
"please provide a MetricRegistry.WithExemplars[F] instead, otherwise any exemplar labels you set won't be displayed",
"1.1.0"
)
def build[F[_]](
metricRegistry: MetricRegistry[F],
callbackRegistry: CallbackRegistry[F]
): MetricFactory.WithCallbacks[F] =
new MetricFactory.WithCallbacks[F](metricRegistry, callbackRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from a [[MetricRegistry.WithExemplars]] and separate [[CallbackRegistry]]
*
* @param metricRegistry
* [[MetricRegistry.WithExemplars]] with which to register new metrics created by the built [[MetricFactory]]
* @param callbackRegistry
* [[CallbackRegistry]] with which to register new metrics created by the built [[MetricFactory]]
* @return
* a new [[MetricFactory.WithCallbacks]] instance
*/
def build[F[_]](
metricRegistry: MetricRegistry.WithExemplars[F],
callbackRegistry: CallbackRegistry[F]
): MetricFactory.WithCallbacks[F] =
new MetricFactory.WithCallbacks[F](metricRegistry, callbackRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from a [[MetricRegistry with CallbackRegistry]]
*
* @param metricRegistry
Expand All @@ -815,26 +747,9 @@ object MetricFactory {
* @return
* a new [[MetricFactory.WithCallbacks]] instance
*/
@deprecated(
"please provide a MetricRegistry.WithExemplars[F] instead, otherwise any exemplar labels you set won't be displayed",
"1.1.0"
)
def build[F[_]](metricRegistry: MetricRegistry[F] with CallbackRegistry[F]): MetricFactory.WithCallbacks[F] =
new MetricFactory.WithCallbacks[F](metricRegistry, metricRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from a [[MetricRegistry.WithExemplars with CallbackRegistry]]
*
* @param metricRegistry
* [[[MetricRegistry.WithExemplars with CallbackRegistry]] with which to register new metrics and callbacks
* created by the built [[MetricFactory]]
* @return
* a new [[MetricFactory.WithCallbacks]] instance
*/
def build[F[_]](
metricRegistry: MetricRegistry.WithExemplars[F] with CallbackRegistry[F]
): MetricFactory.WithCallbacks[F] =
new MetricFactory.WithCallbacks[F](metricRegistry, metricRegistry, prefix, commonLabels) {}

/** Build a [[MetricFactory]] from an existing [[MetricFactory]] and [[CallbackRegistry]]
*
* @param metricFactory
Expand Down
Loading

0 comments on commit 1242f98

Please sign in to comment.