Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dslx): remove Observations from Maybe #1385

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 4 additions & 6 deletions internal/dslx/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func DNSLookupGetaddrinfo(rt Runtime) Func[*DomainToResolve, *ResolvedAddresses]
}

return &Maybe[*ResolvedAddresses]{
Error: err,
Observations: maybeTraceToObservations(trace),
State: state,
Error: err,
State: state,
}
})
}
Expand Down Expand Up @@ -158,9 +157,8 @@ func DNSLookupUDP(rt Runtime, endpoint string) Func[*DomainToResolve, *ResolvedA
}

return &Maybe[*ResolvedAddresses]{
Error: err,
Observations: maybeTraceToObservations(trace),
State: state,
Error: err,
State: state,
}
})
}
23 changes: 8 additions & 15 deletions internal/dslx/fxcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ type Operation[A, B any] func(ctx context.Context, a A) *Maybe[B]
func (op Operation[A, B]) Apply(ctx context.Context, a *Maybe[A]) *Maybe[B] {
if a.Error != nil {
return &Maybe[B]{
Error: a.Error,
Observations: a.Observations,
State: *new(B), // zero value
Error: a.Error,
State: *new(B), // zero value
}
}
return op(ctx, a.State)
Expand All @@ -36,9 +35,6 @@ type Maybe[State any] struct {
// Error is either the error that occurred or nil.
Error error

// Observations contains the collected observations.
Observations []*Observations

// State contains state passed between function calls. You should
// only access State when Error is nil and Skipped is false.
State State
Expand All @@ -47,9 +43,8 @@ type Maybe[State any] struct {
// NewMaybeWithValue constructs a Maybe containing the given value.
func NewMaybeWithValue[State any](value State) *Maybe[State] {
return &Maybe[State]{
Error: nil,
Observations: []*Observations{},
State: value,
Error: nil,
State: value,
}
}

Expand All @@ -74,18 +69,16 @@ func (h *compose2Func[A, B, C]) Apply(ctx context.Context, a *Maybe[A]) *Maybe[C

if mb.Error != nil {
return &Maybe[C]{
Error: mb.Error,
Observations: mb.Observations,
State: *new(C), // zero value
Error: mb.Error,
State: *new(C), // zero value
}
}

mc := h.g.Apply(ctx, mb)
runtimex.Assert(mc != nil, "h.g.Apply returned a nil pointer")

return &Maybe[C]{
Error: mc.Error,
Observations: append(mb.Observations, mc.Observations...), // merge observations
State: mc.State,
Error: mc.Error,
State: mc.State,
}
}
13 changes: 2 additions & 11 deletions internal/dslx/fxcore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ func (f *fn) Apply(ctx context.Context, i *Maybe[int]) *Maybe[int] {
return &Maybe[int]{
Error: f.err,
State: i.State + 1,
Observations: []*Observations{
{
NetworkEvents: []*model.ArchivalNetworkEvent{{Tags: []string{"apply"}}},
},
},
}
}

Expand All @@ -50,9 +45,8 @@ func TestStageAdapter(t *testing.T) {

// create input that contains an error
input := &Maybe[*DomainToResolve]{
Error: errors.New("mocked error"),
Observations: []*Observations{},
State: nil,
Error: errors.New("mocked error"),
State: nil,
}

// run the pipeline
Expand Down Expand Up @@ -91,9 +85,6 @@ func TestCompose2(t *testing.T) {
if r.Error != tt.err {
t.Fatalf("unexpected error")
}
if len(r.Observations) != tt.numObs {
t.Fatalf("unexpected number of (merged) observations")
}
})
}
})
Expand Down
5 changes: 2 additions & 3 deletions internal/dslx/httpcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ func HTTPRequest(rt Runtime, options ...HTTPRequestOption) Func[*HTTPConnection,
}

