Skip to content

Commit 4e68dd0

Browse files
yufangongjenkins
authored and
jenkins
committed
util-stats: Add APIs for providing descriptions
Problem/Solution Add metric description APIs in StatsReceiver and hydrate some key indicators. JIRA Issues: CSL-9962 Differential Revision: https://phabricator.twitter.biz/D615481
1 parent b44e820 commit 4e68dd0

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
66

77
Unreleased
88
----------
9+
New Features
10+
~~~~~~~~~~~~
11+
12+
* util-stats: Counter, Gauge, and Stat can be instrumented with descriptions. ``PHAB_ID = D615481``
913

1014
New Features
1115
~~~~~~~~~~~~

util-stats/src/main/scala/com/twitter/finagle/stats/StatsReceiver.scala

+53
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,32 @@ trait StatsReceiver {
125125
@varargs
126126
def counter(name: String*): Counter = counter(Verbosity.Default, name: _*)
127127

128+
/**
129+
* Get a [[Counter counter]] with the given `description` and `name`.
130+
*/
131+
@varargs
132+
def counter(description: Some[String], name: String*): Counter =
133+
counter(description.get, Verbosity.Default, name: _*)
134+
128135
/**
129136
* Get a [[Counter counter]] with the given `name`.
130137
*/
131138
@varargs
132139
def counter(verbosity: Verbosity, name: String*): Counter =
133140
counter(this.metricBuilder(CounterType).withVerbosity(verbosity).withName(name: _*))
134141

142+
/**
143+
* Get a [[Counter counter]] with the given `description` and `name`.
144+
*/
145+
@varargs
146+
def counter(description: String, verbosity: Verbosity, name: String*): Counter =
147+
counter(
148+
this
149+
.metricBuilder(CounterType)
150+
.withVerbosity(verbosity)
151+
.withName(name: _*)
152+
.withDescription(description))
153+
135154
/**
136155
* Get a [[Counter counter]] with the given schema.
137156
*/
@@ -143,13 +162,32 @@ trait StatsReceiver {
143162
@varargs
144163
def stat(name: String*): Stat = stat(Verbosity.Default, name: _*)
145164

165+
/**
166+
* Get a [[Stat stat]] with the given `description` and `name`.
167+
*/
168+
@varargs
169+
def stat(description: Some[String], name: String*): Stat =
170+
stat(description.get, Verbosity.Default, name: _*)
171+
146172
/**
147173
* Get a [[Stat stat]] with the given name.
148174
*/
149175
@varargs
150176
def stat(verbosity: Verbosity, name: String*): Stat =
151177
stat(this.metricBuilder(HistogramType).withVerbosity(verbosity).withName(name: _*))
152178

179+
/**
180+
* Get a [[Stat stat]] with the given `description` and `name`.
181+
*/
182+
@varargs
183+
def stat(description: String, verbosity: Verbosity, name: String*): Stat =
184+
stat(
185+
this
186+
.metricBuilder(HistogramType)
187+
.withVerbosity(verbosity)
188+
.withName(name: _*)
189+
.withDescription(description))
190+
153191
/**
154192
* Get a [[Stat stat]] with the given schema.
155193
*/
@@ -203,6 +241,12 @@ trait StatsReceiver {
203241
*/
204242
def addGauge(name: String*)(f: => Float): Gauge = addGauge(Verbosity.Default, name: _*)(f)
205243

244+
/**
245+
* Add the function `f` as a [[Gauge gauge]] with the given name and description.
246+
*/
247+
def addGauge(description: Some[String], name: String*)(f: => Float): Gauge =
248+
addGauge(description.get, Verbosity.Default, name: _*)(f)
249+
206250
/**
207251
* Add the function `f` as a [[Gauge gauge]] with the given name.
208252
*
@@ -225,6 +269,15 @@ trait StatsReceiver {
225269
def addGauge(verbosity: Verbosity, name: String*)(f: => Float): Gauge =
226270
addGauge(this.metricBuilder(GaugeType).withVerbosity(verbosity).withName(name: _*))(f)
227271

272+
/**
273+
* Add the function `f` as a [[Gauge gauge]] with the given name and description.
274+
*/
275+
def addGauge(description: String, verbosity: Verbosity, name: String*)(f: => Float): Gauge =
276+
addGauge(
277+
this
278+
.metricBuilder(GaugeType).withVerbosity(verbosity).withName(name: _*).withDescription(
279+
description))(f)
280+
228281
/**
229282
* Just like $AddGaugeScaladocLink but optimized for better Java experience.
230283
*/

0 commit comments

Comments
 (0)