48
48
C : RunnableConfig ,
49
49
{
50
50
let health_port = config. health_check_port ;
51
+ let additional_labels = config. metrics_config . additional_labels . clone ( ) ;
51
52
// Start liveness and readiness probes.
52
53
let task_handler = handle. spawn ( async move {
53
- register_probes_and_metrics_handler ( health_port) . await ;
54
+ register_probes_and_metrics_handler ( health_port, additional_labels ) . await ;
54
55
anyhow:: Ok ( ( ) )
55
56
} ) ;
56
57
let main_task_handler = handle. spawn ( async move { config. run ( ) . await } ) ;
@@ -69,10 +70,19 @@ pub struct GenericConfig<T> {
69
70
// Shared configuration among all services.
70
71
pub health_check_port : u16 ,
71
72
73
+ #[ serde( default ) ]
74
+ pub metrics_config : MetricsConfig ,
75
+
72
76
// Specific configuration for each service.
73
77
pub server_config : T ,
74
78
}
75
79
80
+ #[ derive( Clone , Deserialize , Debug , Default , Serialize ) ]
81
+ pub struct MetricsConfig {
82
+ /// Additional labels to use for metrics.
83
+ pub additional_labels : Vec < ( String , String ) > ,
84
+ }
85
+
76
86
#[ async_trait:: async_trait]
77
87
impl < T > RunnableConfig for GenericConfig < T >
78
88
where
@@ -158,8 +168,15 @@ pub fn setup_logging() {
158
168
}
159
169
160
170
/// Register readiness and liveness probes and set up metrics endpoint.
161
- pub async fn register_probes_and_metrics_handler ( port : u16 ) {
162
- let mut registry = <Registry >:: default ( ) ;
171
+ pub async fn register_probes_and_metrics_handler (
172
+ port : u16 ,
173
+ additional_labels : Vec < ( String , String ) > ,
174
+ ) {
175
+ let mut registry = Registry :: with_labels (
176
+ additional_labels
177
+ . into_iter ( )
178
+ . map ( |( k, v) | ( k. into ( ) , v. into ( ) ) ) ,
179
+ ) ;
163
180
init_step_metrics_registry ( & mut registry) ;
164
181
init_channel_metrics_registry ( & mut registry) ;
165
182
AutometricsSettings :: builder ( )
0 commit comments