github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/bootstrap-messages.go (about) 1 // Copyright (c) 2015-2023 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "context" 22 "sync" 23 24 "github.com/minio/madmin-go/v3" 25 "github.com/minio/minio/internal/pubsub" 26 ) 27 28 const bootstrapTraceLimit = 4 << 10 29 30 type bootstrapTracer struct { 31 mu sync.RWMutex 32 info []madmin.TraceInfo 33 } 34 35 var globalBootstrapTracer = &bootstrapTracer{} 36 37 func (bs *bootstrapTracer) Record(info madmin.TraceInfo) { 38 bs.mu.Lock() 39 defer bs.mu.Unlock() 40 41 if len(bs.info) > bootstrapTraceLimit { 42 return 43 } 44 bs.info = append(bs.info, info) 45 } 46 47 func (bs *bootstrapTracer) Events() []madmin.TraceInfo { 48 traceInfo := make([]madmin.TraceInfo, 0, bootstrapTraceLimit) 49 50 bs.mu.RLock() 51 for _, i := range bs.info { 52 traceInfo = append(traceInfo, i) 53 } 54 bs.mu.RUnlock() 55 56 return traceInfo 57 } 58 59 func (bs *bootstrapTracer) Publish(ctx context.Context, trace *pubsub.PubSub[madmin.TraceInfo, madmin.TraceType]) { 60 for _, bsEvent := range bs.Events() { 61 if bsEvent.Message != "" { 62 select { 63 case <-ctx.Done(): 64 default: 65 trace.Publish(bsEvent) 66 } 67 } 68 } 69 }