return &Maybe[*HTTPResponse]{
Error: err,
Observations: observations,
State: state,
Error: err,
State: state,
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/dslx/httpquic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ func HTTPConnectionQUIC(rt Runtime) Func[*QUICConnection, *HTTPConnection] {
Transport: httpTransport,
}
return &Maybe[*HTTPConnection]{
Error: nil,
Observations: nil,
State: state,
Error: nil,
State: state,
}
})
}
5 changes: 2 additions & 3 deletions internal/dslx/httptcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func HTTPConnectionTCP(rt Runtime) Func[*TCPConnection, *HTTPConnection] {
Transport: httpTransport,
}
return &Maybe[*HTTPConnection]{
Error: nil,
Observations: nil,
State: state,
Error: nil,
State: state,
}
})
}
5 changes: 2 additions & 3 deletions internal/dslx/httptls.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func HTTPConnectionTLS(rt Runtime) Func[*TLSConnection, *HTTPConnection] {
Transport: httpTransport,
}
return &Maybe[*HTTPConnection]{
Error: nil,
Observations: nil,
State: state,
Error: nil,
State: state,
}
})
}
5 changes: 2 additions & 3 deletions internal/dslx/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ func QUICHandshake(rt Runtime, options ...TLSHandshakeOption) Func[*Endpoint, *Q
}

return &Maybe[*QUICConnection]{
Error: err,
Observations: maybeTraceToObservations(trace),
State: state,
Error: err,
State: state,
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/dslx/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ func TCPConnect(rt Runtime) Func[*Endpoint, *TCPConnection] {
}

return &Maybe[*TCPConnection]{
Error: err,
Observations: maybeTraceToObservations(trace),
State: state,
Error: err,
State: state,
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/dslx/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func TLSHandshake(rt Runtime, options ...TLSHandshakeOption) Func[*TCPConnection
}

return &Maybe[*TLSConnection]{
Error: err,
Observations: maybeTraceToObservations(trace),
State: state,
Error: err,
State: state,
}
})
}
Expand Down
29 changes: 0 additions & 29 deletions internal/tutorial/dslx/chapter02/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,6 @@ type Subresult struct {

```

Subresult.mergeObservations merges the observations collected during
a measurement with the Subresult output data format.

```Go

func (tk *Subresult) mergeObservations(obs []*dslx.Observations) {
for _, o := range obs {
tk.NetworkEvents = append(tk.NetworkEvents, o.NetworkEvents...)
tk.TCPConnect = append(tk.TCPConnect, o.TCPConnect...)
tk.TLSHandshakes = append(tk.TLSHandshakes, o.TLSHandshakes...)
}
}

```

## The Measurer

The `Measurer` performs the measurement and implements `ExperimentMeasurer`; i.e., the
Expand Down Expand Up @@ -429,20 +414,6 @@ Store the control failure if any.

```

The measurement result not only contains the potential error, but also
observations that have been collected during each step of the measurement pipeline.
Observations are for example network events like read and write operations,
TLS handshakes, or DNS queries. We as experiment programmers are responsible for
extracting these observations from the dslx measurement result and storing
them in the `TestKeys`, which is precisely what `Subresult.mergeObservations`
(implemented above) does.

```Go
tk.Target.mergeObservations(targetResult.Observations)
tk.Control.mergeObservations(controlResult.Observations)

```

### Return

Finally, we can return, as the measurement ran successfully.
Expand Down
29 changes: 0 additions & 29 deletions internal/tutorial/dslx/chapter02/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ type Subresult struct {
Cached bool `json:"-"`
}

// ```
//
// Subresult.mergeObservations merges the observations collected during
// a measurement with the Subresult output data format.
//
// ```Go

func (tk *Subresult) mergeObservations(obs []*dslx.Observations) {
for _, o := range obs {
tk.NetworkEvents = append(tk.NetworkEvents, o.NetworkEvents...)
tk.TCPConnect = append(tk.TCPConnect, o.TCPConnect...)
tk.TLSHandshakes = append(tk.TLSHandshakes, o.TLSHandshakes...)
}
}

// ```
//
// ## The Measurer
Expand Down Expand Up @@ -428,20 +413,6 @@ func (m *Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
tk.Control.Failure = &failure
}

// ```
//
// The measurement result not only contains the potential error, but also
// observations that have been collected during each step of the measurement pipeline.
// Observations are for example network events like read and write operations,
// TLS handshakes, or DNS queries. We as experiment programmers are responsible for
// extracting these observations from the dslx measurement result and storing
// them in the `TestKeys`, which is precisely what `Subresult.mergeObservations`
// (implemented above) does.
//
// ```Go
tk.Target.mergeObservations(targetResult.Observations)
tk.Control.mergeObservations(controlResult.Observations)

// ```
//
// ### Return
Expand Down