From 0ee0c2812973145ce02f39257dfd17922884b3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Tue, 11 Sep 2018 18:06:15 +0200 Subject: [PATCH] Resolve country code ambigious selection --- internal/cli/list/list.go | 6 ++-- internal/database/actions.go | 2 ++ internal/database/models.go | 21 ++++++++----- internal/log/handlers/cli/results.go | 2 +- internal/output/output.go | 46 ++++++++++++++-------------- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/internal/cli/list/list.go b/internal/cli/list/list.go index 371ff90..9d4e0a8 100644 --- a/internal/cli/list/list.go +++ b/internal/cli/list/list.go @@ -1,8 +1,6 @@ package list import ( - "fmt" - "github.com/alecthomas/kingpin" "github.com/apex/log" "github.com/ooni/probe-cli/internal/cli/root" @@ -71,7 +69,7 @@ func init() { StartTime: result.StartTime, NetworkName: result.Network.NetworkName, Country: result.Network.CountryCode, - ASN: fmt.Sprintf("AS%d", result.Network.ASN), + ASN: result.Network.ASN, MeasurementCount: 0, MeasurementAnomalyCount: 0, TestKeys: "{}", // FIXME this used to be Summary we probably need to use a list now @@ -101,7 +99,7 @@ func init() { StartTime: result.StartTime, NetworkName: result.Network.NetworkName, Country: result.Network.CountryCode, - ASN: fmt.Sprintf("AS%d", result.Network.ASN), + ASN: result.Network.ASN, TestKeys: testKeys, MeasurementCount: totalCount, MeasurementAnomalyCount: anmlyCount, diff --git a/internal/database/actions.go b/internal/database/actions.go index ddfa07e..ba36145 100644 --- a/internal/database/actions.go +++ b/internal/database/actions.go @@ -23,12 +23,14 @@ func ListMeasurements(sess sqlbuilder.Database, resultID int64) ([]MeasurementUR "measurements.start_time as measurement_start_time", "measurements.runtime as measurement_runtime", "networks.id as network_id", + "networks.country_code as network_country_code", "results.id as result_id", "results.start_time as result_start_time", "results.is_done as result_is_done", "results.runtime as result_runtime", "results.test_group_name as test_group_name", "urls.id as url_id", + "urls.country_code as url_country_code", db.Raw("networks.*"), db.Raw("urls.*"), db.Raw("measurements.*"), diff --git a/internal/database/models.go b/internal/database/models.go index 9fb103d..fbbb982 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -26,14 +26,19 @@ type MeasurementURLNetwork struct { MeasurementIsDone bool `db:"measurement_is_done"` MeasurementRuntime float64 `db:"measurement_runtime"` MsmtTblID int64 `db:"msmt_tbl_id"` - Network `db:",inline"` - NetworkID int64 `db:"network_id"` - Result `db:",inline"` - ResultID int64 `db:"result_id"` - ResultRuntime float64 `db:"result_runtime"` - ResultStartTime time.Time `db:"result_start_time"` - ResultIsDone bool `db:"result_is_done"` - URL `db:",inline"` + + Network `db:",inline"` + NetworkID int64 `db:"network_id"` + NetworkCountryCode string `db:"network_country_code"` + + Result `db:",inline"` + ResultID int64 `db:"result_id"` + ResultRuntime float64 `db:"result_runtime"` + ResultStartTime time.Time `db:"result_start_time"` + ResultIsDone bool `db:"result_is_done"` + + URL `db:",inline"` + URLCountryCode sql.NullString `db:"url_country_code"` } // Network represents a network tested by the user diff --git a/internal/log/handlers/cli/results.go b/internal/log/handlers/cli/results.go index d22398a..887117a 100644 --- a/internal/log/handlers/cli/results.go +++ b/internal/log/handlers/cli/results.go @@ -77,7 +77,7 @@ func logResultItem(w io.Writer, f log.Fields) error { name := f.Get("name").(string) startTime := f.Get("start_time").(time.Time) networkName := f.Get("network_name").(string) - asn := fmt.Sprintf("AS %s", f.Get("asn").(string)) + asn := fmt.Sprintf("AS%d (%s)", f.Get("asn").(uint), f.Get("country").(string)) //runtime := f.Get("runtime").(float64) //dataUsageUp := f.Get("dataUsageUp").(int64) //dataUsageDown := f.Get("dataUsageDown").(int64) diff --git a/internal/output/output.go b/internal/output/output.go index fac6faf..bbd139d 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -42,27 +42,27 @@ func MeasurementSummary(msmt MeasurementSummaryData) { // 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, - "test_group_name": msmt.Result.TestGroupName, - "start_time": msmt.MeasurementStartTime, - "test_keys": msmt.TestKeys, - "probe_cc": msmt.Network.CountryCode, - "network_name": msmt.Network.NetworkName, - "asn": msmt.Network.ASN, - "runtime": msmt.MeasurementRuntime, - "url": msmt.URL.URL.String, - "url_category_code": msmt.URL.CategoryCode.String, - "url_country_code": msmt.URL.CountryCode.String, - "is_anomaly": msmt.IsAnomaly.Bool, - "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.MeasurementIsDone, - "report_file_path": msmt.ReportFilePath, + "type": "measurement_item", + "id": msmt.MsmtTblID, + "test_name": msmt.TestName, + "test_group_name": msmt.Result.TestGroupName, + "start_time": msmt.MeasurementStartTime, + "test_keys": msmt.TestKeys, + "network_country_code": msmt.NetworkCountryCode, + "network_name": msmt.Network.NetworkName, + "asn": msmt.Network.ASN, + "runtime": msmt.MeasurementRuntime, + "url": msmt.URL.URL.String, + "url_category_code": msmt.URL.CategoryCode.String, + "url_country_code": msmt.URLCountryCode.String, + "is_anomaly": msmt.IsAnomaly.Bool, + "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.MeasurementIsDone, + "report_file_path": msmt.ReportFilePath, }).Info("measurement") } @@ -77,7 +77,7 @@ type ResultItemData struct { Runtime float64 Country string NetworkName string - ASN string + ASN uint Done bool DataUsageDown int64 DataUsageUp int64 @@ -95,7 +95,7 @@ func ResultItem(result ResultItemData) { "test_keys": result.TestKeys, "measurement_count": result.MeasurementCount, "measurement_anomaly_count": result.MeasurementAnomalyCount, - "country": result.Country, + "network_country_code": result.Country, "network_name": result.NetworkName, "asn": result.ASN, "runtime": result.Runtime,