1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
//! # Measured. A low-overhead prometheus/metrics crate for measuring your application statistics.
//!
//! Getting started? See [`docs`]
extern crate alloc;
use ;
/// Reexport of lasso when feature is enabled
pub use lasso;
/// Implement [`FixedCardinalityLabel`] on an `enum`
///
/// # Container attributes
///
/// * `rename_all = "..."` - rename all variants based on their variant name, supporting:
/// * `"UpperCamelCase"`
/// * `"lowerCamelCase"`
/// * `"snake_case"`
/// * `"kebab-case"`
/// * `"SHOUTY_SNAKE_CASE"`
/// * `"SHOUTY-KEBAB-CASE"`
/// * `"Title Case"`
/// * `"Train-Case"`
/// * `singleton = "..."` - This `FixedCardinalityLabel` on it's own represents a [`LabelGroup`]
///
/// # Variant attributes
///
/// * `rename = "..."` - Rename this variant.
///
/// # Outputs
///
/// * `impl FixedCardinalityLabel for T { ... }`
/// * `impl LabelValue for T { ... }`
/// * `impl LabelGroup for T { ... }`
/// - If `singleton` is specified
///
/// # Example
///
/// ## Basic
///
/// ```
/// #[derive(measured::FixedCardinalityLabel)]
/// #[derive(Debug, Copy, Clone, PartialEq)]
/// enum Operation {
/// Create,
/// Update,
/// Delete,
/// DeleteAll,
/// }
///
/// use measured::label::FixedCardinalityLabel as _;
///
/// assert_eq!(Operation::cardinality(), 4, "Operation has 4 variants");
///
/// assert_eq!(Operation::Create.encode(), 0);
/// assert_eq!(Operation::Update.encode(), 1);
/// assert_eq!(Operation::Delete.encode(), 2);
/// assert_eq!(Operation::DeleteAll.encode(), 3);
///
/// assert_eq!(Operation::decode(0), Operation::Create);
/// assert_eq!(Operation::decode(1), Operation::Update);
/// assert_eq!(Operation::decode(2), Operation::Delete);
/// assert_eq!(Operation::decode(3), Operation::DeleteAll);
///
/// use measured::label::LabelValue as _;
/// use measured::label::LabelTestVisitor;
///
/// assert_eq!(Operation::Create.visit(LabelTestVisitor), "create");
/// assert_eq!(Operation::Update.visit(LabelTestVisitor), "update");
/// assert_eq!(Operation::Delete.visit(LabelTestVisitor), "delete");
/// assert_eq!(Operation::DeleteAll.visit(LabelTestVisitor), "delete_all");
/// ```
///
/// ## Integer values
///
/// ```
/// #[derive(measured::FixedCardinalityLabel)]
/// #[derive(Debug, Copy, Clone, PartialEq)]
/// enum StatusCode {
/// Ok = 200,
/// ImATeapot = 418,
/// InternalServerError = 500,
/// }
///
/// use measured::label::FixedCardinalityLabel as _;
///
/// assert_eq!(StatusCode::cardinality(), 3, "StatusCode has 3 variants");
///
/// assert_eq!(StatusCode::Ok.encode(), 0);
/// assert_eq!(StatusCode::ImATeapot.encode(), 1);
/// assert_eq!(StatusCode::InternalServerError.encode(), 2);
///
/// assert_eq!(StatusCode::decode(0), StatusCode::Ok);
/// assert_eq!(StatusCode::decode(1), StatusCode::ImATeapot);
/// assert_eq!(StatusCode::decode(2), StatusCode::InternalServerError);
///
/// use measured::label::LabelValue as _;
/// use measured::label::LabelTestVisitor;
///
/// assert_eq!(StatusCode::Ok.visit(LabelTestVisitor), "200");
/// assert_eq!(StatusCode::ImATeapot.visit(LabelTestVisitor), "418");
/// assert_eq!(StatusCode::InternalServerError.visit(LabelTestVisitor), "500");
/// ```
///
/// ## Custom values
///
/// ```
/// #[derive(measured::FixedCardinalityLabel)]
/// #[derive(Debug, Copy, Clone, PartialEq)]
/// #[label(rename_all = "SHOUTY-KEBAB-CASE")]
/// enum StatusCode {
/// #[label(rename = "a-okay")]
/// Ok,
/// ImATeapot,
/// InternalServerError,
/// }
///
/// use measured::label::LabelValue as _;
/// use measured::label::LabelTestVisitor;
///
/// assert_eq!(StatusCode::Ok.visit(LabelTestVisitor), "a-okay");
/// assert_eq!(StatusCode::ImATeapot.visit(LabelTestVisitor), "IM-A-TEAPOT");
/// assert_eq!(StatusCode::InternalServerError.visit(LabelTestVisitor), "INTERNAL-SERVER-ERROR");
/// ```
pub use FixedCardinalityLabel;
pub use FixedCardinalityLabel;
/// Implement [`LabelGroup`] on a `struct`
///
/// A [`LabelGroup`] is a collection of named [`LabelValue`](label::LabelValue)s. Additionally to the label group,
/// there is also a [`LabelGroupSet`](label::LabelGroupSet) that is created by this macro.
/// The set provides additional information needed to encode the values in the group.
///
/// # Container attributes
///
/// * `set = Ident` - The name that the corresponding [`LabelGroupSet`](label::LabelGroupSet) should take on. (**required**)
///
/// # Field attributes
///
/// * `fixed` - The field type implements [`FixedCardinalityLabel`] (**implied**)
/// * `fixed_with = Type` - The field corresponds to a [`FixedCardinalitySet`](label::FixedCardinalitySet)
/// * `dynamic_with = Type` - The field corresponds to a [`DynamicLabelSet`](label::DynamicLabelSet)
/// * `default` - The generated [`LabelGroupSet`](label::LabelGroupSet) can default this field.
/// * `rename = "..."` - Rename this label.
///
/// # Outputs
///
/// * `impl LabelGroup for T { ... }`
/// * `struct TSet { ... }`
/// * `impl LabelGroupSet for TSet { ... }`
/// * `impl TSet { pub fn new(...) -> Self {} }`
/// - `new` contains args for all the non-default fields.
/// * `impl Default for TSet { ... }`
/// - only implemented if all fields are default fields.
///
/// # Example
///
/// ```
/// use measured::lasso::{RodeoReader, ThreadedRodeo};
///
/// #[derive(measured::LabelGroup)]
/// #[label(set = ResponseSet)]
/// struct Response<'a> {
/// kind: StatusCode,
///
/// /// route paths are known up front, and stored in a `RodeoReader`
/// #[label(fixed_with = RodeoReader)]
/// route: &'a str,
///
/// /// user names are not known up-front and are allocated on-demand in a ThreadedRodeo
/// #[label(dynamic_with = ThreadedRodeo, default)]
/// user_name: &'a str,
/// }
///
/// #[derive(measured::FixedCardinalityLabel, Copy, Clone)]
/// enum StatusCode {
/// Ok = 200,
/// BadRequest = 400,
/// InternalServerError = 500,
/// }
///
/// let set = ResponseSet::new(
/// ["/foo/bar", "/home"].into_iter().collect::<measured::lasso::Rodeo>().into_reader(),
/// );
///
/// use measured::label::LabelGroupSet as _;
///
/// let response = Response {
/// kind: StatusCode::InternalServerError,
/// route: "/home",
/// user_name: "conradludgate",
/// };
/// assert_eq!(set.encode(response), Some((5, 0)));
///
/// let response = Response {
/// kind: StatusCode::Ok,
/// route: "/foo/bar",
/// user_name: "conradludgate",
/// };
/// assert_eq!(set.encode(response), Some((0, 0)));
///
/// // the dynamic value `"conradludgate"` was inserted into the set
/// assert_eq!(set.user_name.len(), 1);
/// ```
pub use LabelGroup;
pub use LabelGroup;
/// Implement [`MetricGroup`] on a `struct`
///
/// A [`MetricGroup`] is a collection of named [`Metric`]s, [`MetricVec`]s, or nested [`MetricGroup`]s.
///
/// # Container attributes
///
/// * `new(..args)` - The arguments the generated `fn new() -> Self` should take. If not provided, no new function is generated.
///
/// # Field attributes
///
/// ## Nested groups
/// These are for fields that also implement [`MetricGroup`]
///
/// * `namespace = "..."` - The field represents a nested group with the given namespace.
/// * `flatten` - The field represents a nested group with no namespacing.
/// * `init` - The expression needed to initialise the nested metric group.
///
/// ## Metrics
/// These are for fields that implement [`MetricFamilyEncoding`](metric::MetricFamilyEncoding)
///
/// * `rename = "..."` - By default, metrics take on the field name in snake case. rename allows renaming them.
/// * `metadata = expr` - The metadata to initialise a [`Metric`] or [`MetricVec`] with.
/// * `label_set = expr` - The [`LabelGroupSet`](label::LabelGroupSet) to initialise a [`MetricVec`] with.
/// * `init = expr` - The expression needed to initialise the metric, if it cannot be defaulted.
///
/// # Outputs
///
/// * `impl MetricGroup for T { ... }`
/// * `impl MetricGroup { pub fn new(...) -> Self { ... } }`
pub use MetricGroup;
pub use MetricGroup;
/// A [`Metric`] that counts individual observations from an event or sample stream in configurable buckets.
/// Similar to a Summary, it also provides a sum of observations and an observation count.
///
/// ```
/// use measured::Histogram;
/// use measured::metric::histogram::Thresholds;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // create a histogram with 8 buckets starting at 0.01, increasing by 2x each time up to 2.56
/// let histogram = Histogram::with_metadata(Thresholds::<8>::exponential_buckets(0.01, 2.0));
/// // observe a value
/// histogram.get_metric().observe(1.0);
///
/// // sample the histogram and encode the value to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_histogram");
/// histogram.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type Histogram<const N: usize> = ;
/// A collection of multiple [`Histogram`]s, keyed by [`LabelGroup`]s
///
/// ```
/// use measured::{HistogramVec, LabelGroup, FixedCardinalityLabel};
/// use measured::label::StaticLabelSet;
/// use measured::metric::histogram::Thresholds;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // Define a fixed cardinality label
///
/// #[derive(FixedCardinalityLabel, Copy, Clone)]
/// enum Operation {
/// Create,
/// Update,
/// Delete,
/// }
///
/// // Define a label group, consisting of 1 or more label values
///
/// #[derive(LabelGroup)]
/// #[label(set = MyLabelGroupSet)]
/// struct MyLabelGroup {
/// operation: Operation,
/// }
///
/// // create a histogram vec
/// let histograms = HistogramVec::with_label_set_and_metadata(
/// MyLabelGroupSet::new(),
/// Thresholds::<8>::exponential_buckets(0.01, 2.0),
/// );
/// // observe a value
/// histograms.observe(MyLabelGroup { operation: Operation::Create }, 0.5);
/// histograms.observe(MyLabelGroup { operation: Operation::Delete }, 2.0);
///
/// // sample the histograms and encode the values to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_histogram");
/// histograms.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type HistogramVec<L, const N: usize> = ;
/// A [`Metric`] that represents a single numerical value that only ever goes up.
///
/// ```
/// use measured::Counter;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // create a counter
/// let counter = Counter::new();
/// // increment the counter value
/// counter.inc();
///
/// // sample the counter and encode the value to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_counter");
/// counter.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type Counter = ;
/// A collection of multiple [`Counter`]s, keyed by [`LabelGroup`]s
///
/// ```
/// use measured::{CounterVec, LabelGroup, FixedCardinalityLabel};
/// use measured::label::StaticLabelSet;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // Define a fixed cardinality label
///
/// #[derive(FixedCardinalityLabel, Copy, Clone)]
/// enum Operation {
/// Create,
/// Update,
/// Delete,
/// }
///
/// // Define a label group, consisting of 1 or more label values
///
/// #[derive(LabelGroup)]
/// #[label(set = MyLabelGroupSet)]
/// struct MyLabelGroup {
/// operation: Operation,
/// }
///
/// // create a counter vec
/// let counters = CounterVec::with_label_set(MyLabelGroupSet::new());
/// // increment the counter at a given label
/// counters.inc(MyLabelGroup { operation: Operation::Create });
/// counters.inc(MyLabelGroup { operation: Operation::Delete });
///
/// // sample the counters and encode the values to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_counter");
/// counters.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type CounterVec<L> = ;
/// A [`Metric`] that represents a single numerical value that can go up or down over time.
///
/// ```
/// use measured::Gauge;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // create a gauge
/// let gauge = Gauge::new();
/// // increment the gauge value
/// gauge.get_metric().inc();
///
/// // sample the gauge and encode the value to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_gauge");
/// gauge.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type Gauge = ;
/// A collection of multiple [`Gauge`]s, keyed by [`LabelGroup`]s
///
/// ```
/// use measured::{GaugeVec, LabelGroup, FixedCardinalityLabel};
/// use measured::label::StaticLabelSet;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // Define a fixed cardinality label
///
/// #[derive(FixedCardinalityLabel, Copy, Clone)]
/// enum Operation {
/// Create,
/// Update,
/// Delete,
/// }
///
/// // Define a label group, consisting of 1 or more label values
///
/// #[derive(LabelGroup)]
/// #[label(set = MyLabelGroupSet)]
/// struct MyLabelGroup {
/// operation: Operation,
/// }
///
/// // create a gauge vec
/// let gauges = GaugeVec::with_label_set(MyLabelGroupSet::new());
/// // increment the gauge at a given label
/// gauges.inc(MyLabelGroup { operation: Operation::Create });
/// gauges.inc(MyLabelGroup { operation: Operation::Delete });
///
/// // sample the gauges and encode the values to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_gauge");
/// gauges.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type GaugeVec<L> = ;
/// A [`Metric`] that represents a single numerical value that can go up or down over time.
///
/// ```
/// use measured::FloatGauge;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // create a gauge
/// let gauge = FloatGauge::new();
/// // increment the gauge value
/// gauge.get_metric().inc();
///
/// // sample the gauge and encode the value to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_gauge");
/// gauge.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type FloatGauge = ;
/// A collection of multiple [`FloatGauge`]s, keyed by [`LabelGroup`]s
///
/// ```
/// use measured::{FloatGaugeVec, LabelGroup, FixedCardinalityLabel};
/// use measured::label::StaticLabelSet;
/// use measured::metric::name::MetricName;
/// use measured::metric::MetricFamilyEncoding;
/// use measured::text::BufferedTextEncoder;
///
/// // Define a fixed cardinality label
///
/// #[derive(FixedCardinalityLabel, Copy, Clone)]
/// enum Operation {
/// Create,
/// Update,
/// Delete,
/// }
///
/// // Define a label group, consisting of 1 or more label values
///
/// #[derive(LabelGroup)]
/// #[label(set = MyLabelGroupSet)]
/// struct MyLabelGroup {
/// operation: Operation,
/// }
///
/// // create a gauge vec
/// let gauges = FloatGaugeVec::with_label_set(MyLabelGroupSet::new());
/// // increment the gauge at a given label
/// gauges.inc(MyLabelGroup { operation: Operation::Create });
/// gauges.inc(MyLabelGroup { operation: Operation::Delete });
///
/// // sample the gauges and encode the values to a textual format.
/// let mut text_encoder = BufferedTextEncoder::new();
/// let name = MetricName::from_str("my_first_gauge");
/// gauges.collect_family_into(name, &mut text_encoder);
/// let bytes = text_encoder.finish();
/// ```
pub type FloatGaugeVec<L> = ;