diff --git a/internal/cli/list/list.go b/internal/cli/list/list.go index 13ef534..fdf93ff 100644 --- a/internal/cli/list/list.go +++ b/internal/cli/list/list.go @@ -27,8 +27,8 @@ func init() { log.WithError(err).Error("failed to list measurements") return err } - for idx, msmt := range measurements { - fmt.Printf("%d: %v\n", idx, msmt) + for _, msmt := range measurements { + output.MeasurementItem(msmt) } } else { doneResults, incompleteResults, err := database.ListResults(ctx.DB) diff --git a/internal/database/actions.go b/internal/database/actions.go index 6cfd1f9..2fe12c6 100644 --- a/internal/database/actions.go +++ b/internal/database/actions.go @@ -18,6 +18,7 @@ func ListMeasurements(sess sqlbuilder.Database, resultID int64) ([]MeasurementUR measurements := []MeasurementURLNetwork{} req := sess.Select( + "measurements.id as msmt_tbl_id", "networks.id as network_id", "results.id as result_id", "urls.id as url_id", diff --git a/internal/database/models.go b/internal/database/models.go index 83b2226..60c510b 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -22,6 +22,7 @@ type ResultNetwork struct { // MeasurementURLNetwork is used for the JOIN between Measurement and URL type MeasurementURLNetwork struct { Measurement `db:",inline"` + MsmtTblID int64 `db:"msmt_tbl_id"` Network `db:",inline"` NetworkID int64 `db:"network_id"` URL `db:",inline"` diff --git a/internal/log/handlers/cli/cli.go b/internal/log/handlers/cli/cli.go index 0aa718d..8e4c2ec 100644 --- a/internal/log/handlers/cli/cli.go +++ b/internal/log/handlers/cli/cli.go @@ -136,10 +136,10 @@ func (h *Handler) DefaultLog(e *log.Entry) error { if name == "source" { continue } - s += fmt.Sprintf(" %s=%s", color.Sprint(name), e.Fields.Get(name)) + s += fmt.Sprintf(" %s=%v", color.Sprint(name), e.Fields.Get(name)) } - fmt.Fprintf(h.Writer, s) + fmt.Fprint(h.Writer, s) fmt.Fprintln(h.Writer) return nil diff --git a/internal/output/output.go b/internal/output/output.go index 7d6bf77..0e6a214 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -7,6 +7,7 @@ import ( "time" "github.com/apex/log" + "github.com/ooni/probe-cli/internal/database" "github.com/ooni/probe-cli/internal/util" ) @@ -19,6 +20,32 @@ func Progress(key string, perc float64, msg string) { }).Info(msg) } +// MeasurementItem logs a progress type event +func MeasurementItem(msmt database.MeasurementURLNetwork) { + log.WithFields(log.Fields{ + "type": "measurement_item", + "id": msmt.MsmtTblID, + "test_name": msmt.TestName, + "start_time": msmt.StartTime, + "test_keys": msmt.TestKeys, + "probe_cc": msmt.Network.CountryCode, + "network_name": msmt.Network.NetworkName, + "asn": msmt.Network.ASN, + "runtime": msmt.Runtime, + "url": msmt.URL.URL, + "url_category_code": msmt.URL.CategoryCode, + "url_country_code": msmt.URL.CountryCode, + "is_anomaly": msmt.IsAnomaly, + "is_uploaded": msmt.IsUploaded, + "is_upload_failed": msmt.IsUploadFailed, + "upload_failure_msg": msmt.UploadFailureMsg.String, + "is_failed": msmt.IsFailed, + "failure_msg": msmt.FailureMsg.String, + "is_done": msmt.IsDone, + "report_file_path": msmt.ReportFilePath, + }).Info("measurement") +} + // ResultItemData is the metadata about a result type ResultItemData struct { ID int64 diff --git a/nettests/nettests.go b/nettests/nettests.go index 899acfd..bb0a176 100644 --- a/nettests/nettests.go +++ b/nettests/nettests.go @@ -172,13 +172,6 @@ func (c *Controller) Init(nt *mk.Nettest) error { nt.On("status.geoip_lookup", func(e mk.Event) { log.Debugf(color.RedString(e.Key)) - - /* FIXME - Put this into the network table - msmtTemplate.ASN = e.Value.ProbeASN - msmtTemplate.IP = e.Value.ProbeIP - msmtTemplate.CountryCode = e.Value.ProbeCC - */ }) nt.On("status.measurement_start", func(e mk.Event) {