@@ -10,7 +10,9 @@ use super::gauge::Gauge;
1010use super :: label:: LabelSet ;
1111use super :: metric:: { Metric , MetricName } ;
1212use super :: prometheus:: PrometheusSerializable ;
13+ use crate :: metric:: description:: MetricDescription ;
1314use crate :: sample_collection:: SampleCollection ;
15+ use crate :: unit:: Unit ;
1416
1517#[ derive( Debug , Default ) ]
1618pub struct Metrics {
@@ -27,6 +29,16 @@ impl Metrics {
2729
2830 // Counter-specific methods
2931
32+ /// # Panics
33+ ///
34+ /// Panics if it can't get write access to the inner collection.
35+ pub fn describe_counter ( & mut self , name : & MetricName , _opt_unit : Option < Unit > , _opt_description : Option < MetricDescription > ) {
36+ self . inner . write ( ) . unwrap ( ) . counters . ensure_metric_exists ( name) ;
37+ }
38+
39+ /// It allows to describe a counter metric so the metrics appear in the JSON
40+ /// response even if there are no samples yet.
41+ ///
3042 /// # Panics
3143 ///
3244 /// Panics if it can't get read access to the inner collection.
@@ -44,6 +56,16 @@ impl Metrics {
4456
4557 // Gauge-specific methods
4658
59+ /// It allows to describe a gauge metric so the metrics appear in the JSON
60+ /// response even if there are no samples yet.
61+ ///
62+ /// # Panics
63+ ///
64+ /// Panics if it can't get write access to the inner collection.
65+ pub fn describe_gauge ( & mut self , name : & MetricName , _opt_unit : Option < Unit > , _opt_description : Option < MetricDescription > ) {
66+ self . inner . write ( ) . unwrap ( ) . gauges . ensure_metric_exists ( name) ;
67+ }
68+
4769 /// # Panics
4870 ///
4971 /// Panics if it can't get read access to the inner collection.
@@ -89,6 +111,10 @@ impl MetricCollection {
89111
90112 // Counter-specific methods
91113
114+ pub fn describe_counter ( & mut self , name : & MetricName , _opt_unit : Option < Unit > , _opt_description : Option < MetricDescription > ) {
115+ self . counters . ensure_metric_exists ( name) ;
116+ }
117+
92118 #[ must_use]
93119 pub fn get_counter_value ( & self , name : & MetricName , labels : & LabelSet ) -> Counter {
94120 self . counters . get_value ( name, labels)
@@ -108,6 +134,10 @@ impl MetricCollection {
108134
109135 // Gauge-specific methods
110136
137+ pub fn describe_gauge ( & mut self , name : & MetricName , _opt_unit : Option < Unit > , _opt_description : Option < MetricDescription > ) {
138+ self . gauges . ensure_metric_exists ( name) ;
139+ }
140+
111141 #[ must_use]
112142 pub fn get_gauge_value ( & self , name : & MetricName , labels : & LabelSet ) -> Gauge {
113143 self . gauges . get_value ( name, labels)
0 commit comments