-
Notifications
You must be signed in to change notification settings - Fork 1
/
write.go
51 lines (45 loc) · 1.02 KB
/
write.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
package wt
import (
"log"
"strconv"
"time"
"go.k6.io/k6/metrics"
)
func (c *Connection) Write(p []byte) {
n, err := c.activeStream.Write(p)
defer c.logWriteMetrics(n)
if err != nil {
log.Println("Write error: " + err.Error())
if n != len(p) {
log.Println("Wrote n: " + strconv.Itoa(n) + " bytes instead of the expected: " + strconv.Itoa(len(p)))
}
}
}
func (c *Connection) logWriteMetrics(n int) {
state := c.vu.State()
ctx := c.vu.Context()
if state == nil || ctx == nil {
return
}
now := time.Now()
metrics.PushIfNotDone(ctx, state.Samples, metrics.ConnectedSamples{
Samples: []metrics.Sample{
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.StreamsWriteCount},
Value: 1,
},
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.StreamsWriteBytes},
Value: float64(n),
},
{
Time: now,
TimeSeries: metrics.TimeSeries{Metric: c.metrics.StreamsWriteSize},
Value: float64(n),
},
},
Time: now,
})
}