fix: crash in ResourceMetrics RPC handling concurrent writers (#19123)

Continuation of #19103 that had fixed the crash in peer metrics for cluster endpoint.
This commit is contained in:
Harshavardhana
2024-02-25 00:51:38 -08:00
committed by GitHub
parent b49ce1713f
commit 8a698fef71
2 changed files with 39 additions and 31 deletions

View File

@@ -242,26 +242,6 @@ func (client *peerRESTClient) GetMetrics(ctx context.Context, t madmin.MetricTyp
return v.ValueOrZero(), err
}
func (client *peerRESTClient) GetResourceMetrics(ctx context.Context) (<-chan Metric, error) {
st, err := getResourceMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
if err != nil {
return nil, err
}
ch := make(chan Metric, 1)
go func(ch chan<- Metric) {
defer close(ch)
st.Results(func(metric *Metric) error {
select {
case <-ctx.Done():
return ctx.Err()
case ch <- *metric:
return nil
}
})
}(ch)
return ch, nil
}
// GetProcInfo - fetch MinIO process information for a remote node.
func (client *peerRESTClient) GetProcInfo(ctx context.Context) (info madmin.ProcInfo, err error) {
resp, err := getProcInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS())
@@ -661,6 +641,28 @@ func (client *peerRESTClient) MonitorBandwidth(ctx context.Context, buckets []st
return getBandwidthRPC.Call(ctx, client.gridConn(), values)
}
func (client *peerRESTClient) GetResourceMetrics(ctx context.Context) (<-chan Metric, error) {
resp, err := getResourceMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
if err != nil {
return nil, err
}
ch := make(chan Metric)
go func(ch chan<- Metric) {
defer close(ch)
for _, m := range resp.Value() {
if m == nil {
continue
}
select {
case <-ctx.Done():
return
case ch <- *m:
}
}
}(ch)
return ch, nil
}
func (client *peerRESTClient) GetPeerMetrics(ctx context.Context) (<-chan Metric, error) {
resp, err := getPeerMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS())
if err != nil {