From 8aad36a25718b5e237a56cfb0c0a13d44ff18a98 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 8 Jul 2022 17:04:31 +0200 Subject: [PATCH] feat(miniooni): introduce the --repeat-every command line flag (#819) Until OONI Run v2 has support for repeating the measurement with a schedule, introduce a command line flag requested by users to repeat a measurement every given number of seconds. Part of https://github.com/ooni/probe/issues/2184 --- internal/cmd/miniooni/libminiooni.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/cmd/miniooni/libminiooni.go b/internal/cmd/miniooni/libminiooni.go index d5103bd..934e83a 100644 --- a/internal/cmd/miniooni/libminiooni.go +++ b/internal/cmd/miniooni/libminiooni.go @@ -45,6 +45,7 @@ type Options struct { ProbeServicesURL string Proxy string Random bool + RepeatEvery int64 ReportFile string TorArgs []string TorBinary string @@ -104,6 +105,10 @@ func init() { getopt.FlagLong( &globalOptions.Random, "random", 0, "Randomize inputs", ) + getopt.FlagLong( + &globalOptions.RepeatEvery, "repeat-every", 0, + "Repeat the measurement every INTERVAL number of seconds", "INTERVAL", + ) getopt.FlagLong( &globalOptions.ReportFile, "reportfile", 'o', "Set the report file path", "PATH", @@ -283,7 +288,20 @@ func MainWithConfiguration(experimentName string, currentOptions Options) { currentOptions.ReportFile = "report.jsonl" } log.Log = logger + for { + mainSingleIteration(logger, experimentName, currentOptions) + if currentOptions.RepeatEvery <= 0 { + break + } + log.Infof("waiting %ds before repeating the measurement", currentOptions.RepeatEvery) + log.Info("use Ctrl-C to interrupt miniooni") + time.Sleep(time.Duration(currentOptions.RepeatEvery) * time.Second) + } +} +// mainSingleIteration runs a single iteration. There may be multiple iterations +// when the user specifies the --repeat-every command line flag. +func mainSingleIteration(logger model.Logger, experimentName string, currentOptions Options) { extraOptions := mustMakeMapAny(currentOptions.ExtraOptions) annotations := mustMakeMapString(currentOptions.Annotations)