From 01b46a5e9f8fffa6751777e9f680afd89095112e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A1lez=20Lopes?= Date: Fri, 1 Oct 2021 13:29:53 +0200 Subject: [PATCH] Make data_sent work on the cloud MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel González Lopes --- remote_write.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/remote_write.go b/remote_write.go index f79252e..60d2c01 100644 --- a/remote_write.go +++ b/remote_write.go @@ -18,6 +18,7 @@ import ( "go.k6.io/k6/js/modules" "go.k6.io/k6/lib" "go.k6.io/k6/lib/metrics" + "go.k6.io/k6/lib/netext" "go.k6.io/k6/stats" ) @@ -143,11 +144,19 @@ func (c *Client) send(ctx context.Context, state *lib.State, req []byte) (http.R Value: float64(1), }) - stats.PushIfNotDone(ctx, state.Samples, stats.Sample{ - Metric: metrics.DataSent, - Time: now, - Value: float64(binary.Size(req)), - }) + simpleNetTrail := netext.NetTrail{ + BytesWritten: int64(binary.Size(req)), + StartTime: now.Add(-time.Minute), + EndTime: now, + Samples: []stats.Sample{ + { + Time: now, + Metric: metrics.DataSent, + Value: float64(binary.Size(req)), + }, + }, + } + stats.PushIfNotDone(ctx, state.Samples, &simpleNetTrail) start := time.Now() httpResp, err := c.client.Do(httpReq)