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(oonimkall): use richer-input-aware target loader #1620

Merged
merged 76 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
4ea29ff
refactor: make TargetLoader using ExperimentBuilder
bassosimone Jun 6, 2024
4beba37
x
bassosimone Jun 6, 2024
775c836
x
bassosimone Jun 6, 2024
4eb8147
x
bassosimone Jun 6, 2024
e38678d
x
bassosimone Jun 6, 2024
06d300f
x
bassosimone Jun 6, 2024
d490448
x
bassosimone Jun 6, 2024
a97bcd8
dnscheck
bassosimone Jun 6, 2024
1a57fd3
x
bassosimone Jun 6, 2024
c5b2d02
Merge remote-tracking branch 'origin/master' into issue/2607g
bassosimone Jun 6, 2024
399cf78
x
bassosimone Jun 6, 2024
34fe88f
x
bassosimone Jun 6, 2024
ed89561
x
bassosimone Jun 6, 2024
c9e55e7
x
bassosimone Jun 6, 2024
68f806d
x
bassosimone Jun 6, 2024
21baba0
x
bassosimone Jun 6, 2024
6a86d43
x
bassosimone Jun 6, 2024
8b710f6
cleanup(pkg/oonimkall): simplify test code
bassosimone Jun 7, 2024
c4f28d2
x
bassosimone Jun 7, 2024
a6bdeb7
x
bassosimone Jun 7, 2024
066c888
Merge branch 'master' into issue/2607h
bassosimone Jun 7, 2024
9c169e4
x
bassosimone Jun 7, 2024
c9c87a8
Merge branch 'issue/2607h' into issue/2607i
bassosimone Jun 7, 2024
5b71682
x
bassosimone Jun 19, 2024
6ba566c
Merge branch 'master' into issue/2607i
bassosimone Jun 19, 2024
f3c41bb
feat(oonirun): allow true JSON richer input
bassosimone Jun 26, 2024
4f183bd
x
bassosimone Jun 26, 2024
c6e19fe
Merge branch 'master' into issue/2607i
bassosimone Jun 26, 2024
52fe297
x
bassosimone Jun 26, 2024
b9390cf
x
bassosimone Jun 26, 2024
ca1cdc7
feat: correctly set options from richer input
bassosimone Jun 26, 2024
45a18b7
x
bassosimone Jun 26, 2024
50d1909
chore: add more tests for new code I wrote
bassosimone Jun 27, 2024
cf55bfb
x
bassosimone Jun 27, 2024
c6dacf7
x
bassosimone Jun 27, 2024
7621643
x
bassosimone Jun 27, 2024
4575f5e
x
bassosimone Jun 27, 2024
d1f243d
x
bassosimone Jun 27, 2024
21c62db
fix: make sure with testing experiment config is always a struct
bassosimone Jun 27, 2024
b8d219b
x
bassosimone Jun 27, 2024
d49c4db
x
bassosimone Jun 27, 2024
eed4d02
x
bassosimone Jun 27, 2024
0dd4e67
x
bassosimone Jun 27, 2024
8f507eb
x
bassosimone Jun 27, 2024
168e9bf
x
bassosimone Jun 27, 2024
bfc184f
x
bassosimone Jun 27, 2024
b94b224
Merge branch 'ri-multi-input' into ri-correctly-set-options
bassosimone Jun 27, 2024
eb94cc6
x
bassosimone Jun 27, 2024
43ef9bf
x
bassosimone Jun 27, 2024
6ca260c
x
bassosimone Jun 27, 2024
653e54b
x
bassosimone Jun 27, 2024
c5a70e8
x
bassosimone Jun 27, 2024
7f1a0c7
x
bassosimone Jun 27, 2024
bae5076
x
bassosimone Jun 27, 2024
9eeb1aa
x
bassosimone Jun 27, 2024
0005f1e
x
bassosimone Jun 27, 2024
620d4f9
x
bassosimone Jun 27, 2024
7b82000
x
bassosimone Jun 27, 2024
ddf00a7
x
bassosimone Jun 27, 2024
5229771
Merge remote-tracking branch 'origin/master' into ri-correctly-set-op…
bassosimone Jun 28, 2024
418ebbd
chore: update the living design document
bassosimone Jun 28, 2024
68496c4
Merge branch 'master' into issue/2607i
bassosimone Jun 28, 2024
d3e3b09
Merge branch 'master' into issue/2607i
bassosimone Jun 28, 2024
3aadc2a
chore: start addressing already-identified TODOs
bassosimone Jun 28, 2024
206eec2
Merge branch 'ri-correctly-set-options' into issue/2607i
bassosimone Jun 28, 2024
4ccbce3
doc: update the living design document
bassosimone Jun 28, 2024
325cf08
doc: document changes in this pull request
bassosimone Jun 28, 2024
5d8e033
Merge branch 'master' into issue/2607i
bassosimone Jun 28, 2024
c4675c5
doc: document the measurement algorithm
bassosimone Jun 28, 2024
6f1c8e9
chore: attempt to upgrade all tests
bassosimone Jun 28, 2024
59ee9ab
x
bassosimone Jun 28, 2024
9fdc61f
x
bassosimone Jun 28, 2024
5d34280
x
bassosimone Jun 28, 2024
d0f680a
x
bassosimone Jun 28, 2024
f736751
fix the test that was failing
bassosimone Jun 28, 2024
536f423
reference open issues
bassosimone Jun 28, 2024
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
107 changes: 104 additions & 3 deletions docs/design/dd-008-richer-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,106 @@ In practice, the code would always use either `InitialOptions` or
`ExtraOptions`, but we also wanted to specify priority in case both
of them were available.

