Skip to content

Commit

Permalink
Deprecated scope parameter in preparation for v5.0.0.
Browse files Browse the repository at this point in the history
Added MIMA check.
  • Loading branch information
erikvanoosten committed Nov 28, 2018
1 parent 184e067 commit 6a25966
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 31 deletions.
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -125,3 +125,9 @@ pomExtra := (
</developer>
</developers>
)

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)
}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")
2 changes: 1 addition & 1 deletion releasechecklist.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
12 changes: 5 additions & 7 deletions src/main/scala/nl/grons/metrics/scala/HdrMetricBuilder.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 =
Expand Down
107 changes: 86 additions & 21 deletions src/main/scala/nl/grons/metrics/scala/MetricBuilder.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -26,29 +26,27 @@ 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)

/**
* 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 })
}

/**
* 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 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] = {
Expand All @@ -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.
Expand All @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a25966

Please sign in to comment.