Skip to content

Commit

Permalink
feat(minipipeline): add ControlFinalResponseExpectations (#1451)
Browse files Browse the repository at this point in the history
This PR adds the ControlFinalResponseExpectations field to
WebObservationsContainer. We need this field to determine whether
unexplained failures observed by the probe (i.e., failures occurring
during redirects) are to be expected (because for some reason also the
TH failed) or unexpected (because the TH succeeded).

Part of ooni/probe#2640.
  • Loading branch information
bassosimone committed Jan 18, 2024
1 parent 2f83da4 commit 0e44897
Show file tree
Hide file tree
Showing 70 changed files with 226 additions and 9 deletions.
3 changes: 3 additions & 0 deletions internal/cmd/minipipeline/testdata/observations.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,8 @@
},
"ControlHTTPResponseTitle": "Nexa Center for Internet \u0026 Society | Il centro Nexa è un centro di ricerca del Dipartimento di Automatica e Informatica del Politecnico di Torino"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
3 changes: 3 additions & 0 deletions internal/cmd/minipipeline/testdata/observations_classic.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,8 @@
},
"ControlHTTPResponseTitle": "Nexa Center for Internet \u0026 Society | Il centro Nexa è un centro di ricerca del Dipartimento di Automatica e Informatica del Politecnico di Torino"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
3 changes: 3 additions & 0 deletions internal/minipipeline/classic.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ func ClassicFilter(input *WebObservationsContainer) (output *WebObservationsCont
output.KnownTCPEndpoints[txid] = entry
}

// ControlFinalResponseExpectations
output.ControlFinalResponseExpectations = input.ControlFinalResponseExpectations

return
}
20 changes: 19 additions & 1 deletion internal/minipipeline/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ type WebObservation struct {
ControlHTTPResponseTitle optional.Value[string]
}

// WebObservationsControlFinalResponseExpectation summarizes the expectations
// on the final response based on what the control has observed.
type WebObservationsControlFinalResponseExpectation struct {
// Failure is the failure observed by the control when attempting
// to fetch the final webpage associated with a URL.
Failure optional.Value[string]
}

// WebObservationsContainer contains [*WebObservations].
//
// The zero value of this struct is not ready to use, please use [NewWebObservationsContainer].
Expand All @@ -273,6 +281,10 @@ type WebObservationsContainer struct {
// KnownTCPEndpoints maps transaction IDs to TCP observations.
KnownTCPEndpoints map[int64]*WebObservation

// ControlFinalResponseExpectations summarizes the expectations we have
// for the control based on the final response.
ControlFinalResponseExpectations optional.Value[*WebObservationsControlFinalResponseExpectation]

// knownIPAddresses is an internal field that maps an IP address to the
// corresponding DNS observation that discovered it.
knownIPAddresses map[string]*WebObservation
Expand Down Expand Up @@ -584,7 +596,6 @@ func (c *WebObservationsContainer) controlXrefTLSFailures(resp *model.THResponse
}

func (c *WebObservationsContainer) controlSetHTTPFinalResponseExpectation(resp *model.THResponse) {

// We need to set expectations for each type of observation. For example, to detect
// NXDOMAIN blocking with redirects when there's the expectation of success, we need
// to have the expectation inside the DNS-lookup-failure observation.
Expand All @@ -595,6 +606,13 @@ func (c *WebObservationsContainer) controlSetHTTPFinalResponseExpectation(resp *
observations = append(observations, obs)
}

// make sure we have a final expectation based on what the control observed, which
// is in turn necessary to figure out whether unexplained probe failures during redirects
// are expected or unexpected.
c.ControlFinalResponseExpectations = optional.Some(&WebObservationsControlFinalResponseExpectation{
Failure: optional.Some(utilsStringPointerToString(resp.HTTPRequest.Failure)),
})

for _, obs := range observations {
obs.ControlHTTPFailure = optional.Some(utilsStringPointerToString(resp.HTTPRequest.Failure))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
},
"ControlFinalResponseExpectations": {
"Failure": "unknown_error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
}
},
"ControlFinalResponseExpectations": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
}
},
"ControlFinalResponseExpectations": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
}
},
"ControlFinalResponseExpectations": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@
"ControlHTTPResponseHeadersKeys": null,
"ControlHTTPResponseTitle": null
}
}
},
"ControlFinalResponseExpectations": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
}
],
"DNSLookupSuccesses": [],
"KnownTCPEndpoints": {}
"KnownTCPEndpoints": {},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
}
],
"DNSLookupSuccesses": [],
"KnownTCPEndpoints": {}
"KnownTCPEndpoints": {},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,5 +359,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,5 +404,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,8 @@
},
"ControlHTTPResponseTitle": "Default Web Page"
}
},
"ControlFinalResponseExpectations": {
"Failure": ""
}
}
Loading

0 comments on commit 0e44897

Please sign in to comment.