fix(webconnectivity@v0.5): include http transaction start/done (#943)

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 https://github.com/ooni/probe/issues/2238
This commit is contained in:
Simone Basso 2022-09-08 10:37:08 +02:00 committed by GitHub
parent 596eab4a42
commit 5ade2d9568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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
})
}