Skip to content

Commit 236ce51

Browse files
committed
use atomic add for total bytes value
Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 1eaff5e commit 236ce51

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

scaletest/workspacetraffic/metrics.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package workspacetraffic
22

3-
import "github.com/prometheus/client_golang/prometheus"
3+
import (
4+
"sync/atomic"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
48

59
type Metrics struct {
610
BytesReadTotal prometheus.CounterVec
@@ -75,7 +79,7 @@ type ConnMetrics interface {
7579
AddError(float64)
7680
ObserveLatency(float64)
7781
AddTotal(float64)
78-
GetTotal() int64
82+
GetTotalBytes() int64
7983
}
8084

8185
type connMetrics struct {
@@ -94,10 +98,10 @@ func (c *connMetrics) ObserveLatency(f float64) {
9498
}
9599

96100
func (c *connMetrics) AddTotal(f float64) {
97-
c.total += int64(f)
101+
atomic.AddInt64(&c.total, int64(f))
98102
c.addTotal(f)
99103
}
100104

101-
func (c *connMetrics) GetTotal() int64 {
105+
func (c *connMetrics) GetTotalBytes() int64 {
102106
return c.total
103107
}

scaletest/workspacetraffic/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
211211
}
212212

213213
func (r *Runner) GetBytesTransferred() (bytesRead, bytesWritten int64) {
214-
bytesRead = r.cfg.ReadMetrics.GetTotal()
215-
bytesWritten = r.cfg.WriteMetrics.GetTotal()
214+
bytesRead = r.cfg.ReadMetrics.GetTotalBytes()
215+
bytesWritten = r.cfg.WriteMetrics.GetTotalBytes()
216216
return bytesRead, bytesWritten
217217
}
218218

scaletest/workspacetraffic/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,6 @@ func (m *testMetrics) Latencies() []float64 {
423423
return m.latencies
424424
}
425425

426-
func (m *testMetrics) GetTotal() int64 {
426+
func (m *testMetrics) GetTotalBytes() int64 {
427427
return int64(m.total)
428428
}

0 commit comments

Comments
 (0)