Implement support for not writing to disk and fetching measurements f… (#189)
* Implement support for not writing to disk and fetching measurements from the API * Handle case of input not being set * Comment about exposing raw_measurement in probe-engine * Add basic test for GetMeasurementJSON * Update internal/database/actions.go Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
parent
4ac1e5f5d4
commit
af4cbd1846
3 changed files with 88 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -55,6 +56,25 @@ func GetMeasurementJSON(sess sqlbuilder.Database, measurementID int64) (map[stri
|
|||
log.Errorf("failed to run query %s: %v", req.String(), err)
|
||||
return nil, err
|
||||
}
|
||||
if measurement.IsUploaded {
|
||||
// TODO(bassosimone): this should be a function exposed by probe-engine
|
||||
reportID := measurement.Measurement.ReportID.String
|
||||
measurementURL := fmt.Sprintf("https://api.ooni.io/api/v1/raw_measurement?report_id=%s", reportID)
|
||||
if measurement.URL.URL.Valid == true {
|
||||
measurementURL += "&input=" + measurement.URL.URL.String
|
||||
}
|
||||
resp, err := http.Get(measurementURL)
|
||||
if err != nil {
|
||||
log.Errorf("failed to fetch the measurement %s %s", reportID, measurement.URL.URL.String)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if err := json.NewDecoder(resp.Body).Decode(&msmtJSON); err != nil {
|
||||
log.Error("failed to unmarshal the measurement_json")
|
||||
return nil, err
|
||||
}
|
||||
return msmtJSON, nil
|
||||
}
|
||||
// MeasurementFilePath might be NULL because the measurement from a
|
||||
// 3.0.0-beta install
|
||||
if measurement.Measurement.MeasurementFilePath.Valid == false {
|
||||
|
|
|
|||
Loading…
Reference in a new issue