Structured output of measurements

This commit is contained in:
Arturo Filastò 2018-09-10 18:03:32 +02:00
parent 53791076c9
commit 1637fdbf93
6 changed files with 33 additions and 11 deletions

View File

@ -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)

View File

@ -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",

View File

@ -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"`

View File

@ -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

View File

@ -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

View File

@ -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) {