database

package
v0.0.0-...-bd88772 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTestKeys

func AddTestKeys(sess sqlbuilder.Database, msmt *Measurement, tk interface{}) error

AddTestKeys writes the summary to the measurement

func Connect

func Connect(path string) (db sqlbuilder.Database, err error)

Connect to the database

func CreateOrUpdateURL

func CreateOrUpdateURL(sess sqlbuilder.Database, urlStr string, categoryCode string, countryCode string) (int64, error)

CreateOrUpdateURL will create a new URL entry to the urls table if it doesn't exists, otherwise it will update the category code of the one already in there.

func DeleteResult

func DeleteResult(sess sqlbuilder.Database, resultID int64) error

DeleteResult will delete a particular result and the relative measurement on disk.

func GetMeasurementCounts

func GetMeasurementCounts(sess sqlbuilder.Database, resultID int64) (uint64, uint64, error)

GetMeasurementCounts returns the number of anomalous and total measurement for a given result

func GetMeasurementJSON

func GetMeasurementJSON(sess sqlbuilder.Database, measurementID int64) (map[string]interface{}, error)

GetMeasurementJSON returns a map[string]interface{} given a database and a measurementID

func GetResultTestKeys

func GetResultTestKeys(sess sqlbuilder.Database, resultID int64) (string, error)

GetResultTestKeys returns a list of TestKeys for a given result

func ListResults

func ListResults(sess sqlbuilder.Database) ([]ResultNetwork, []ResultNetwork, error)

ListResults return the list of results

func RunMigrations

func RunMigrations(db *sql.DB) error

RunMigrations runs the database migrations

Types

type Measurement

type Measurement struct {
	ID               int64          `db:"measurement_id,omitempty"`
	TestName         string         `db:"test_name"`
	StartTime        time.Time      `db:"measurement_start_time"`
	Runtime          float64        `db:"measurement_runtime"` // Fractional number of seconds
	IsDone           bool           `db:"measurement_is_done"`
	IsUploaded       bool           `db:"measurement_is_uploaded"`
	IsFailed         bool           `db:"measurement_is_failed"`
	FailureMsg       sql.NullString `db:"measurement_failure_msg,omitempty"`
	IsUploadFailed   bool           `db:"measurement_is_upload_failed"`
	UploadFailureMsg sql.NullString `db:"measurement_upload_failure_msg,omitempty"`
	IsRerun          bool           `db:"measurement_is_rerun"`
	ReportID         sql.NullString `db:"report_id,omitempty"`
	URLID            sql.NullInt64  `db:"url_id,omitempty"` // Used to reference URL
	MeasurementID    sql.NullInt64  `db:"collector_measurement_id,omitempty"`
	IsAnomaly        sql.NullBool   `db:"is_anomaly,omitempty"`
	// FIXME we likely want to support JSON. See: https://github.com/upper/db/issues/462
	TestKeys            string         `db:"test_keys"`
	ResultID            int64          `db:"result_id"`
	ReportFilePath      sql.NullString `db:"report_file_path,omitempty"`
	MeasurementFilePath sql.NullString `db:"measurement_file_path,omitempty"`
}

Measurement model

func CreateMeasurement

func CreateMeasurement(sess sqlbuilder.Database, reportID sql.NullString, testName string, measurementDir string, idx int, resultID int64, urlID sql.NullInt64) (*Measurement, error)

CreateMeasurement writes the measurement to the database a returns a pointer to the Measurement

func (*Measurement) Done

func (m *Measurement) Done(sess sqlbuilder.Database) error

Done marks the measurement as completed

func (*Measurement) Failed

func (m *Measurement) Failed(sess sqlbuilder.Database, failure string) error

Failed writes the error string to the measurement

func (*Measurement) UploadFailed

func (m *Measurement) UploadFailed(sess sqlbuilder.Database, failure string) error

UploadFailed writes the error string for the upload failure to the measurement

func (*Measurement) UploadSucceeded

func (m *Measurement) UploadSucceeded(sess sqlbuilder.Database) error

UploadSucceeded writes the error string for the upload failure to the measurement

type MeasurementURLNetwork

type MeasurementURLNetwork struct {
	Measurement `db:",inline"`
	Network     `db:",inline"`
	Result      `db:",inline"`
	URL         `db:",inline"`
}

MeasurementURLNetwork is used for the JOIN between Measurement and URL

func ListMeasurements

func ListMeasurements(sess sqlbuilder.Database, resultID int64) ([]MeasurementURLNetwork, error)

ListMeasurements given a result ID

type Network

type Network struct {
	ID          int64  `db:"network_id,omitempty"`
	NetworkName string `db:"network_name"`
	NetworkType string `db:"network_type"`
	IP          string `db:"ip"`
	ASN         uint   `db:"asn"`
	CountryCode string `db:"network_country_code"`
}

Network represents a network tested by the user

func CreateNetwork

func CreateNetwork(sess sqlbuilder.Database, loc enginex.LocationProvider) (*Network, error)

CreateNetwork will create a new network in the network table

type PerformanceTestKeys

type PerformanceTestKeys struct {
	Upload   float64 `json:"upload"`
	Download float64 `json:"download"`
	Ping     float64 `json:"ping"`
	Bitrate  float64 `json:"median_bitrate"`
}

PerformanceTestKeys is the result summary for a performance test

type Result

type Result struct {
	ID             int64     `db:"result_id,omitempty"`
	TestGroupName  string    `db:"test_group_name"`
	StartTime      time.Time `db:"result_start_time"`
	NetworkID      int64     `db:"network_id"`     // Used to include a Network
	Runtime        float64   `db:"result_runtime"` // Runtime is expressed in fractional seconds
	IsViewed       bool      `db:"result_is_viewed"`
	IsDone         bool      `db:"result_is_done"`
	DataUsageUp    float64   `db:"result_data_usage_up"`
	DataUsageDown  float64   `db:"result_data_usage_down"`
	MeasurementDir string    `db:"measurement_dir"`
}

Result model

func CreateResult

func CreateResult(sess sqlbuilder.Database, homePath string, testGroupName string, networkID int64) (*Result, error)

CreateResult writes the Result to the database a returns a pointer to the Result

func (*Result) Finished

func (r *Result) Finished(sess sqlbuilder.Database) error

Finished marks the result as done and sets the runtime

type ResultNetwork

type ResultNetwork struct {
	Result  `db:",inline"`
	Network `db:",inline"`
}

ResultNetwork is used to represent the structure made from the JOIN between the results and networks tables.

type URL

type URL struct {
	ID           sql.NullInt64  `db:"url_id,omitempty"`
	URL          sql.NullString `db:"url"`
	CategoryCode sql.NullString `db:"category_code"`
	CountryCode  sql.NullString `db:"url_country_code"`
}

URL represents URLs from the testing lists

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL