diff --git a/internal/experiment/webconnectivity/cleartextflow.go b/internal/experiment/webconnectivity/cleartextflow.go index a1712d8a61..bae9859c73 100644 --- a/internal/experiment/webconnectivity/cleartextflow.go +++ b/internal/experiment/webconnectivity/cleartextflow.go @@ -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 { @@ -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, diff --git a/internal/experiment/webconnectivity/secureflow.go b/internal/experiment/webconnectivity/secureflow.go index dd837d356e..ee19242e2a 100644 --- a/internal/experiment/webconnectivity/secureflow.go +++ b/internal/experiment/webconnectivity/secureflow.go @@ -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 { @@ -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, diff --git a/internal/experiment/webconnectivity/testkeys.go b/internal/experiment/webconnectivity/testkeys.go index 9518943efa..4db7f3e71f 100644 --- a/internal/experiment/webconnectivity/testkeys.go +++ b/internal/experiment/webconnectivity/testkeys.go @@ -8,6 +8,7 @@ package webconnectivity // import ( + "sort" "sync" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" @@ -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 + }) }