From 1cd73c4293a28f11f6e85bae73b873784bed73c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Herna=CC=81ndez?= Date: Thu, 27 Jul 2023 09:17:58 +0200 Subject: [PATCH] Get rid of `Sized` and `IndexedSeq` from APIs --- .../internal/ShapelessPolyfill.scala | 4 - .../internal/ShapelessPolyfill.scala | 22 -- .../prometheus4cats/internal/package.scala | 197 +++++++----------- .../internal/summary/SummaryDsl.scala | 11 +- .../scala/test/MetricsFactoryDslTest.scala | 19 +- 5 files changed, 95 insertions(+), 158 deletions(-) diff --git a/core/src/main/scala-2/prometheus4cats/internal/ShapelessPolyfill.scala b/core/src/main/scala-2/prometheus4cats/internal/ShapelessPolyfill.scala index 99a9da1a..3f1354ea 100644 --- a/core/src/main/scala-2/prometheus4cats/internal/ShapelessPolyfill.scala +++ b/core/src/main/scala-2/prometheus4cats/internal/ShapelessPolyfill.scala @@ -36,8 +36,4 @@ private[prometheus4cats] trait ShapelessPolyfill { val Succ = shapeless.Succ - type Sized[+Repr, L <: Nat] = shapeless.Sized[Repr, L] - - val Sized = shapeless.Sized - } diff --git a/core/src/main/scala-3/prometheus4cats/internal/ShapelessPolyfill.scala b/core/src/main/scala-3/prometheus4cats/internal/ShapelessPolyfill.scala index 3f786a46..9c2bb89c 100644 --- a/core/src/main/scala-3/prometheus4cats/internal/ShapelessPolyfill.scala +++ b/core/src/main/scala-3/prometheus4cats/internal/ShapelessPolyfill.scala @@ -21,10 +21,6 @@ import scala.quoted.* private[prometheus4cats] trait ShapelessPolyfill { - type Represented[R] = R match { - case IndexedSeq[a] => a - } - type Nat = Int object Nat { @@ -52,22 +48,4 @@ private[prometheus4cats] trait ShapelessPolyfill { given gt2[A <: Nat, B <: Nat](using GT[A, B]): GT[S[A], S[B]] = new GT[S[A], S[B]] {} } - type TupleSized[R, A, N <: Int] <: Tuple = N match { - case 0 => EmptyTuple - case S[n] => A *: TupleSized[R, A, n] - } - - extension [R, A, N <: Int](s: TupleSized[R, A, N]) { - def unsized: IndexedSeq[A] = - s.productIterator.toIndexedSeq.asInstanceOf[IndexedSeq[A]] - def :+(a: A): TupleSized[R, A, N + 1] = - (s :* a).asInstanceOf[TupleSized[R, A, N + 1]] - } - - type Sized[Repr, L <: Nat] = TupleSized[Repr, Represented[Repr], L] - - object Sized { - def apply[A](a1: A): Sized[IndexedSeq[A], 1] = Tuple1(a1) - } - } diff --git a/core/src/main/scala/prometheus4cats/internal/package.scala b/core/src/main/scala/prometheus4cats/internal/package.scala index 5914b309..1c50a1e5 100644 --- a/core/src/main/scala/prometheus4cats/internal/package.scala +++ b/core/src/main/scala/prometheus4cats/internal/package.scala @@ -184,41 +184,10 @@ class MetricDsl[F[_], A, M[_[_], _], L[_[_], _, _]] private[prometheus4cats] ( (name, toString) => new LabelledMetricDsl( makeLabelledMetric, - Sized(name), - a => Sized(toString(a)) + IndexedSeq(name), + a => IndexedSeq(toString(a)) ) - /** Creates a metric whose labels aren't checked at compile time. Provides a builder for a labelled metric that takes - * a map of label names to their values. - * - * This should be used when the labels are not known at compile time and potentially come from some source at - * runtime. - * - * @param labelNames - * names of the labels - */ - def unsafeLabels( - labelNames: IndexedSeq[Label.Name] - ): BuildStep[F, L[F, A, Map[Label.Name, String]]] = - BuildStep[F, L[F, A, Map[Label.Name, String]]]( - makeLabelledMetric( - labelNames - )(labels => labelNames.flatMap(labels.get)) - ) - - /** Creates a metric whose labels aren't checked at compile time. Provides a builder for a labelled metric that takes - * a map of label names to their values. - * - * This should be used when the labels are not known at compile time and potentially come from some source at - * runtime. - * - * @param labelNames - * glob of names of the labels - */ - def unsafeLabels( - labelNames: Label.Name* - ): BuildStep[F, L[F, A, Map[Label.Name, String]]] = unsafeLabels(labelNames.toIndexedSeq) - /** Creates a metric whose label sizes _are_ checked at compile time. Takes a sized collection of label name and a * function converting some label object `B` to a sized collection of strings. * @@ -234,10 +203,12 @@ class MetricDsl[F[_], A, M[_[_], _], L[_[_], _, _]] private[prometheus4cats] ( * @param f * function to convert `B` in to a sized collection of label values */ - def labels[B, N <: Nat](labelNames: Sized[IndexedSeq[Label.Name], N])( - f: B => Sized[IndexedSeq[String], N] - ): LabelsBuildStep[F, A, B, N, L] = - new LabelsBuildStep(makeLabelledMetric, labelNames, f) + def labels[B](labels: (Label.Name, B => String)*): LabelsBuildStep[F, A, B, L] = { + val labelNames = labels.toIndexedSeq.map(_._1) + val labelValues = labels.toIndexedSeq.map(_._2) + + new LabelsBuildStep(makeLabelledMetric, labelNames, b => labelValues.map(_(b))) + } } object MetricDsl { @@ -250,37 +221,31 @@ object MetricDsl { with CallbackStep[F, A0] { override protected def buildCallback: F[A0] => Resource[F, Unit] = makeCallback - override def unsafeLabels( - labelNames: IndexedSeq[Label.Name] - ): CallbackBuildStep[F, L[F, A, Map[Label.Name, String]], NonEmptyList[(A0, Map[Label.Name, String])]] = - new CallbackBuildStep[F, L[F, A, Map[Label.Name, String]], NonEmptyList[(A0, Map[Label.Name, String])]]( - makeLabelledMetric(labelNames)(labels => labelNames.flatMap(labels.get)), - cb => makeLabelledCallback(labelNames, cb)(labels => labelNames.flatMap(labels.get)) - ) + override def labels[B]( + labels: (Label.Name, B => String)* + ): LabelsBuildStep.WithCallbacks[F, A, A0, B, L] = { + val labelNames = labels.toIndexedSeq.map(_._1) + val labelValues = labels.toIndexedSeq.map(_._2) - override def unsafeLabels( - labelNames: Label.Name* - ): CallbackBuildStep[F, L[F, A, Map[Label.Name, String]], NonEmptyList[(A0, Map[Label.Name, String])]] = - unsafeLabels( - labelNames.toIndexedSeq + new LabelsBuildStep.WithCallbacks[F, A, A0, B, L]( + makeLabelledMetric, + makeLabelledCallback, + labelNames, + b => labelValues.map(_(b)) ) - - override def labels[B, N <: Nat](labelNames: Sized[IndexedSeq[Label.Name], N])( - f: B => Sized[IndexedSeq[String], N] - ): LabelsBuildStep.WithCallbacks[F, A, A0, B, N, L] = - new LabelsBuildStep.WithCallbacks[F, A, A0, B, N, L](makeLabelledMetric, makeLabelledCallback, labelNames, f) + } override def label[B]: FirstLabelApply.WithCallbacks[F, A, A0, B, L] = new FirstLabelApply.WithCallbacks[F, A, A0, B, L] { override def apply( name: Label.Name, toString: B => String - ): LabelledMetricDsl.WithCallbacks[F, A, A0, B, Nat._1, L] = - new LabelledMetricDsl.WithCallbacks[F, A, A0, B, Nat._1, L]( + ): LabelledMetricDsl.WithCallbacks[F, A, A0, B, L] = + new LabelledMetricDsl.WithCallbacks[F, A, A0, B, L]( makeLabelledMetric, makeLabelledCallback, - Sized(name), - a => Sized(toString(a)) + IndexedSeq(name), + a => IndexedSeq(toString(a)) ) } } @@ -304,28 +269,28 @@ object MetricDsl { } } -abstract class BaseLabelsBuildStep[F[_], A, T, N <: Nat, L[_[_], _, _]]( +abstract class BaseLabelsBuildStep[F[_], A, T, L[_[_], _, _]]( fa: Resource[F, L[F, A, T]] ) extends BuildStep[F, L[F, A, T]] { protected[internal] val makeLabelledMetric: LabelledMetricPartiallyApplied[F, A, L] - protected[internal] val labelNames: Sized[IndexedSeq[Label.Name], N] - protected[internal] val f: T => Sized[IndexedSeq[String], N] + protected[internal] val labelNames: IndexedSeq[Label.Name] + protected[internal] val f: T => IndexedSeq[String] - def contramapLabels[B](f: B => T): BaseLabelsBuildStep[F, A, B, N, L] + def contramapLabels[B](f: B => T): BaseLabelsBuildStep[F, A, B, L] override def build: Resource[F, L[F, A, T]] = fa } object BaseLabelsBuildStep { - implicit final class CounterSyntax[F[_], A, T, N <: Nat]( - dsl: BaseLabelsBuildStep[F, A, T, N, Counter.Labelled] + implicit final class CounterSyntax[F[_], A, T]( + dsl: BaseLabelsBuildStep[F, A, T, Counter.Labelled] ) { def asOutcomeRecorder(implicit F: MonadCancelThrow[F] ): BuildStep[F, OutcomeRecorder.Labelled.Aux[F, A, T, Counter.Labelled]] = BuildStep( dsl - .makeLabelledMetric[(T, Status)](dsl.labelNames.unsized :+ Label.Name.outcomeStatus) { case (t, status) => - dsl.f(t).unsized :+ status.show + .makeLabelledMetric[(T, Status)](dsl.labelNames :+ Label.Name.outcomeStatus) { case (t, status) => + dsl.f(t) :+ status.show } .map(OutcomeRecorder.Labelled.fromCounter(_)) ) @@ -333,15 +298,15 @@ object BaseLabelsBuildStep { def contramap[B](f: B => A): BuildStep[F, Counter.Labelled[F, B, T]] = dsl.map(_.contramap(f)) } - implicit final class GaugeSyntax[F[_], A, T, N <: Nat]( - dsl: BaseLabelsBuildStep[F, A, T, N, Gauge.Labelled] + implicit final class GaugeSyntax[F[_], A, T]( + dsl: BaseLabelsBuildStep[F, A, T, Gauge.Labelled] ) { def asOutcomeRecorder(implicit F: MonadCancelThrow[F] ): BuildStep[F, OutcomeRecorder.Labelled.Aux[F, A, T, Gauge.Labelled]] = BuildStep( dsl - .makeLabelledMetric[(T, Status)](dsl.labelNames.unsized :+ Label.Name.outcomeStatus) { case (t, status) => - dsl.f(t).unsized :+ status.show + .makeLabelledMetric[(T, Status)](dsl.labelNames :+ Label.Name.outcomeStatus) { case (t, status) => + dsl.f(t) :+ status.show } .map(OutcomeRecorder.Labelled.fromGauge(_)) ) @@ -349,30 +314,30 @@ object BaseLabelsBuildStep { def contramap[B](f: B => A): BuildStep[F, Gauge.Labelled[F, B, T]] = dsl.map(_.contramap(f)) } - implicit final class HistogramSyntax[F[_], A, T, N <: Nat]( - dsl: BaseLabelsBuildStep[F, A, T, N, Histogram.Labelled] + implicit final class HistogramSyntax[F[_], A, T]( + dsl: BaseLabelsBuildStep[F, A, T, Histogram.Labelled] ) { def contramap[B](f: B => A): BuildStep[F, Histogram.Labelled[F, B, T]] = dsl.map(_.contramap(f)) } - implicit final class SummarySyntax[F[_], A, T, N <: Nat]( - dsl: BaseLabelsBuildStep[F, A, T, N, Summary.Labelled] + implicit final class SummarySyntax[F[_], A, T]( + dsl: BaseLabelsBuildStep[F, A, T, Summary.Labelled] ) { def contramap[B](f: B => A): BuildStep[F, Summary.Labelled[F, B, T]] = dsl.map(_.contramap(f)) } } -class LabelsBuildStep[F[_], A, T, N <: Nat, L[_[_], _, _]] private[internal] ( +class LabelsBuildStep[F[_], A, T, L[_[_], _, _]] private[internal] ( protected[internal] val makeLabelledMetric: LabelledMetricPartiallyApplied[F, A, L], - protected[internal] val labelNames: Sized[IndexedSeq[Label.Name], N], - protected[internal] val f: T => Sized[IndexedSeq[String], N] -) extends BaseLabelsBuildStep[F, A, T, N, L]( - makeLabelledMetric(labelNames.unsized)( + protected[internal] val labelNames: IndexedSeq[Label.Name], + protected[internal] val f: T => IndexedSeq[String] +) extends BaseLabelsBuildStep[F, A, T, L]( + makeLabelledMetric(labelNames)( // avoid using andThen because it can be slow and this gets called repeatedly during runtime - t => f(t).unsized + t => f(t) ) ) { - override def contramapLabels[B](f0: B => T): LabelsBuildStep[F, A, B, N, L] = new LabelsBuildStep[F, A, B, N, L]( + override def contramapLabels[B](f0: B => T): LabelsBuildStep[F, A, B, L] = new LabelsBuildStep[F, A, B, L]( makeLabelledMetric, labelNames, b => f(f0(b)) @@ -380,46 +345,46 @@ class LabelsBuildStep[F[_], A, T, N <: Nat, L[_[_], _, _]] private[internal] ( } object LabelsBuildStep { - final class WithCallbacks[F[_], A, A0, T, N <: Nat, L[_[_], _, _]] private[internal] ( + final class WithCallbacks[F[_], A, A0, T, L[_[_], _, _]] private[internal] ( makeLabelledMetric: LabelledMetricPartiallyApplied[F, A, L], makeLabelledCallback: LabelledCallbackPartiallyApplied[F, A0], - labelNames: Sized[IndexedSeq[Label.Name], N], - f: T => Sized[IndexedSeq[String], N] - ) extends LabelsBuildStep[F, A, T, N, L]( + labelNames: IndexedSeq[Label.Name], + f: T => IndexedSeq[String] + ) extends LabelsBuildStep[F, A, T, L]( makeLabelledMetric, labelNames, f ) with CallbackStep[F, NonEmptyList[(A0, T)]] { override protected def buildCallback: F[NonEmptyList[(A0, T)]] => Resource[F, Unit] = cb => - makeLabelledCallback(labelNames.unsized, cb)(f(_).unsized) + makeLabelledCallback(labelNames, cb)(f(_)) - override def contramapLabels[B](f0: B => T): LabelsBuildStep.WithCallbacks[F, A, A0, B, N, L] = + override def contramapLabels[B](f0: B => T): LabelsBuildStep.WithCallbacks[F, A, A0, B, L] = new WithCallbacks(makeLabelledMetric, makeLabelledCallback, labelNames, b => f(f0(b))) } } -class LabelledMetricDsl[F[_], A, T, N <: Nat, L[_[_], _, _]] private[internal] ( +class LabelledMetricDsl[F[_], A, T, L[_[_], _, _]] private[internal] ( protected[internal] val makeLabelledMetric: LabelledMetricPartiallyApplied[F, A, L], - protected[internal] val labelNames: Sized[IndexedSeq[Label.Name], N], - protected[internal] val f: T => Sized[IndexedSeq[String], N] -) extends BaseLabelsBuildStep[F, A, T, N, L]( - makeLabelledMetric(labelNames.unsized)( + protected[internal] val labelNames: IndexedSeq[Label.Name], + protected[internal] val f: T => IndexedSeq[String] +) extends BaseLabelsBuildStep[F, A, T, L]( + makeLabelledMetric(labelNames)( // avoid using andThen because it can be slow and this gets called repeatedly during runtime - t => f(t).unsized + t => f(t) ) ) { /** Sets a new label for the metric, the label type will be joined together with previous types in a tuple. Requires * either a `Show` instance for the label type, or a method converting the label value to a `String`. */ - def label[B]: LabelApply[F, A, T, N, B, L] = - new LabelApply[F, A, T, N, B, L] { + def label[B]: LabelApply[F, A, T, B, L] = + new LabelApply[F, A, T, B, L] { override def apply[C]( name: Label.Name, toString: B => String - )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl[F, A, C, Succ[N], L] = new LabelledMetricDsl( + )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl[F, A, C, L] = new LabelledMetricDsl( makeLabelledMetric, labelNames :+ name, c => f(initLast.init(c)) :+ toString(initLast.last(c)) @@ -427,33 +392,33 @@ class LabelledMetricDsl[F[_], A, T, N <: Nat, L[_[_], _, _]] private[internal] ( } - override def contramapLabels[B](f0: B => T): LabelledMetricDsl[F, A, B, N, L] = new LabelledMetricDsl( + override def contramapLabels[B](f0: B => T): LabelledMetricDsl[F, A, B, L] = new LabelledMetricDsl( makeLabelledMetric, labelNames, b => f(f0(b)) ) } object LabelledMetricDsl { - final class WithCallbacks[F[_], A, A0, T, N <: Nat, L[_[_], _, _]] private[internal] ( + final class WithCallbacks[F[_], A, A0, T, L[_[_], _, _]] private[internal] ( makeLabelledMetric: LabelledMetricPartiallyApplied[F, A, L], makeLabelledCallback: LabelledCallbackPartiallyApplied[F, A0], - labelNames: Sized[IndexedSeq[Label.Name], N], - f: T => Sized[IndexedSeq[String], N] - ) extends LabelledMetricDsl[F, A, T, N, L](makeLabelledMetric, labelNames, f) + labelNames: IndexedSeq[Label.Name], + f: T => IndexedSeq[String] + ) extends LabelledMetricDsl[F, A, T, L](makeLabelledMetric, labelNames, f) with CallbackStep[F, NonEmptyList[(A0, T)]] { override protected def buildCallback: F[NonEmptyList[(A0, T)]] => Resource[F, Unit] = cb => - makeLabelledCallback.apply(labelNames.unsized, cb)(f(_).unsized) + makeLabelledCallback.apply(labelNames, cb)(f(_)) /** @inheritdoc */ - override def label[B]: LabelApply.WithCallbacks[F, A, A0, T, N, B, L] = - new LabelApply.WithCallbacks[F, A, A0, T, N, B, L] { + override def label[B]: LabelApply.WithCallbacks[F, A, A0, T, B, L] = + new LabelApply.WithCallbacks[F, A, A0, T, B, L] { override def apply[C]( name: Label.Name, toString: B => String - )(implicit initLast: InitLast.Aux[T, B, C]): WithCallbacks[F, A, A0, C, Succ[N], L] = new WithCallbacks( + )(implicit initLast: InitLast.Aux[T, B, C]): WithCallbacks[F, A, A0, C, L] = new WithCallbacks( makeLabelledMetric, makeLabelledCallback, labelNames :+ name, @@ -462,17 +427,17 @@ object LabelledMetricDsl { } - override def contramapLabels[B](f0: B => T): WithCallbacks[F, A, A0, B, N, L] = + override def contramapLabels[B](f0: B => T): WithCallbacks[F, A, A0, B, L] = new WithCallbacks(makeLabelledMetric, makeLabelledCallback, labelNames, b => f(f0(b))) } } abstract private[internal] class FirstLabelApply[F[_], A, B, L[_[_], _, _]] { - def apply(name: Label.Name)(implicit show: Show[B]): LabelledMetricDsl[F, A, B, Nat._1, L] = + def apply(name: Label.Name)(implicit show: Show[B]): LabelledMetricDsl[F, A, B, L] = apply(name, _.show) - def apply(name: Label.Name, toString: B => String): LabelledMetricDsl[F, A, B, Nat._1, L] + def apply(name: Label.Name, toString: B => String): LabelledMetricDsl[F, A, B, L] } @@ -482,10 +447,10 @@ object FirstLabelApply { override def apply(name: Label.Name)(implicit show: Show[B] - ): LabelledMetricDsl.WithCallbacks[F, A, A0, B, Nat._1, L] = + ): LabelledMetricDsl.WithCallbacks[F, A, A0, B, L] = apply(name, _.show) - override def apply(name: Label.Name, toString: B => String): LabelledMetricDsl.WithCallbacks[F, A, A0, B, Nat._1, L] + override def apply(name: Label.Name, toString: B => String): LabelledMetricDsl.WithCallbacks[F, A, A0, B, L] } } @@ -505,32 +470,32 @@ class TypeStep[+D[_]] private[prometheus4cats] (long: D[Long], double: D[Double] def ofDouble: D[Double] = double } -abstract class LabelApply[F[_], A, T, N <: Nat, B, L[_[_], _, _]] { +abstract class LabelApply[F[_], A, T, B, L[_[_], _, _]] { def apply[C](name: Label.Name)(implicit show: Show[B], initLast: InitLast.Aux[T, B, C] - ): LabelledMetricDsl[F, A, C, Succ[N], L] = apply(name, _.show) + ): LabelledMetricDsl[F, A, C, L] = apply(name, _.show) def apply[C]( name: Label.Name, toString: B => String - )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl[F, A, C, Succ[N], L] + )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl[F, A, C, L] } object LabelApply { - abstract class WithCallbacks[F[_], A, A0, T, N <: Nat, B, L[_[_], _, _]] extends LabelApply[F, A, T, N, B, L] { + abstract class WithCallbacks[F[_], A, A0, T, B, L[_[_], _, _]] extends LabelApply[F, A, T, B, L] { override def apply[C](name: Label.Name)(implicit show: Show[B], initLast: InitLast.Aux[T, B, C] - ): LabelledMetricDsl.WithCallbacks[F, A, A0, C, Succ[N], L] = apply(name, _.show) + ): LabelledMetricDsl.WithCallbacks[F, A, A0, C, L] = apply(name, _.show) override def apply[C]( name: Label.Name, toString: B => String - )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl.WithCallbacks[F, A, A0, C, Succ[N], L] + )(implicit initLast: InitLast.Aux[T, B, C]): LabelledMetricDsl.WithCallbacks[F, A, A0, C, L] } } diff --git a/core/src/main/scala/prometheus4cats/internal/summary/SummaryDsl.scala b/core/src/main/scala/prometheus4cats/internal/summary/SummaryDsl.scala index a359f472..623fd313 100644 --- a/core/src/main/scala/prometheus4cats/internal/summary/SummaryDsl.scala +++ b/core/src/main/scala/prometheus4cats/internal/summary/SummaryDsl.scala @@ -59,17 +59,8 @@ object SummaryDsl { def label[B]: FirstLabelApply[F, A, B, Summary.Labelled] - def unsafeLabels( - labelNames: IndexedSeq[Label.Name] - ): BuildStep[F, Summary.Labelled[F, A, Map[Label.Name, String]]] + def labels[B](labels: (Label.Name, B => String)*): LabelsBuildStep[F, A, B, Summary.Labelled] - def unsafeLabels( - labelNames: Label.Name* - ): BuildStep[F, Summary.Labelled[F, A, Map[Label.Name, String]]] - - def labels[B, N <: Nat](labelNames: Sized[IndexedSeq[Label.Name], N])( - f: B => Sized[IndexedSeq[String], N] - ): LabelsBuildStep[F, A, B, N, Summary.Labelled] } private val defaultQuantiles: Seq[Summary.QuantileDefinition] = Seq.empty diff --git a/core/src/test/scala/test/MetricsFactoryDslTest.scala b/core/src/test/scala/test/MetricsFactoryDslTest.scala index 1057a65d..c0688a6a 100644 --- a/core/src/test/scala/test/MetricsFactoryDslTest.scala +++ b/core/src/test/scala/test/MetricsFactoryDslTest.scala @@ -49,21 +49,23 @@ object MetricsFactoryDslTest { doubleLabelledGaugeBuilder.asCurrentTimeRecorder(_.toUnit(TimeUnit.NANOSECONDS)) doubleLabelledGaugeBuilder.asOutcomeRecorder.build - val doubleLabelsGaugeBuilder = doubleGaugeBuilder.labels(Sized(Label.Name("test")))((s: String) => Sized(s)).build + val doubleLabelsGaugeBuilder = doubleGaugeBuilder.labels[String](Label.Name("test") -> identity).build val longGaugeBuilder = gaugeBuilder.ofLong.help("help") longGaugeBuilder.build longGaugeBuilder.asCurrentTimeRecorder longGaugeBuilder.asCurrentTimeRecorder(_.toDays) longGaugeBuilder.label[String]("label1").label[Int]("label2").label[BigInteger]("label3", _.toString).build - longGaugeBuilder.unsafeLabels(Label.Name("label1"), Label.Name("label2")).build + longGaugeBuilder.labels[String](Label.Name("label1") -> identity, Label.Name("label2") -> identity).build val counterBuilder = factory.counter("test_total") val doubleCounterBuilder = counterBuilder.ofDouble.help("help") doubleCounterBuilder.build doubleCounterBuilder.asOutcomeRecorder.build - doubleCounterBuilder.unsafeLabels(Label.Name("label1"), Label.Name("label2")).build + doubleCounterBuilder + .labels[String](Label.Name("label1") -> identity, Label.Name("label2") -> identity) + .build val doubleLabelledCounterBuilder = doubleCounterBuilder.label[String]("label1").label[Int]("label2").label[BigInteger]("label3", _.toString) @@ -74,7 +76,9 @@ object MetricsFactoryDslTest { val longCounterBuilder = counterBuilder.ofLong.help("help") longCounterBuilder.build longCounterBuilder.label[String]("label1").label[Int]("label2").label[BigInteger]("label3", _.toString).build - longCounterBuilder.unsafeLabels(Label.Name("label1"), Label.Name("label2")).build + longCounterBuilder + .labels[String](Label.Name("label1") -> identity, Label.Name("label2") -> identity) + .build val histogramBuilder = factory.histogram("test2") @@ -87,7 +91,10 @@ object MetricsFactoryDslTest { .label[BigInteger]("label3", _.toString) .asTimer .build - doubleHistogramBuilder.unsafeLabels(Label.Name("label1"), Label.Name("label2")).asTimer.build + doubleHistogramBuilder + .labels[String](Label.Name("label1") -> identity, Label.Name("label2") -> identity) + .asTimer + .build histogramBuilder.ofLong.help("me").linearBuckets[Nat._1](1, 10) histogramBuilder.ofDouble.help("me").exponentialBuckets[Nat._1](1, 10) @@ -95,7 +102,7 @@ object MetricsFactoryDslTest { val longHistogramBuilder = histogramBuilder.ofLong.help("help").buckets(1, 2) longHistogramBuilder.build longHistogramBuilder.label[String]("label1").label[Int]("label2").label[BigInteger]("label3", _.toString).build - longHistogramBuilder.unsafeLabels(Label.Name("label1"), Label.Name("label2")).build + longHistogramBuilder.labels[String](Label.Name("label1") -> identity, Label.Name("label2") -> identity).build val infoBuilder = factory.info("test_info").help("help") infoBuilder.contramap[List[(Label.Name, String)]](_.toMap)