Skip to content

Commit

Permalink
Fix metric timings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <[email protected]>
  • Loading branch information
dgzlopes committed Sep 30, 2021
1 parent 5bb984f commit 1efb25b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
k6
k6
vendor
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/onsi/gomega v1.10.5 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/prometheus v1.8.2-0.20210621150501-ff58416a0b02
github.com/xhit/go-str2duration/v2 v2.0.0 // indirect
github.com/xhit/go-str2duration/v2 v2.0.0
go.k6.io/k6 v0.32.0
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
12 changes: 7 additions & 5 deletions remote_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ func (c *Client) Store(ctx context.Context, ts []Timeseries) (http.Response, err
return http.Response{}, errors.New("State is nil")
}

now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RemoteWriteNumSeries,
Time: time.Time{},
Time: now,
Value: float64(len(batch)),
})

Expand Down Expand Up @@ -134,16 +135,17 @@ func (c *Client) send(ctx context.Context, state *lib.State, req []byte) (http.R
defer cancel()

httpReq = httpReq.WithContext(ctx)
now := time.Now()

stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RemoteWriteReqs,
Time: time.Time{},
Time: now,
Value: float64(1),
})

stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: metrics.DataSent,
Time: time.Time{},
Time: now,
Value: float64(binary.Size(req)),
})

Expand All @@ -156,14 +158,14 @@ func (c *Client) send(ctx context.Context, state *lib.State, req []byte) (http.R

stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RemoteWriteReqDuration,
Time: time.Time{},
Time: now,
Value: float64(elapsed.Milliseconds()),
})

if httpResp.StatusCode != http.StatusOK {
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RemoteWriteReqFailed,
Time: time.Time{},
Time: now,
Value: float64(1),
})
}
Expand Down

0 comments on commit 1efb25b

Please sign in to comment.