2023-03-17 19:01:03 -04:00
|
|
|
// Copyright (c) 2015-2023 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
|
2023-06-19 20:53:08 -04:00
|
|
|
"github.com/minio/madmin-go/v3"
|
2023-03-17 19:01:03 -04:00
|
|
|
"github.com/minio/minio/internal/pubsub"
|
|
|
|
)
|
|
|
|
|
2023-08-23 06:07:06 -04:00
|
|
|
const bootstrapTraceLimit = 4 << 10
|
2023-03-17 19:01:03 -04:00
|
|
|
|
|
|
|
type bootstrapTracer struct {
|
2023-08-23 06:07:06 -04:00
|
|
|
mu sync.RWMutex
|
|
|
|
info []madmin.TraceInfo
|
2023-03-17 19:01:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var globalBootstrapTracer = &bootstrapTracer{}
|
|
|
|
|
2023-08-23 06:07:06 -04:00
|
|
|
func (bs *bootstrapTracer) Record(info madmin.TraceInfo) {
|
2023-03-17 19:01:03 -04:00
|
|
|
bs.mu.Lock()
|
|
|
|
defer bs.mu.Unlock()
|
|
|
|
|
2023-08-23 06:07:06 -04:00
|
|
|
if len(bs.info) > bootstrapTraceLimit {
|
|
|
|
return
|
2023-03-17 19:01:03 -04:00
|
|
|
}
|
2023-08-23 06:07:06 -04:00
|
|
|
bs.info = append(bs.info, info)
|
2023-03-17 19:01:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bs *bootstrapTracer) Events() []madmin.TraceInfo {
|
2023-08-23 06:07:06 -04:00
|
|
|
traceInfo := make([]madmin.TraceInfo, 0, bootstrapTraceLimit)
|
2023-03-17 19:01:03 -04:00
|
|
|
|
|
|
|
bs.mu.RLock()
|
2023-08-23 06:07:06 -04:00
|
|
|
for _, i := range bs.info {
|
|
|
|
traceInfo = append(traceInfo, i)
|
|
|
|
}
|
2023-03-17 19:01:03 -04:00
|
|
|
bs.mu.RUnlock()
|
2023-08-23 06:07:06 -04:00
|
|
|
|
2023-03-17 19:01:03 -04:00
|
|
|
return traceInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bs *bootstrapTracer) Publish(ctx context.Context, trace *pubsub.PubSub[madmin.TraceInfo, madmin.TraceType]) {
|
|
|
|
for _, bsEvent := range bs.Events() {
|
2023-08-23 06:07:06 -04:00
|
|
|
if bsEvent.Message != "" {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
default:
|
|
|
|
trace.Publish(bsEvent)
|
|
|
|
}
|
2023-03-17 19:01:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|