@@ -71,34 +71,32 @@ func New(opts *options.Options, kubeClient kubernetes.Interface, storeBuilder ks
71
71
72
72
// ReconfigureSharding reconfigures sharding with the current shard and totalShards, and
73
73
// it's a no-op if both values are 0.
74
- func (m * MetricsHandler ) ReconfigureSharding (ctx context.Context ) {
75
- m .mtx .RLock ()
76
- hasShardsSet := m . curShard != 0 || m . curTotalShards != 0
77
- m . mtx . RUnlock ()
78
- if ! hasShardsSet {
79
- return
74
+ func (m * MetricsHandler ) BuildWriters (ctx context.Context ) {
75
+ m .mtx .Lock ()
76
+ defer m . mtx . Unlock ()
77
+
78
+ if m . cancel != nil {
79
+ m . cancel ()
80
80
}
81
- m .ConfigureSharding (ctx , m .curShard , m .curTotalShards )
81
+ ctx , m .cancel = context .WithCancel (ctx )
82
+ m .storeBuilder .WithContext (ctx )
83
+ m .metricsWriters = m .storeBuilder .Build ()
82
84
}
83
85
84
86
// ConfigureSharding configures sharding. Configuration can be used mutlitple times and
85
87
// concurrently.
86
88
func (m * MetricsHandler ) ConfigureSharding (ctx context.Context , shard int32 , totalShards int ) {
87
89
m .mtx .Lock ()
88
- defer m .mtx .Unlock ()
89
90
90
- if m .cancel != nil {
91
- m .cancel ()
92
- }
93
91
if totalShards != 1 {
94
92
klog .InfoS ("Configuring sharding of this instance to be shard index (zero-indexed) out of total shards" , "shard" , shard , "totalShards" , totalShards )
95
93
}
96
- ctx , m .cancel = context .WithCancel (ctx )
97
- m .storeBuilder .WithSharding (shard , totalShards )
98
- m .storeBuilder .WithContext (ctx )
99
- m .metricsWriters = m .storeBuilder .Build ()
100
94
m .curShard = shard
101
95
m .curTotalShards = totalShards
96
+ m .storeBuilder .WithSharding (shard , totalShards )
97
+ m .mtx .Unlock ()
98
+
99
+ m .BuildWriters (ctx )
102
100
}
103
101
104
102
// Run configures the MetricsHandler's sharding and if autosharding is enabled
0 commit comments