1616@dataclass (slots = True , kw_only = True )
1717class MetricsBase :
1818 subsystem : str
19+ registry : CollectorRegistry
1920
2021
2122@dataclass (slots = True , kw_only = True )
@@ -36,7 +37,12 @@ def __post_init__(self) -> None:
3637 cluster_subsystem = f"{ self .subsystem } _cluster"
3738 # Creating and assigning gauges using the field names and the metric definitions
3839 for field_name , definition in CLUSTER_METRICS_DEFINITIONS .items ():
39- gauge = create_gauge (field_name , definition , cluster_subsystem )
40+ gauge = create_gauge (
41+ field_name = field_name ,
42+ definition = definition ,
43+ subsystem = cluster_subsystem ,
44+ registry = self .registry ,
45+ )
4046 setattr (self , field_name , gauge )
4147
4248 def update_from_cluster (self , cluster : Cluster ) -> None :
@@ -65,27 +71,31 @@ def __post_init__(self) -> None:
6571 labelnames = EC2_INSTANCE_LABELS ,
6672 namespace = METRICS_NAMESPACE ,
6773 subsystem = self .subsystem ,
74+ registry = self .registry ,
6875 )
6976 self .started_instances = Counter (
7077 "started_instances_total" ,
7178 "Number of EC2 instances that were started" ,
7279 labelnames = EC2_INSTANCE_LABELS ,
7380 namespace = METRICS_NAMESPACE ,
7481 subsystem = self .subsystem ,
82+ registry = self .registry ,
7583 )
7684 self .stopped_instances = Counter (
7785 "stopped_instances_total" ,
7886 "Number of EC2 instances that were stopped" ,
7987 labelnames = EC2_INSTANCE_LABELS ,
8088 namespace = METRICS_NAMESPACE ,
8189 subsystem = self .subsystem ,
90+ registry = self .registry ,
8291 )
8392 self .terminated_instances = Counter (
8493 "terminated_instances_total" ,
8594 "Number of EC2 instances that were terminated" ,
8695 labelnames = EC2_INSTANCE_LABELS ,
8796 namespace = METRICS_NAMESPACE ,
8897 subsystem = self .subsystem ,
98+ registry = self .registry ,
8999 )
90100
91101 def instance_started (self , instance_type : str ) -> None :
@@ -123,7 +133,12 @@ def __post_init__(self) -> None:
123133 setattr (
124134 self ,
125135 field_name ,
126- create_gauge (field_name , definition , buffer_pools_subsystem ),
136+ create_gauge (
137+ field_name = field_name ,
138+ definition = definition ,
139+ subsystem = buffer_pools_subsystem ,
140+ registry = self .registry ,
141+ ),
127142 )
128143 self .instances_ready_to_pull_seconds = Histogram (
129144 "instances_ready_to_pull_duration_seconds" ,
@@ -132,6 +147,7 @@ def __post_init__(self) -> None:
132147 namespace = METRICS_NAMESPACE ,
133148 subsystem = buffer_pools_subsystem ,
134149 buckets = (10 , 20 , 30 , 40 , 50 , 60 , 120 ),
150+ registry = self .registry ,
135151 )
136152 self .instances_completed_pulling_seconds = Histogram (
137153 "instances_completed_pulling_duration_seconds" ,
@@ -150,6 +166,7 @@ def __post_init__(self) -> None:
150166 30 * _MINUTE ,
151167 40 * _MINUTE ,
152168 ),
169+ registry = self .registry ,
153170 )
154171
155172 def update_from_buffer_pool_manager (
@@ -174,8 +191,12 @@ class AutoscalingInstrumentation(MetricsBase):
174191 buffer_machines_pools_metrics : BufferPoolsMetrics = field (init = False )
175192
176193 def __post_init__ (self ) -> None :
177- self .cluster_metrics = ClusterMetrics (subsystem = self .subsystem )
178- self .ec2_client_metrics = EC2ClientMetrics (subsystem = self .subsystem )
194+ self .cluster_metrics = ClusterMetrics (
195+ subsystem = self .subsystem , registry = self .registry
196+ )
197+ self .ec2_client_metrics = EC2ClientMetrics (
198+ subsystem = self .subsystem , registry = self .registry
199+ )
179200 self .buffer_machines_pools_metrics = BufferPoolsMetrics (
180- subsystem = self .subsystem
201+ subsystem = self .subsystem , registry = self . registry
181202 )
0 commit comments