Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use vu.Context when pushing metrics
Previously, the browser implementation components, such as browser,
page, frame... were holding a context inherited from the vu.context
because the browser lifecycle was tight to it. Therefore, we were
passing these contexts when calling k6metrics.PushIfNotDone, as if that
context was done, it meant that the VU context was also done and at the
same time the VU metrics samples channel was closed. With the current
implementation, because the browser, page, frame... contexts do not
inherit from the VU.context, we can not use these contexts when calling
k6metrics.PushIfNotDone, as it is not a guarantee that the vu samples
channel is open, so we should use the VU context directly.
  • Loading branch information
ka3de committed Jun 1, 2023
commit 65e9ff36712bf4d1812b2a686da17dadb03b03b4
2 changes: 1 addition & 1 deletion common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (fs *FrameSession) parseAndEmitWebVitalMetric(object string) error {
}

now := time.Now()
k6metrics.PushIfNotDone(fs.ctx, state.Samples, k6metrics.ConnectedSamples{
k6metrics.PushIfNotDone(fs.vu.Context(), state.Samples, k6metrics.ConnectedSamples{
Samples: []k6metrics.Sample{
{
TimeSeries: k6metrics.TimeSeries{Metric: metric, Tags: tags},
Expand Down
6 changes: 3 additions & 3 deletions common/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (m *NetworkManager) emitRequestMetrics(req *Request) {
tags = tags.With("url", req.URL())
}

k6metrics.PushIfNotDone(m.ctx, state.Samples, k6metrics.ConnectedSamples{
k6metrics.PushIfNotDone(m.vu.Context(), state.Samples, k6metrics.ConnectedSamples{
Samples: []k6metrics.Sample{
{
TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserDataSent, Tags: tags},
Expand Down Expand Up @@ -221,7 +221,7 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) {
tags = tags.With("from_prefetch_cache", strconv.FormatBool(fromPreCache))
tags = tags.With("from_service_worker", strconv.FormatBool(fromSvcWrk))

k6metrics.PushIfNotDone(m.ctx, state.Samples, k6metrics.ConnectedSamples{
k6metrics.PushIfNotDone(m.vu.Context(), state.Samples, k6metrics.ConnectedSamples{
Samples: []k6metrics.Sample{
{
TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqs, Tags: tags},
Expand All @@ -242,7 +242,7 @@ func (m *NetworkManager) emitResponseMetrics(resp *Response, req *Request) {
})

if resp != nil && resp.timing != nil {
k6metrics.PushIfNotDone(m.ctx, state.Samples, k6metrics.ConnectedSamples{
k6metrics.PushIfNotDone(m.vu.Context(), state.Samples, k6metrics.ConnectedSamples{
Samples: []k6metrics.Sample{
{
TimeSeries: k6metrics.TimeSeries{Metric: m.customMetrics.BrowserHTTPReqConnecting, Tags: tags},
Expand Down