Skip to content

Commit 2c4addd

Browse files
committed
Fix go-vet warning about mutex copying
1 parent 64b7478 commit 2c4addd

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

receiver/base.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ type Base struct {
2828
pastDropped uint64 // atomic
2929
tooLongDropped uint64 // atomic
3030
}
31-
droppedList [droppedListSize]string
32-
droppedListNext int
33-
droppedListMu sync.Mutex
34-
parseThreads int
35-
dropFutureSeconds uint32
36-
dropPastSeconds uint32
37-
dropTooLongLimit uint16
31+
droppedList [droppedListSize]string
32+
droppedListNext int
33+
droppedListMu sync.Mutex
34+
parseThreads int
35+
dropFutureSeconds uint32
36+
dropPastSeconds uint32
37+
dropTooLongLimit uint16
3838
readTimeoutSeconds uint32
39-
writeChan chan *RowBinary.WriteBuffer
40-
logger *zap.Logger
41-
Tags tags.TagConfig
42-
concatCharacter string
39+
writeChan chan *RowBinary.WriteBuffer
40+
logger *zap.Logger
41+
Tags tags.TagConfig
42+
concatCharacter string
4343
}
4444

4545
func NewBase(logger *zap.Logger, config tags.TagConfig) Base {
@@ -56,6 +56,12 @@ func sendInt64Gauge(send func(metric string, value float64), metric string, valu
5656
send(metric, float64(atomic.LoadInt64(value)))
5757
}
5858

59+
func (base *Base) applyOptions(opts ...Option) {
60+
for _, applyOption := range opts {
61+
applyOption(base)
62+
}
63+
}
64+
5965
func (base *Base) isDrop(nowTime uint32, metricTime uint32) bool {
6066
if base.dropFutureSeconds != 0 && (metricTime > (nowTime + base.dropFutureSeconds)) {
6167
atomic.AddUint64(&base.stat.futureDropped, 1)

receiver/receiver.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
9797
return nil, err
9898
}
9999

100-
base := NewBase(zapwriter.Logger(strings.Replace(u.Scheme, "+", "_", -1)), config)
101-
102-
for _, optApply := range opts {
103-
optApply(&base)
104-
}
100+
logger := zapwriter.Logger(strings.Replace(u.Scheme, "+", "_", -1))
105101

106102
if u.Scheme == "tcp" {
107103
addr, err := net.ResolveTCPAddr("tcp", u.Host)
@@ -110,9 +106,10 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
110106
}
111107

112108
r := &TCP{
113-
Base: base,
109+
Base: NewBase(logger, config),
114110
parseChan: make(chan *Buffer),
115111
}
112+
r.applyOptions(opts...)
116113

117114
if err = r.Listen(addr); err != nil {
118115
return nil, err
@@ -128,9 +125,10 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
128125
}
129126

130127
r := &Pickle{
131-
Base: base,
128+
Base: NewBase(logger, config),
132129
parseChan: make(chan []byte),
133130
}
131+
r.applyOptions(opts...)
134132

135133
if err = r.Listen(addr); err != nil {
136134
return nil, err
@@ -146,9 +144,10 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
146144
}
147145

148146
r := &UDP{
149-
Base: base,
147+
Base: NewBase(logger, config),
150148
parseChan: make(chan *Buffer),
151149
}
150+
r.applyOptions(opts...)
152151

153152
if err = r.Listen(addr); err != nil {
154153
return nil, err
@@ -164,8 +163,9 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
164163
}
165164

166165
r := &GRPC{
167-
Base: base,
166+
Base: NewBase(logger, config),
168167
}
168+
r.applyOptions(opts...)
169169

170170
if err = r.Listen(addr); err != nil {
171171
return nil, err
@@ -181,8 +181,9 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
181181
}
182182

183183
r := &PrometheusRemoteWrite{
184-
Base: base,
184+
Base: NewBase(logger, config),
185185
}
186+
r.applyOptions(opts...)
186187

187188
if err = r.Listen(addr); err != nil {
188189
return nil, err
@@ -198,8 +199,9 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
198199
}
199200

200201
r := &TelegrafHttpJson{
201-
Base: base,
202+
Base: NewBase(logger, config),
202203
}
204+
r.applyOptions(opts...)
203205

204206
if err = r.Listen(addr); err != nil {
205207
return nil, err

0 commit comments

Comments
 (0)