-
Notifications
You must be signed in to change notification settings - Fork 0
/
correlation.go
77 lines (64 loc) · 1.96 KB
/
correlation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package logger
import (
"sync"
"github.com/ThotaGopichandThota/gn-logger1/proto"
)
var globalCorrelation logCorrelation
// logCorrelation holds log correlation elements
type logCorrelation struct {
mut sync.RWMutex
enabled bool
shard string
epoch uint32
round int64
subRound string
}
// ToggleCorrelation enables or disables correlation elements for log lines
func ToggleCorrelation(enable bool) {
globalCorrelation.mut.Lock()
globalCorrelation.enabled = enable
globalCorrelation.mut.Unlock()
}
// IsEnabledCorrelation returns whether correlation elements are enabled
func IsEnabledCorrelation() bool {
globalCorrelation.mut.RLock()
enabled := globalCorrelation.enabled
globalCorrelation.mut.RUnlock()
return enabled
}
// SetCorrelationShard sets the current shard ID as a log correlation element
func SetCorrelationShard(shardID string) {
globalCorrelation.mut.Lock()
globalCorrelation.shard = shardID
globalCorrelation.mut.Unlock()
}
// SetCorrelationEpoch sets the current epoch as a log correlation element
func SetCorrelationEpoch(epoch uint32) {
globalCorrelation.mut.Lock()
globalCorrelation.epoch = epoch
globalCorrelation.mut.Unlock()
}
// SetCorrelationRound sets the current round as a log correlation element
func SetCorrelationRound(round int64) {
globalCorrelation.mut.Lock()
globalCorrelation.round = round
globalCorrelation.mut.Unlock()
}
// SetCorrelationSubround sets the current sub-round as a log correlation element
func SetCorrelationSubround(subRound string) {
globalCorrelation.mut.Lock()
globalCorrelation.subRound = subRound
globalCorrelation.mut.Unlock()
}
// GetCorrelation gets global correlation elements
func GetCorrelation() proto.LogCorrelationMessage {
globalCorrelation.mut.RLock()
lcm := proto.LogCorrelationMessage{
Shard: globalCorrelation.shard,
Epoch: globalCorrelation.epoch,
Round: globalCorrelation.round,
SubRound: globalCorrelation.subRound,
}
globalCorrelation.mut.RUnlock()
return lcm
}