feat(ooniprobe): introduce websites_max_runtime (#273)
We cannot control anymore the maximum number of URLs using the API because now we are using check-in, that has no such limit. We could theoretically clamp the number of URLs to measure after the call to check-in, and still honour the setting. Yet, the right thing to do seems to introduce a max runtime variable because that is what desktop and mobile do. Thus, introduce code that warns the user about the change in the settings, should they have set the URL limit to nonzero. We are going to do a best effort conversion from the URL limit to the maximum runtime for the rest of 2021. Since then, we will silently ignore the URL limit. This work is part of https://github.com/ooni/probe/issues/1299.
This commit is contained in:
parent
a0763756b2
commit
c264f61536
|
@ -1,38 +1,5 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
var websiteCategories = []string{
|
|
||||||
"ALDR",
|
|
||||||
"ANON",
|
|
||||||
"COMM",
|
|
||||||
"COMT",
|
|
||||||
"CTRL",
|
|
||||||
"CULTR",
|
|
||||||
"DATE",
|
|
||||||
"ECON",
|
|
||||||
"ENV",
|
|
||||||
"FILE",
|
|
||||||
"GAME",
|
|
||||||
"GMB",
|
|
||||||
"GOVT",
|
|
||||||
"GRP",
|
|
||||||
"HACK",
|
|
||||||
"HATE",
|
|
||||||
"HOST",
|
|
||||||
"HUMR",
|
|
||||||
"IGO",
|
|
||||||
"LGBT",
|
|
||||||
"MILX",
|
|
||||||
"MMED",
|
|
||||||
"NEWS",
|
|
||||||
"POLR",
|
|
||||||
"PORN",
|
|
||||||
"PROV",
|
|
||||||
"PUBH",
|
|
||||||
"REL",
|
|
||||||
"SRCH",
|
|
||||||
"XED",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sharing settings
|
// Sharing settings
|
||||||
type Sharing struct {
|
type Sharing struct {
|
||||||
UploadResults bool `json:"upload_results"`
|
UploadResults bool `json:"upload_results"`
|
||||||
|
@ -45,6 +12,7 @@ type Advanced struct {
|
||||||
|
|
||||||
// Nettests related settings
|
// Nettests related settings
|
||||||
type Nettests struct {
|
type Nettests struct {
|
||||||
|
WebsitesMaxRuntime int64 `json:"websites_max_runtime"`
|
||||||
WebsitesURLLimit int64 `json:"websites_url_limit"`
|
WebsitesURLLimit int64 `json:"websites_url_limit"`
|
||||||
WebsitesEnabledCategoryCodes []string `json:"websites_enabled_category_codes"`
|
WebsitesEnabledCategoryCodes []string `json:"websites_enabled_category_codes"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"upload_results": true
|
"upload_results": true
|
||||||
},
|
},
|
||||||
"nettests": {
|
"nettests": {
|
||||||
"websites_url_limit": 0
|
"websites_max_runtime": 0
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
"send_crash_reports": true
|
"send_crash_reports": true
|
||||||
|
|
|
@ -111,10 +111,16 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ntStartTime = time.Now()
|
maxRuntime := time.Duration(c.Probe.Config().Nettests.WebsitesMaxRuntime) * time.Second
|
||||||
|
start := time.Now()
|
||||||
|
c.ntStartTime = start
|
||||||
for idx, input := range inputs {
|
for idx, input := range inputs {
|
||||||
if c.Probe.IsTerminated() == true {
|
if c.Probe.IsTerminated() {
|
||||||
log.Debug("isTerminated == true, breaking the input loop")
|
log.Info("user requested us to terminate using Ctrl-C")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if maxRuntime > 0 && time.Since(start) > maxRuntime {
|
||||||
|
log.Info("exceeded maximum runtime")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c.curInputIdx = idx // allow for precise progress
|
c.curInputIdx = idx // allow for precise progress
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package nettests
|
package nettests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/database"
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/database"
|
||||||
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
|
||||||
|
@ -15,9 +17,36 @@ type RunGroupConfig struct {
|
||||||
Inputs []string
|
Inputs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const websitesURLLimitRemoved = `WARNING: CONFIGURATION CHANGE REQUIRED:
|
||||||
|
|
||||||
|
* Since ooniprobe 3.9.0, websites_url_limit has been replaced
|
||||||
|
by websites_max_runtime in the configuration
|
||||||
|
|
||||||
|
* To silence this warning either set websites_url_limit to zero or
|
||||||
|
replace it with websites_max_runtime
|
||||||
|
|
||||||
|
* For the rest of 2021, we will automatically convert websites_url_limit
|
||||||
|
to websites_max_runtime (if the latter is not already set)
|
||||||
|
|
||||||
|
* We will consider that each URL in websites_url_limit takes five
|
||||||
|
seconds to run and thus calculate websites_max_runtime
|
||||||
|
|
||||||
|
* Since 2022, we will start silently ignoring websites_url_limit
|
||||||
|
`
|
||||||
|
|
||||||
// RunGroup runs a group of nettests according to the specified config.
|
// RunGroup runs a group of nettests according to the specified config.
|
||||||
func RunGroup(config RunGroupConfig) error {
|
func RunGroup(config RunGroupConfig) error {
|
||||||
if config.Probe.IsTerminated() == true {
|
if config.Probe.Config().Nettests.WebsitesURLLimit > 0 {
|
||||||
|
log.Warn(websitesURLLimitRemoved)
|
||||||
|
if config.Probe.Config().Nettests.WebsitesMaxRuntime <= 0 {
|
||||||
|
limit := config.Probe.Config().Nettests.WebsitesURLLimit
|
||||||
|
maxRuntime := 5 * limit
|
||||||
|
config.Probe.Config().Nettests.WebsitesMaxRuntime = maxRuntime
|
||||||
|
}
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Probe.IsTerminated() {
|
||||||
log.Debugf("context is terminated, stopping runNettestGroup early")
|
log.Debugf("context is terminated, stopping runNettestGroup early")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,10 @@ import (
|
||||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO(bassosimone): we should remove the limit argument and
|
|
||||||
// we should also remove it from the config.
|
|
||||||
|
|
||||||
// TODO(bassosimone): we should propagate the kind of run
|
// TODO(bassosimone): we should propagate the kind of run
|
||||||
// to here such that we get the right runType.
|
// to here such that we get the right runType.
|
||||||
|
|
||||||
// TODO(bassosimone): we are breaking the use case in which
|
func lookupURLs(ctl *Controller, categories []string) ([]string, map[int64]int64, error) {
|
||||||
// someone choose the number of URLs explicitly via the config.
|
|
||||||
|
|
||||||
func lookupURLs(ctl *Controller, limit int64, categories []string) ([]string, map[int64]int64, error) {
|
|
||||||
inputloader := &engine.InputLoader{
|
inputloader := &engine.InputLoader{
|
||||||
CheckInConfig: &model.CheckInConfig{
|
CheckInConfig: &model.CheckInConfig{
|
||||||
WebConnectivity: model.CheckInConfigWebConnectivity{
|
WebConnectivity: model.CheckInConfigWebConnectivity{
|
||||||
|
@ -53,13 +47,12 @@ func lookupURLs(ctl *Controller, limit int64, categories []string) ([]string, ma
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebConnectivity test implementation
|
// WebConnectivity test implementation
|
||||||
type WebConnectivity struct {
|
type WebConnectivity struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Run starts the test
|
// Run starts the test
|
||||||
func (n WebConnectivity) Run(ctl *Controller) error {
|
func (n WebConnectivity) Run(ctl *Controller) error {
|
||||||
log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
||||||
urls, urlIDMap, err := lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesURLLimit, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
urls, urlIDMap, err := lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"upload_results": true
|
"upload_results": true
|
||||||
},
|
},
|
||||||
"nettests": {
|
"nettests": {
|
||||||
"websites_url_limit": 0
|
"websites_max_runtime": 0
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
"send_crash_reports": true
|
"send_crash_reports": true
|
||||||
|
|
2
cmd/ooniprobe/testdata/testing-config.json
vendored
2
cmd/ooniprobe/testdata/testing-config.json
vendored
|
@ -5,7 +5,7 @@
|
||||||
"upload_results": true
|
"upload_results": true
|
||||||
},
|
},
|
||||||
"nettests": {
|
"nettests": {
|
||||||
"websites_url_limit": 10
|
"websites_max_runtime": 15
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
"send_crash_reports": true
|
"send_crash_reports": true
|
||||||
|
|
2
debian/ooniprobe.conf.disabled
vendored
2
debian/ooniprobe.conf.disabled
vendored
|
@ -6,7 +6,7 @@
|
||||||
"upload_results": true
|
"upload_results": true
|
||||||
},
|
},
|
||||||
"nettests": {
|
"nettests": {
|
||||||
"websites_url_limit": 0,
|
"websites_max_runtime": 0,
|
||||||
"websites_enabled_category_codes": null
|
"websites_enabled_category_codes": null
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user