## Implementation: oonimkall changes

In [#1620](https://github.com/ooni/probe-cli/pull/1620), we started to
modify the `./pkg/oonimkall` package to support richer input.

Before this diff, the code was not using a loader for loading targets
for experiments, and the code roughly looked like this:

```Go
switch builder.InputPolicy() {
case model.InputOrQueryBackend, model.InputStrictlyRequired:
if len(r.settings.Inputs) <= 0 {
r.emitter.EmitFailureStartup("no input provided")
return
}

case model.InputOrStaticDefault:
if len(r.settings.Inputs) <= 0 {
inputs, err := targetloading.StaticBareInputForExperiment(r.settings.Name)
if err != nil {
r.emitter.EmitFailureStartup("no default static input for this experiment")
return
}
r.settings.Inputs = inputs
}

case model.InputOptional:
if len(r.settings.Inputs) <= 0 {
r.settings.Inputs = append(r.settings.Inputs, "")
}

default: // treat this case as engine.InputNone.
if len(r.settings.Inputs) > 0 {
r.emitter.EmitFailureStartup("experiment does not accept input")
return
}
r.settings.Inputs = append(r.settings.Inputs, "")
}
```

Basically, we were switching on the experiment builder's `InputPolicy` and
checking whether input was present or absent according to policy. But, we were
not *actually* loading input when needed.

To support richer input for experiments such as `openvpn`, instead, we must
use a loader and fetch such input, as follows:

```Go
loader := builder.NewTargetLoader(&model.ExperimentTargetLoaderConfig{
CheckInConfig: &model.OOAPICheckInConfig{ /* not needed for now */ },
Session: sess,
StaticInputs: r.settings.Inputs,
SourceFiles: []string{},
})
loadCtx, loadCancel := context.WithTimeout(rootCtx, 30*time.Second)
defer loadCancel()
targets, err := loader.Load(loadCtx)
if err != nil {
r.emitter.EmitFailureStartup(err.Error())
return
}
```

After this change, we still assume the mobile app is providing us with
inputs for Web Connectivity. Because the loader honours user-provided inputs,
there's no functional change with the previous behavior. However, if there
is no input, we're going to load it using the proper mechanisms, including
using the correct backend API for the `openvpn` experiment.

Also, to pave the way for supporting loading for Web Connectivity as well, we
need to supply the information required to populate the URLs table as part
of the `status.measurement_start` event, as follows:

```diff
type eventMeasurementGeneric struct {
+ CategoryCode string `json:"category_code,omitempty"`
+ CountryCode string `json:"country_code,omitempty"`
Failure string `json:"failure,omitempty"`
Idx int64 `json:"idx"`
Input string `json:"input"`
JSONStr string `json:"json_str,omitempty"`
}


r.emitter.Emit(eventTypeStatusMeasurementStart, eventMeasurementGeneric{
+ CategoryCode: target.Category(),
+ CountryCode: target.Country(),
Idx: int64(idx),
Input: target.Input(),
})
```

By providing the `CategoryCode` and the `CountryCode`, the mobile app is now
able to correctly populate the URLs table ahead of measuring.

Future work will address passing the correct check-in options to the
experiment runner, so that we can actually remove the mobile app source
code that invokes the check-in API, and simplify both the codebase of
the mobile app and the one of `./pkg/oonimkall`.

## Next steps

This is a rough sequence of next steps that we should expand as we implement
Expand All @@ -466,11 +566,12 @@ than using the check-in API (and maybe keep the caching support?).
its own constructor for the proper target loader, and split the implementation
inside of the `targetloader` package to have multiple target loaders.

* rework `pkg/oonimkall` to invoke a target loader rather than relying
on the `InputPolicy`

* make sure richer-input-enabled experiments can run with `oonimkall`
after we have performed the previous change

* make sure we're passing the correct check-in settings to `oonimkall`
such that it's possible to run Web Connectivity from mobile using
the loader and we can simplify the mobile app codebase

* devise long term strategy for delivering richer input to `oonimkall`
from mobile apps, which we'll need as soon as we convert the IM experiments
15 changes: 3 additions & 12 deletions internal/targetloading/targetloading.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ var dnsCheckDefaultInput = []string{

var stunReachabilityDefaultInput = stuninput.AsnStunReachabilityInput()

// StaticBareInputForExperiment returns the list of strings an
// staticBareInputForExperiment returns the list of strings an
// experiment should use as static input. In case there is no
// static input for this experiment, we return an error.
func StaticBareInputForExperiment(name string) ([]string, error) {
func staticBareInputForExperiment(name string) ([]string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can become private because ./pkg/oonimkall does not need it anymore.

// Implementation note: we may be called from pkg/oonimkall
// with a non-canonical experiment name, so we need to convert
// the experiment name to be canonical before proceeding.
Expand All @@ -239,7 +239,7 @@ func StaticBareInputForExperiment(name string) ([]string, error) {
// staticInputForExperiment returns the static input for the given experiment
// or an error if there's no static input for the experiment.
func staticInputForExperiment(name string) ([]model.ExperimentTarget, error) {
return stringListToModelExperimentTarget(StaticBareInputForExperiment(name))
return stringListToModelExperimentTarget(staticBareInputForExperiment(name))
}

// loadOrStaticDefault implements the InputOrStaticDefault policy.
Expand Down Expand Up @@ -364,15 +364,6 @@ func (il *Loader) checkIn(
return &reply.Tests, nil
}

// fetchOpenVPNConfig fetches vpn information for the configured providers
func (il *Loader) fetchOpenVPNConfig(ctx context.Context, provider string) (*model.OOAPIVPNProviderConfig, error) {
reply, err := il.Session.FetchOpenVPNConfig(ctx, provider, "XX")
if err != nil {
return nil, err
}
return reply, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this function, since no-one else is using it.

// preventMistakes makes the code more robust with respect to any possible
// integration issue where the backend returns to us URLs that don't
// belong to the category codes we requested.
Expand Down
14 changes: 10 additions & 4 deletions pkg/oonimkall/taskmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ type eventLog struct {
}

type eventMeasurementGeneric struct {
Failure string `json:"failure,omitempty"`
Idx int64 `json:"idx"`
Input string `json:"input"`
JSONStr string `json:"json_str,omitempty"`
CategoryCode string `json:"category_code,omitempty"`
CountryCode string `json:"country_code,omitempty"`
Failure string `json:"failure,omitempty"`
Idx int64 `json:"idx"`
Input string `json:"input"`
JSONStr string `json:"json_str,omitempty"`
}

type eventStatusEnd struct {
Expand Down Expand Up @@ -314,4 +316,8 @@ type settingsOptions struct {
// SoftwareVersion is the software version. If this option is not
// present, then the library startup will fail.
SoftwareVersion string `json:"software_version,omitempty"`

// TODO(https://github.com/ooni/probe/issues/2767): to support OONI Run v2 descriptors with
// richer input from mobile, here we also need a string-serialization
// of the descriptor options to load.
}
Loading
Loading