fix(ooniprobe): consistent progress with maxRuntime (#277)

See https://github.com/ooni/probe/issues/1299
This commit is contained in:
Simone Basso 2021-03-31 14:06:05 +02:00 committed by GitHub
parent 4e344f1fcf
commit 969d8b772f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -68,6 +68,7 @@ func init() {
Probe: probe, Probe: probe,
InputFiles: *inputFile, InputFiles: *inputFile,
Inputs: *input, Inputs: *input,
RunType: "manual",
}) })
}) })

View File

@ -212,8 +212,18 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err
// OnProgress should be called when a new progress event is available. // OnProgress should be called when a new progress event is available.
func (c *Controller) OnProgress(perc float64, msg string) { func (c *Controller) OnProgress(perc float64, msg string) {
// TODO(bassosimone): should we adjust this algorithm when we have a // when we have maxRuntime, honor it
// maximum runtime that we would like to honor? maxRuntime := time.Duration(c.Probe.Config().Nettests.WebsitesMaxRuntime) * time.Second
if c.RunType == "manual" && maxRuntime > 0 {
elapsed := time.Since(c.ntStartTime)
perc = float64(elapsed) / float64(maxRuntime)
eta := maxRuntime.Seconds() - elapsed.Seconds()
log.Debugf("OnProgress: %f - %s", perc, msg)
key := fmt.Sprintf("%T", c.nt)
output.Progress(key, perc, eta, msg)
return
}
// otherwise estimate the ETA
log.Debugf("OnProgress: %f - %s", perc, msg) log.Debugf("OnProgress: %f - %s", perc, msg)
var eta float64 var eta float64
eta = -1.0 eta = -1.0