Commit ec243b8b authored by Tsaiilin's avatar Tsaiilin

trace 日志采样

parent 06bd0e54
package trace
import (
"sync/atomic"
"time"
"github.com/adamweixuan/getty"
"go.uber.org/zap"
"time"
"virjar.com/majora-go/log"
)
......@@ -117,10 +120,30 @@ func (r *RecorderImpl) Enable() bool {
var defaultNopRecorder = NopRecorder{}
var slots = make([]int64, 30)
func AcquireRecorder(sessionId string) Recorder {
return &RecorderImpl{
sessionId: sessionId,
now := time.Now()
slotIndex := now.Minute() / 2
timeMinute := now.Unix() / 60
slot := &slots[slotIndex]
slotTime := atomic.LoadInt64(slot)
if slotTime == timeMinute {
return &defaultNopRecorder
}
if atomic.CompareAndSwapInt64(slot, slotTime, timeMinute) {
return &RecorderImpl{sessionId: sessionId}
}
return &defaultNopRecorder
}
type slot struct {
time int64
recorder Recorder
}
type Session struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment