Skip to content

Commit

Permalink
Fix go-vet warning about mutex copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Sep 29, 2021
1 parent 64b7478 commit 2c4addd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 17 additions & 11 deletions receiver/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ type Base struct {
pastDropped uint64 // atomic
tooLongDropped uint64 // atomic
}
droppedList [droppedListSize]string
droppedListNext int
droppedListMu sync.Mutex
parseThreads int
dropFutureSeconds uint32
dropPastSeconds uint32
dropTooLongLimit uint16
droppedList [droppedListSize]string
droppedListNext int
droppedListMu sync.Mutex
parseThreads int
dropFutureSeconds uint32
dropPastSeconds uint32
dropTooLongLimit uint16
readTimeoutSeconds uint32
writeChan chan *RowBinary.WriteBuffer
logger *zap.Logger
Tags tags.TagConfig
concatCharacter string
writeChan chan *RowBinary.WriteBuffer
logger *zap.Logger
Tags tags.TagConfig
concatCharacter string
}

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

func (base *Base) applyOptions(opts ...Option) {
for _, applyOption := range opts {
applyOption(base)
}
}

func (base *Base) isDrop(nowTime uint32, metricTime uint32) bool {
if base.dropFutureSeconds != 0 && (metricTime > (nowTime + base.dropFutureSeconds)) {
atomic.AddUint64(&base.stat.futureDropped, 1)
Expand Down
24 changes: 13 additions & 11 deletions receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ func New(dsn string, config tags.TagConfig, opts ...Option) (Receiver, error) {
return nil, err
}

base := NewBase(zapwriter.Logger(strings.Replace(u.Scheme, "+", "_", -1)), config)

for _, optApply := range opts {
optApply(&base)
}
logger := zapwriter.Logger(strings.Replace(u.Scheme, "+", "_", -1))

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

r := &TCP{
Base: base,
Base: NewBase(logger, config),
parseChan: make(chan *Buffer),
}
r.applyOptions(opts...)

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

r := &Pickle{
Base: base,
Base: NewBase(logger, config),
parseChan: make(chan []byte),
}
r.applyOptions(opts...)

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

r := &UDP{
Base: base,
Base: NewBase(logger, config),
parseChan: make(chan *Buffer),
}
r.applyOptions(opts...)

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

r := &GRPC{
Base: base,
Base: NewBase(logger, config),
}
r.applyOptions(opts...)

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

r := &PrometheusRemoteWrite{
Base: base,
Base: NewBase(logger, config),
}
r.applyOptions(opts...)

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

r := &TelegrafHttpJson{
Base: base,
Base: NewBase(logger, config),
}
r.applyOptions(opts...)

if err = r.Listen(addr); err != nil {
return nil, err
Expand Down

0 comments on commit 2c4addd

Please sign in to comment.