Skip to content

Commit

Permalink
fix(webconnectivity@v0.5): include http transaction start/done (#943)
Browse files Browse the repository at this point in the history
Code based on urlgetter had this event and we would like to have this
event with step-by-step code as well.

Because there's no tracing for HTTP when using step-by-step, we will
need to include emitting these events inside the boilerplate.

By doing that, we emit events out of order, so make sure we sort
them by T, which is "the moment when the event was collected".

Part of ooni/probe#2238
  • Loading branch information
bassosimone authored Sep 8, 2022
1 parent 596eab4 commit 5ade2d9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/experiment/webconnectivity/cleartextflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func (t *CleartextFlow) httpTransaction(ctx context.Context, network, address, a
txp model.HTTPTransport, req *http.Request, trace *measurexlite.Trace) (*http.Response, []byte, error) {
const maxbody = 1 << 19
started := trace.TimeSince(trace.ZeroTime)
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index, started, "http_transaction_start",
))
resp, err := txp.RoundTrip(req)
var body []byte
if err == nil {
Expand All @@ -235,6 +238,9 @@ func (t *CleartextFlow) httpTransaction(ctx context.Context, network, address, a
body, err = netxlite.ReadAllContext(ctx, reader)
}
finished := trace.TimeSince(trace.ZeroTime)
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index, finished, "http_transaction_done",
))
ev := measurexlite.NewArchivalHTTPRequestResult(
trace.Index,
started,
Expand Down
6 changes: 6 additions & 0 deletions internal/experiment/webconnectivity/secureflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ func (t *SecureFlow) httpTransaction(ctx context.Context, network, address, alpn
txp model.HTTPTransport, req *http.Request, trace *measurexlite.Trace) (*http.Response, []byte, error) {
const maxbody = 1 << 19
started := trace.TimeSince(trace.ZeroTime)
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index, started, "http_transaction_start",
))
resp, err := txp.RoundTrip(req)
var body []byte
if err == nil {
Expand All @@ -287,6 +290,9 @@ func (t *SecureFlow) httpTransaction(ctx context.Context, network, address, alpn
body, err = netxlite.ReadAllContext(ctx, reader)
}
finished := trace.TimeSince(trace.ZeroTime)
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index, finished, "http_transaction_done",
))
ev := measurexlite.NewArchivalHTTPRequestResult(
trace.Index,
started,
Expand Down
6 changes: 6 additions & 0 deletions internal/experiment/webconnectivity/testkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package webconnectivity
//

import (
"sort"
"sync"

"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
Expand Down Expand Up @@ -328,4 +329,9 @@ func NewTestKeys() *TestKeys {
// must be called from the measurer after all the tasks have completed.
func (tk *TestKeys) Finalize(logger model.Logger) {
tk.analysisToplevel(logger)
// Note: sort.SliceStable is WAI when the input slice is nil
// as demonstrated by https://go.dev/play/p/znA4MyGFVHC
sort.SliceStable(tk.NetworkEvents, func(i, j int) bool {
return tk.NetworkEvents[i].T < tk.NetworkEvents[j].T
})
}

0 comments on commit 5ade2d9

Please sign in to comment.