diff --git a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala index 3ec38752..50df9bc5 100644 --- a/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala +++ b/src/main/scala/com/twitter/ostrich/stats/StatsCollection.scala @@ -134,6 +134,10 @@ class StatsCollection extends StatsProvider with JsonSerializable { counter } + def removeCounter(name: String) { + counterMap.remove(name) + } + protected def newCounter(name: String) = { new Counter() } diff --git a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala index c0044335..63ab982c 100644 --- a/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala +++ b/src/test/scala/com/twitter/ostrich/stats/StatsCollectionSpec.scala @@ -74,6 +74,14 @@ object StatsCollectionSpec extends Specification { collection.incr("widgets", -1) collection.getCounters() mustEqual Map("widgets" -> 2) } + + "clearCounter" in { + collection.getCounter("smellyfeet") + collection.incr("smellyfeet", 1) + collection.getCounters() mustEqual Map("smellyfeet" -> 1) + collection.removeCounter("smellyfeet") + collection.getCounters() mustEqual Map() + } } "metrics" in {