From 6a259664a749ad1b0f910ce9b8df517bebd951f0 Mon Sep 17 00:00:00 2001 From: Erik van Oosten Date: Wed, 28 Nov 2018 12:52:48 +0100 Subject: [PATCH] Deprecated `scope` parameter in preparation for v5.0.0. Added MIMA check. --- build.sbt | 8 +- project/plugins.sbt | 1 + releasechecklist.md | 2 +- .../metrics/scala/HdrMetricBuilder.scala | 12 +- .../grons/metrics/scala/MetricBuilder.scala | 107 ++++++++++++++---- .../metrics/scala/FutureMetricsSpec.scala | 2 +- 6 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 project/plugins.sbt diff --git a/build.sbt b/build.sbt index 1c4fc112..d50c9cae 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import sbt.Keys._ -lazy val baseVersion = "3.5.9" +lazy val baseVersion = "3.5.10" // See crossrelease.sh for valid combinations of akkaVersion and crossScalaVersion. @@ -125,3 +125,9 @@ pomExtra := ( ) + +mimaPreviousArtifacts := { + val av = akkaVersion.value + val version = "3.5.9" + (if (av.nonEmpty) "_a" + av.split('.').take(2).mkString(".") else "") + Set("nl.grons" %% "metrics-scala" % version) +} diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 00000000..cf7f4738 --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0") diff --git a/releasechecklist.md b/releasechecklist.md index da362f35..28caa0ab 100644 --- a/releasechecklist.md +++ b/releasechecklist.md @@ -1,7 +1,7 @@ 1. Double check documentation is up to date. 2. Validate version in build.sbt 3. Validate entry in CHANGELOG.md -4. Run `./crossrelease.sh clean` and `./crossrelease.sh test` +4. Run `./crossrelease.sh clean`, `./crossrelease.sh test` and `./crossrelease.sh mimaReportBinaryIssues` 5. Push changes, e.g.`git commit -m 'Releasing 3.x.x'` 6. Set tag `git tag version-3.x.x` 7. `./crossrelease.sh` diff --git a/src/main/scala/nl/grons/metrics/scala/HdrMetricBuilder.scala b/src/main/scala/nl/grons/metrics/scala/HdrMetricBuilder.scala index d1d78873..062329b7 100644 --- a/src/main/scala/nl/grons/metrics/scala/HdrMetricBuilder.scala +++ b/src/main/scala/nl/grons/metrics/scala/HdrMetricBuilder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2017 Erik van Oosten + * Copyright (c) 2013-2018 Erik van Oosten * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,24 +42,22 @@ class HdrMetricBuilder( * Creates a new histogram metric with a [[Reservoir]] from the HdrHistogram library. * * @param name the name of the histogram - * @param scope the scope of the histogram or null for no scope */ - override def histogram(name: String, scope: String): Histogram = + override def histogram(name: String): Histogram = new Histogram( registry.histogram( - metricNameFor(name, scope), + metricNameFor(name), () => new DropwizardHistogram(createHdrReservoir()))) /** * Creates a new timer metric with a [[Reservoir]] from the HdrHistogram library. * * @param name the name of the timer - * @param scope the scope of the timer or null for no scope */ - override def timer(name: String, scope: String): Timer = + override def timer(name: String): Timer = new Timer( registry.timer( - metricNameFor(name, scope), + metricNameFor(name), () => new DropwizardTimer(createHdrReservoir()))) private def createHdrReservoir(): Reservoir = diff --git a/src/main/scala/nl/grons/metrics/scala/MetricBuilder.scala b/src/main/scala/nl/grons/metrics/scala/MetricBuilder.scala index c26b1979..ec84ce6d 100644 --- a/src/main/scala/nl/grons/metrics/scala/MetricBuilder.scala +++ b/src/main/scala/nl/grons/metrics/scala/MetricBuilder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2017 Erik van Oosten + * Copyright (c) 2013-2018 Erik van Oosten * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import _root_.scala.concurrent.duration.FiniteDuration /** * Builds and registering metrics. */ -class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) { +class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) extends DeprecatedMetricBuilder { private[this] val gauges: AtomicReference[Seq[DropwizardGauge[_]]] = new AtomicReference(Seq.empty) @@ -34,10 +34,9 @@ class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) { * Registers a new gauge metric. * * @param name the name of the gauge - * @param scope the scope of the gauge or null for no scope */ - def gauge[A](name: String, scope: String = null)(f: => A): Gauge[A] = { - wrapDwGauge(metricNameFor(name, scope), new DropwizardGauge[A] { def getValue: A = f }) + def gauge[A](name: String)(f: => A): Gauge[A] = { + wrapDwGauge(metricNameFor(name), new DropwizardGauge[A] { def getValue: A = f }) } /** @@ -45,10 +44,9 @@ class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) { * * @param name the name of the gauge * @param timeout the timeout - * @param scope the scope of the gauge or null for no scope */ - def cachedGauge[A](name: String, timeout: FiniteDuration, scope: String = null)(f: => A): Gauge[A] = { - wrapDwGauge(metricNameFor(name, scope), new DropwizardCachedGauge[A](timeout.length, timeout.unit) { def loadValue: A = f }) + def cachedGauge[A](name: String, timeout: FiniteDuration)(f: => A): Gauge[A] = { + wrapDwGauge(metricNameFor(name), new DropwizardCachedGauge[A](timeout.length, timeout.unit) { def loadValue: A = f }) } private def wrapDwGauge[A](name: String, dwGauge: DropwizardGauge[A]): Gauge[A] = { @@ -61,37 +59,33 @@ class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) { * Creates a new counter metric. * * @param name the name of the counter - * @param scope the scope of the counter or null for no scope */ - def counter(name: String, scope: String = null): Counter = - new Counter(registry.counter(metricNameFor(name, scope))) + def counter(name: String): Counter = + new Counter(registry.counter(metricNameFor(name))) /** * Creates a new histogram metric. * * @param name the name of the histogram - * @param scope the scope of the histogram or null for no scope */ - def histogram(name: String, scope: String = null): Histogram = - new Histogram(registry.histogram(metricNameFor(name, scope))) + def histogram(name: String): Histogram = + new Histogram(registry.histogram(metricNameFor(name))) /** * Creates a new meter metric. * * @param name the name of the meter - * @param scope the scope of the meter or null for no scope */ - def meter(name: String, scope: String = null): Meter = - new Meter(registry.meter(metricNameFor(name, scope))) + def meter(name: String): Meter = + new Meter(registry.meter(metricNameFor(name))) /** * Creates a new timer metric. * * @param name the name of the timer - * @param scope the scope of the timer or null for no scope */ - def timer(name: String, scope: String = null): Timer = - new Timer(registry.timer(metricNameFor(name, scope))) + def timer(name: String): Timer = + new Timer(registry.timer(metricNameFor(name))) /** * Unregisters all gauges that were created through this builder. @@ -104,6 +98,77 @@ class MetricBuilder(val baseName: MetricName, val registry: MetricRegistry) { }) } + protected def metricNameFor(name: String): String = baseName.append(name).name +} + +trait DeprecatedMetricBuilder { this: MetricBuilder => + + /** + * Registers a new gauge metric. + * + * @param name the name of the gauge + * @param scope (deprecated) the scope of the gauge or null for no scope + */ + @deprecated("""Please use `gauge(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def gauge[A](name: String, scope: String = null)(f: => A): Gauge[A] = + gauge(mergeScope(name, scope))(f) + + /** + * Registers a new gauge metric that caches its value for a given duration. + * + * @param name the name of the gauge + * @param timeout the timeout + * @param scope (deprecated) the scope of the gauge or null for no scope + */ + @deprecated("""Please use `cachedGauge(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def cachedGauge[A](name: String, timeout: FiniteDuration, scope: String = null)(f: => A): Gauge[A] = + cachedGauge(mergeScope(name, scope), timeout)(f) + + /** + * Creates a new counter metric. + * + * @param name the name of the counter + * @param scope (deprecated) the scope of the counter or null for no scope + */ + @deprecated("""Please use `counter(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def counter(name: String, scope: String = null): Counter = + counter(mergeScope(name, scope)) + + /** + * Creates a new histogram metric. + * + * @param name the name of the histogram + * @param scope (deprecated) the scope of the histogram or null for no scope + */ + @deprecated("""Please use `histogram(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def histogram(name: String, scope: String = null): Histogram = + histogram(mergeScope(name, scope)) + + /** + * Creates a new meter metric. + * + * @param name the name of the meter + * @param scope (deprecated) the scope of the meter or null for no scope + */ + @deprecated("""Please use `meter(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def meter(name: String, scope: String = null): Meter = + meter(mergeScope(name, scope)) + + /** + * Creates a new timer metric. + * + * @param name the name of the timer + * @param scope (deprecated) the scope of the timer or null for no scope + */ + @deprecated("""Please use `timer(name+"."+scope)(f)` instead. The scope parameter has been deprecated and will be removed in v5.0.0.""", "3.5.10") + def timer(name: String, scope: String = null): Timer = + timer(mergeScope(name, scope)) + + private def mergeScope(name: String, scope: String): String = + if (scope == null) name else name + "." + scope + + @deprecated("""Do not use metricNameFor, it is an internal API. This method will be removed in v5.0.0.""", "3.5.10") protected def metricNameFor(name: String, scope: String = null): String = baseName.append(name, scope).name -} + +} \ No newline at end of file diff --git a/src/test/scala/nl/grons/metrics/scala/FutureMetricsSpec.scala b/src/test/scala/nl/grons/metrics/scala/FutureMetricsSpec.scala index e4e5e4d7..fb404161 100644 --- a/src/test/scala/nl/grons/metrics/scala/FutureMetricsSpec.scala +++ b/src/test/scala/nl/grons/metrics/scala/FutureMetricsSpec.scala @@ -32,7 +32,7 @@ class FutureMetricsSpec extends FunSpec with OneInstancePerTest with FutureMetri val metricRegistry = null override def metrics = new MetricBuilder(null,null) { - override def timer(name: String, scope: String = null): Timer = mockTimer + override def timer(name: String): Timer = mockTimer } var timeCalled = false