@@ -87,8 +87,8 @@ impl PrometheusBuilder {
87
87
///
88
88
/// The HTTP listener that is spawned will respond to GET requests on any request path.
89
89
///
90
- /// Running in HTTP listener mode is mutually exclusive with the push gateway i.e. enabling the
91
- /// HTTP listener will disable the push gateway, and vise versa.
90
+ /// Running in HTTP listener mode is mutually exclusive with the push gateway i.e. enabling the HTTP listener will
91
+ /// disable the push gateway, and vise versa.
92
92
///
93
93
/// Defaults to enabled, listening at `0.0.0.0:9000`.
94
94
///
@@ -105,15 +105,14 @@ impl PrometheusBuilder {
105
105
106
106
/// Configures the exporter to push periodic requests to a Prometheus [push gateway].
107
107
///
108
- /// Running in push gateway mode is mutually exclusive with the HTTP listener i.e. enabling the
109
- /// push gateway will disable the HTTP listener, and vise versa.
108
+ /// Running in push gateway mode is mutually exclusive with the HTTP listener i.e. enabling the push gateway will
109
+ /// disable the HTTP listener, and vise versa.
110
110
///
111
111
/// Defaults to disabled.
112
112
///
113
113
/// ## Errors
114
114
///
115
- /// If the given endpoint cannot be parsed into a valid URI, an error variant will be
116
- /// returned describing the error.
115
+ /// If the given endpoint cannot be parsed into a valid URI, an error variant will be returned describing the error.
117
116
///
118
117
/// [push gateway]: https://prometheus.io/docs/instrumenting/pushing/
119
118
#[ cfg( feature = "push-gateway" ) ]
@@ -139,13 +138,13 @@ impl PrometheusBuilder {
139
138
Ok ( self )
140
139
}
141
140
142
- /// Configures the exporter to expose an HTTP listener that functions as a [scrape endpoint],
143
- /// listening on a Unix Domain socket at the given path
141
+ /// Configures the exporter to expose an HTTP listener that functions as a [scrape endpoint], listening on a Unix
142
+ /// Domain socket at the given path
144
143
///
145
144
/// The HTTP listener that is spawned will respond to GET requests on any request path.
146
145
///
147
- /// Running in HTTP listener mode is mutually exclusive with the push gateway i.e. enabling the
148
- /// HTTP listener will disable the push gateway, and vise versa.
146
+ /// Running in HTTP listener mode is mutually exclusive with the push gateway i.e. enabling the HTTP listener will
147
+ /// disable the push gateway, and vise versa.
149
148
///
150
149
/// Defaults to disabled.
151
150
///
@@ -162,22 +161,21 @@ impl PrometheusBuilder {
162
161
163
162
/// Adds an IP address or subnet to the allowlist for the scrape endpoint.
164
163
///
165
- /// If a client makes a request to the scrape endpoint and their IP is not present in the
166
- /// allowlist, either directly or within any of the allowed subnets, they will receive a 403
167
- /// Forbidden response.
164
+ /// If a client makes a request to the scrape endpoint and their IP is not present in the allowlist, either directly
165
+ /// or within any of the allowed subnets, they will receive a 403 Forbidden response.
168
166
///
169
167
/// Defaults to allowing all IPs.
170
168
///
171
169
/// ## Security Considerations
172
170
///
173
- /// On its own, an IP allowlist is insufficient for access control, if the exporter is running
174
- /// in an environment alongside applications (such as web browsers) that are susceptible to [DNS
171
+ /// On its own, an IP allowlist is insufficient for access control, if the exporter is running in an environment
172
+ /// alongside applications (such as web browsers) that are susceptible to [DNS
175
173
/// rebinding](https://en.wikipedia.org/wiki/DNS_rebinding) attacks.
176
174
///
177
175
/// ## Errors
178
176
///
179
- /// If the given address cannot be parsed into an IP address or subnet, an error variant will be
180
- /// returned describing the error.
177
+ /// If the given address cannot be parsed into an IP address or subnet, an error variant will be returned describing
178
+ /// the error.
181
179
#[ cfg( feature = "http-listener" ) ]
182
180
#[ cfg_attr( docsrs, doc( cfg( feature = "http-listener" ) ) ) ]
183
181
pub fn add_allowed_address < A > ( mut self , address : A ) -> Result < Self , BuildError >
@@ -195,15 +193,15 @@ impl PrometheusBuilder {
195
193
196
194
/// Sets the quantiles to use when rendering histograms.
197
195
///
198
- /// Quantiles represent a scale of 0 to 1, where percentiles represent a scale of 1 to 100, so
199
- /// a quantile of 0.99 is the 99th percentile, and a quantile of 0.99 is the 99.9th percentile.
196
+ /// Quantiles represent a scale of 0 to 1, where percentiles represent a scale of 1 to 100, so a quantile of 0.99 is
197
+ /// the 99th percentile, and a quantile of 0.99 is the 99.9th percentile.
200
198
///
201
- /// Defaults to a hard-coded set of quantiles: 0.0, 0.5, 0.9, 0.95, 0.99, 0.999, and 1.0. This means
202
- /// that all histograms will be exposed as Prometheus summaries.
199
+ /// Defaults to a hard-coded set of quantiles: 0.0, 0.5, 0.9, 0.95, 0.99, 0.999, and 1.0. This means that all
200
+ /// histograms will be exposed as Prometheus summaries.
203
201
///
204
202
/// If buckets are set (via [`set_buckets`][Self::set_buckets] or
205
- /// [`set_buckets_for_metric`][Self::set_buckets_for_metric]) then all histograms will be exposed
206
- /// as summaries instead.
203
+ /// [`set_buckets_for_metric`][Self::set_buckets_for_metric]) then all histograms will be exposed as summaries
204
+ /// instead.
207
205
///
208
206
/// ## Errors
209
207
///
@@ -219,17 +217,16 @@ impl PrometheusBuilder {
219
217
220
218
/// Sets the bucket width when using summaries.
221
219
///
222
- /// Summaries are rolling, which means that they are divided into buckets of a fixed duration
223
- /// (width), and older buckets are dropped as they age out. This means data from a period as
224
- /// large as the width will be dropped at a time.
220
+ /// Summaries are rolling, which means that they are divided into buckets of a fixed duration (width), and older
221
+ /// buckets are dropped as they age out. This means data from a period as large as the width will be dropped at a
222
+ /// time.
225
223
///
226
- /// The total amount of data kept for a summary is the number of buckets times the bucket width.
227
- /// For example, a bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds
228
- /// of data is kept at most, with the oldest 20 second chunk of data being dropped as the
229
- /// summary rolls forward.
224
+ /// The total amount of data kept for a summary is the number of buckets times the bucket width. For example, a
225
+ /// bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds of data is kept at most, with the
226
+ /// oldest 20 second chunk of data being dropped as the summary rolls forward.
230
227
///
231
- /// Use more buckets with a smaller width to roll off smaller amounts of data at a time, or
232
- /// fewer buckets with a larger width to roll it off in larger chunks.
228
+ /// Use more buckets with a smaller width to roll off smaller amounts of data at a time, or fewer buckets with a
229
+ /// larger width to roll it off in larger chunks.
233
230
///
234
231
/// Defaults to 20 seconds.
235
232
///
@@ -247,17 +244,16 @@ impl PrometheusBuilder {
247
244
248
245
/// Sets the bucket count when using summaries.
249
246
///
250
- /// Summaries are rolling, which means that they are divided into buckets of a fixed duration
251
- /// (width), and older buckets are dropped as they age out. This means data from a period as
252
- /// large as the width will be dropped at a time.
247
+ /// Summaries are rolling, which means that they are divided into buckets of a fixed duration (width), and older
248
+ /// buckets are dropped as they age out. This means data from a period as large as the width will be dropped at a
249
+ /// time.
253
250
///
254
- /// The total amount of data kept for a summary is the number of buckets times the bucket width.
255
- /// For example, a bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds
256
- /// of data is kept at most, with the oldest 20 second chunk of data being dropped as the
257
- /// summary rolls forward.
251
+ /// The total amount of data kept for a summary is the number of buckets times the bucket width. For example, a
252
+ /// bucket count of 3 and a bucket width of 20 seconds would mean that 60 seconds of data is kept at most, with the
253
+ /// oldest 20 second chunk of data being dropped as the summary rolls forward.
258
254
///
259
- /// Use more buckets with a smaller width to roll off smaller amounts of data at a time, or
260
- /// fewer buckets with a larger width to roll it off in larger chunks.
255
+ /// Use more buckets with a smaller width to roll off smaller amounts of data at a time, or fewer buckets with a
256
+ /// larger width to roll it off in larger chunks.
261
257
///
262
258
/// Defaults to 3.
263
259
#[ must_use]
@@ -268,8 +264,8 @@ impl PrometheusBuilder {
268
264
269
265
/// Sets the buckets to use when rendering histograms.
270
266
///
271
- /// Buckets values represent the higher bound of each buckets. If buckets are set, then all
272
- /// histograms will be rendered as true Prometheus histograms, instead of summaries.
267
+ /// Buckets values represent the higher bound of each buckets. If buckets are set, then all histograms will be
268
+ /// rendered as true Prometheus histograms, instead of summaries.
273
269
///
274
270
/// ## Errors
275
271
///
@@ -285,16 +281,16 @@ impl PrometheusBuilder {
285
281
286
282
/// Sets the bucket for a specific pattern.
287
283
///
288
- /// The match pattern can be a full match (equality), prefix match, or suffix match. The
289
- /// matchers are applied in that order if two or more matchers would apply to a single metric.
290
- /// That is to say, if a full match and a prefix match applied to a metric, the full match would
291
- /// win, and if a prefix match and a suffix match applied to a metric, the prefix match would win.
284
+ /// The match pattern can be a full match (equality), prefix match, or suffix match. The matchers are applied in
285
+ /// that order if two or more matchers would apply to a single metric. That is to say, if a full match and a prefix
286
+ /// match applied to a metric, the full match would win, and if a prefix match and a suffix match applied to a
287
+ /// metric, the prefix match would win.
292
288
///
293
- /// Buckets values represent the higher bound of each buckets. If buckets are set, then any
294
- /// histograms that match will be rendered as true Prometheus histograms, instead of summaries.
289
+ /// Buckets values represent the higher bound of each buckets. If buckets are set, then any histograms that match
290
+ /// will be rendered as true Prometheus histograms, instead of summaries.
295
291
///
296
- /// This option changes the observer's output of histogram-type metric into summaries.
297
- /// It only affects matching metrics if [`set_buckets`][Self::set_buckets] was not used.
292
+ /// This option changes the observer's output of histogram-type metric into summaries. It only affects matching
293
+ /// metrics if [`set_buckets`][Self::set_buckets] was not used.
298
294
///
299
295
/// ## Errors
300
296
///
@@ -315,18 +311,17 @@ impl PrometheusBuilder {
315
311
316
312
/// Sets the idle timeout for metrics.
317
313
///
318
- /// If a metric hasn't been updated within this timeout, it will be removed from the registry
319
- /// and in turn removed from the normal scrape output until the metric is emitted again. This
320
- /// behavior is driven by requests to generate rendered output, and so metrics will not be
321
- /// removed unless a request has been made recently enough to prune the idle metrics.
314
+ /// If a metric hasn't been updated within this timeout, it will be removed from the registry and in turn removed
315
+ /// from the normal scrape output until the metric is emitted again. This behavior is driven by requests to
316
+ /// generate rendered output, and so metrics will not be removed unless a request has been made recently enough to
317
+ /// prune the idle metrics.
322
318
///
323
- /// Further, the metric kind "mask" configures which metrics will be considered by the idle
324
- /// timeout. If the kind of a metric being considered for idle timeout is not of a kind
325
- /// represented by the mask, it will not be affected, even if it would have othered been removed
326
- /// for exceeding the idle timeout.
319
+ /// Further, the metric kind "mask" configures which metrics will be considered by the idle timeout. If the kind of
320
+ /// a metric being considered for idle timeout is not of a kind represented by the mask, it will not be affected,
321
+ /// even if it would have otherwise been removed for exceeding the idle timeout.
327
322
///
328
- /// Refer to the documentation for [`MetricKindMask`](metrics_util::MetricKindMask) for more
329
- /// information on defining a metric kind mask.
323
+ /// Refer to the documentation for [`MetricKindMask`](metrics_util::MetricKindMask) for more information on defining
324
+ /// a metric kind mask.
330
325
#[ must_use]
331
326
pub fn idle_timeout ( mut self , mask : MetricKindMask , timeout : Option < Duration > ) -> Self {
332
327
self . idle_timeout = timeout;
@@ -336,8 +331,8 @@ impl PrometheusBuilder {
336
331
337
332
/// Sets the upkeep interval.
338
333
///
339
- /// The upkeep task handles periodic maintenance operations, such as draining histogram data,
340
- /// to ensure that all recorded data is up-to-date and prevent unbounded memory growth.
334
+ /// The upkeep task handles periodic maintenance operations, such as draining histogram data, to ensure that all
335
+ /// recorded data is up-to-date and prevent unbounded memory growth.
341
336
#[ must_use]
342
337
pub fn upkeep_timeout ( mut self , timeout : Duration ) -> Self {
343
338
self . upkeep_timeout = timeout;
@@ -346,9 +341,8 @@ impl PrometheusBuilder {
346
341
347
342
/// Adds a global label to this exporter.
348
343
///
349
- /// Global labels are applied to all metrics. Labels defined on the metric key itself have precedence
350
- /// over any global labels. If this method is called multiple times, the latest value for a given label
351
- /// key will be used.
344
+ /// Global labels are applied to all metrics. Labels defined on the metric key itself have precedence over any
345
+ /// global labels. If this method is called multiple times, the latest value for a given label key will be used.
352
346
#[ must_use]
353
347
pub fn add_global_label < K , V > ( mut self , key : K , value : V ) -> Self
354
348
where
@@ -362,14 +356,13 @@ impl PrometheusBuilder {
362
356
363
357
/// Builds the recorder and exporter and installs them globally.
364
358
///
365
- /// When called from within a Tokio runtime, the exporter future is spawned directly
366
- /// into the runtime. Otherwise, a new single-threaded Tokio runtime is created
367
- /// on a background thread, and the exporter is spawned there.
359
+ /// When called from within a Tokio runtime, the exporter future is spawned directly into the runtime. Otherwise, a
360
+ /// new single-threaded Tokio runtime is created on a background thread, and the exporter is spawned there.
368
361
///
369
362
/// ## Errors
370
363
///
371
- /// If there is an error while either building the recorder and exporter, or installing the
372
- /// recorder and exporter, an error variant will be returned describing the error.
364
+ /// If there is an error while either building the recorder and exporter, or installing the recorder and exporter,
365
+ /// an error variant will be returned describing the error.
373
366
#[ cfg( any( feature = "http-listener" , feature = "push-gateway" ) ) ]
374
367
#[ cfg_attr( docsrs, doc( cfg( any( feature = "http-listener" , feature = "push-gateway" ) ) ) ) ]
375
368
pub fn install ( self ) -> Result < ( ) , BuildError > {
@@ -415,10 +408,13 @@ impl PrometheusBuilder {
415
408
///
416
409
/// The handle can be used to generate valid Prometheus scrape endpoint payloads directly.
417
410
///
411
+ /// The caller is responsible for ensuring that upkeep is run periodically. See the **Upkeep and maintenance**
412
+ /// section in the top-level crate documentation for more information.
413
+ ///
418
414
/// ## Errors
419
415
///
420
- /// If there is an error while building the recorder, or installing the recorder, an error
421
- /// variant will be returned describing the error.
416
+ /// If there is an error while building the recorder, or installing the recorder, an error variant will be returned
417
+ /// describing the error.
422
418
pub fn install_recorder ( self ) -> Result < PrometheusHandle , BuildError > {
423
419
let recorder = self . build_recorder ( ) ;
424
420
let handle = recorder. handle ( ) ;
@@ -430,19 +426,19 @@ impl PrometheusBuilder {
430
426
431
427
/// Builds the recorder and exporter and returns them both.
432
428
///
433
- /// In most cases, users should prefer to use [`install`][PrometheusBuilder::install] to create
434
- /// and install the recorder and exporter automatically for them. If a caller is combining
435
- /// recorders, or needs to schedule the exporter to run in a particular way, this method, or
436
- /// [`build_recorder`][PrometheusBuilder::build_recorder], provide the flexibility to do so.
429
+ /// In most cases, users should prefer to use [`install`][PrometheusBuilder::install] to create and install the
430
+ /// recorder and exporter automatically for them. If a caller is combining recorders, or needs to schedule the
431
+ /// exporter to run in a particular way, this method, or [`build_recorder`][PrometheusBuilder::build_recorder],
432
+ /// provide the flexibility to do so.
437
433
///
438
434
/// ## Panics
439
435
///
440
436
/// This method must be called from within an existing Tokio runtime or it will panic.
441
437
///
442
438
/// ## Errors
443
439
///
444
- /// If there is an error while building the recorder and exporter, an error variant will be
445
- /// returned describing the error.
440
+ /// If there is an error while building the recorder and exporter, an error variant will be returned describing the
441
+ /// error.
446
442
#[ warn( clippy:: too_many_lines) ]
447
443
#[ cfg( any( feature = "http-listener" , feature = "push-gateway" ) ) ]
448
444
#[ cfg_attr( docsrs, doc( cfg( any( feature = "http-listener" , feature = "push-gateway" ) ) ) ) ]
@@ -495,6 +491,9 @@ impl PrometheusBuilder {
495
491
}
496
492
497
493
/// Builds the recorder and returns it.
494
+ ///
495
+ /// The caller is responsible for ensuring that upkeep is run periodically. See the **Upkeep and maintenance**
496
+ /// section in the top-level crate documentation for more information.
498
497
pub fn build_recorder ( self ) -> PrometheusRecorder {
499
498
self . build_with_clock ( Clock :: new ( ) )
500
499
}
0 commit comments