@@ -17,7 +17,7 @@ export class PrometheusMetricsExporter {
17
17
protected readonly clusterCordoned : prom . Gauge < string > ;
18
18
protected readonly statusUpdatesTotal : prom . Counter < string > ;
19
19
20
- protected activeClusterNames : string [ ] = [ ] ;
20
+ protected activeClusterNames = new Set < string > ( ) ;
21
21
22
22
constructor ( ) {
23
23
this . workspaceStartupTimeHistogram = new prom . Histogram ( {
@@ -69,18 +69,18 @@ export class PrometheusMetricsExporter {
69
69
}
70
70
71
71
updateClusterMetrics ( clusters : WorkspaceClusterWoTLS [ ] ) : void {
72
- let newActiveClusterNames : string [ ] = [ ] ;
72
+ let newActiveClusterNames = new Set < string > ( ) ;
73
73
clusters . forEach ( cluster => {
74
74
this . clusterCordoned . labels ( cluster . name ) . set ( cluster . state === 'cordoned' ? 1 : 0 ) ;
75
75
this . clusterScore . labels ( cluster . name ) . set ( cluster . score ) ;
76
- newActiveClusterNames . push ( cluster . name ) ;
76
+ newActiveClusterNames . add ( cluster . name ) ;
77
77
} ) ;
78
78
79
- const noLongerActiveCluster = this . activeClusterNames . filter ( c => ! newActiveClusterNames . includes ( c ) ) ;
80
- if ( noLongerActiveCluster . length > 0 ) {
81
- this . clusterScore . remove ( ... noLongerActiveCluster ) ;
82
- this . clusterCordoned . remove ( ... noLongerActiveCluster ) ;
83
- }
79
+ const noLongerActiveCluster = Array . from ( this . activeClusterNames ) . filter ( c => ! newActiveClusterNames . has ( c ) ) ;
80
+ noLongerActiveCluster . forEach ( clusterName => {
81
+ this . clusterCordoned . remove ( clusterName ) ;
82
+ this . clusterScore . remove ( clusterName ) ;
83
+ } ) ;
84
84
this . activeClusterNames = newActiveClusterNames ;
85
85
}
86
86
0 commit comments