model

package
v0.0.0-...-b8b0e3c Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusOK means the latest run in test was within the threshold
	StatusOK = Status("ok")

	// StatusFail means the latest run in test was not within the threshold
	StatusFail = Status("fail")
)
View Source
const (
	// ThresholdMean is the threshold for mean / average
	ThresholdMean Threshold = Threshold("mean")

	// ThresholdMedian is the threshold for the median
	ThresholdMedian = Threshold("median")

	// Threshold95th is the threshold for the 95th percentile
	Threshold95th = Threshold("95th")

	// ThresholdFastest is the threshold for the fastest metric
	ThresholdFastest = Threshold("fastest")

	// ThresholdSlowest is the threshold for the slowest metric
	ThresholdSlowest = Threshold("slowest")

	// ThresholdRPS is the threshold for the RPS metric
	ThresholdRPS = Threshold("rps")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Model
	RunID uint `json:"runId"`

	// The Mark for histogram bucket in seconds
	Mark float64 `json:"mark"`

	// The count in the bucket
	Count int `json:"count"`

	// The frequency of results in the bucket as a decimal percentage
	Frequency float64 `json:"frequency"`
}

Bucket holds histogram data

type Detail

type Detail struct {
	Model

	Run *Run `json:"-"`

	// Run id
	RunID uint `json:"runID" gorm:"type:integer REFERENCES runs(id)"`

	// Timestamp for the detail
	Timestamp time.Time `json:"timestamp"`

	// Latency of the call
	Latency float64 `json:"latency" validate:"required"`

	// Error details
	Error string `json:"error"`

	// Status of the call
	Status string `json:"status"`
}

Detail represents a run detail

func (*Detail) BeforeSave

func (d *Detail) BeforeSave(scope *gorm.Scope) error

BeforeSave is called by GORM before save

func (*Detail) UnmarshalJSON

func (d *Detail) UnmarshalJSON(data []byte) error

UnmarshalJSON for Detail

type DetailService

type DetailService struct {
	DB     *gorm.DB
	Config *config.DBConfig
}

DetailService is our implementation

func (*DetailService) Count

func (ds *DetailService) Count(rid uint) (uint, error)

Count returns the total number of runs

func (*DetailService) Create

func (ds *DetailService) Create(r *Detail) error

Create creates a new detail

func (*DetailService) CreateBatch

func (ds *DetailService) CreateBatch(rid uint, s []*Detail) (uint, uint)

CreateBatch creates a batch of details returning the number successfully created, and the number failed

func (*DetailService) Delete

func (ds *DetailService) Delete(r *Detail) error

Delete deletes a detial

func (*DetailService) DeleteAll

func (ds *DetailService) DeleteAll(rid uint) error

DeleteAll deletes all details for a run

func (*DetailService) FindByID

func (ds *DetailService) FindByID(id uint) (*Detail, error)

FindByID finds test by id

func (*DetailService) FindByRunID

func (ds *DetailService) FindByRunID(rid, num, page uint) ([]*Detail, error)

FindByRunID finds tests by project

func (*DetailService) FindByRunIDAll

func (ds *DetailService) FindByRunIDAll(rid uint) ([]*Detail, error)

FindByRunIDAll lists details using sorting

func (*DetailService) FindByRunIDSorted

func (ds *DetailService) FindByRunIDSorted(rid, num, page uint, sortField, order string) ([]*Detail, error)

FindByRunIDSorted lists details using sorting

func (*DetailService) Update

func (ds *DetailService) Update(d *Detail) error

Update updates a detail

type LatencyDistribution

type LatencyDistribution struct {
	Model
	RunID      uint          `json:"runId"`
	Percentage int           `json:"percentage"`
	Latency    time.Duration `json:"latency"`
}

LatencyDistribution holds latency distribution data

type Model

type Model struct {
	// The id
	ID uint `json:"id" gorm:"primary_key"`

	// The creation time
	CreatedAt time.Time `json:"createdAt"`

	// The updated time
	UpdatedAt time.Time `json:"updatedAt"`

	// The deleted time
	DeletedAt *time.Time `json:"deletedAt" sql:"index"`
}

Model base model definition. Copy of gorm.Model with custom tags

type Options

type Options struct {
	Call          string             `json:"call,omitempty"`
	Proto         string             `json:"proto,omitempty"`
	Host          string             `json:"host,omitempty"`
	Cert          string             `json:"cert,omitempty"`
	CName         string             `json:"cname,omitempty"`
	N             int                `json:"n,omitempty"`
	C             int                `json:"c,omitempty"`
	QPS           int                `json:"qps,omitempty"`
	Z             time.Duration      `json:"z,omitempty"`
	Timeout       int                `json:"timeout,omitempty"`
	DialTimtout   int                `json:"dialTimeout,omitempty"`
	KeepaliveTime int                `json:"keepAlice,omitempty"`
	Data          interface{}        `json:"data,omitempty"`
	Metadata      *map[string]string `json:"metadata,omitempty"`
}

Options represents run options

type Project

type Project struct {
	Model
	Name        string `json:"name" gorm:"unique_index;not null"`
	Description string `json:"description"`
}

Project represents a project

func (*Project) BeforeCreate

func (p *Project) BeforeCreate() error

BeforeCreate is a GORM hook called when a model is created

func (*Project) BeforeSave

func (p *Project) BeforeSave(scope *gorm.Scope) error

BeforeSave is a GORM hook called when a model is created

func (*Project) BeforeUpdate

func (p *Project) BeforeUpdate() error

BeforeUpdate is a GORM hook called when a model is updated

type ProjectService

type ProjectService struct {
	DB *gorm.DB
}

ProjectService is our implementation

func (*ProjectService) Count

func (ps *ProjectService) Count() (uint, error)

Count returns the total number of projects

func (*ProjectService) Create

func (ps *ProjectService) Create(p *Project) error

Create creates a new project

func (*ProjectService) Delete

func (ps *ProjectService) Delete(p *Project) error

Delete deletes project

func (*ProjectService) FindByID

func (ps *ProjectService) FindByID(id uint) (*Project, error)

FindByID finds project by id

func (*ProjectService) FindByName

func (ps *ProjectService) FindByName(name string) (*Project, error)

FindByName finds project by name

func (*ProjectService) List

func (ps *ProjectService) List(limit, page uint) ([]*Project, error)

List lists projects

func (*ProjectService) ListSorted

func (ps *ProjectService) ListSorted(limit, page uint, sortField, order string) ([]*Project, error)

ListSorted lists projects using sorting

func (*ProjectService) Update

func (ps *ProjectService) Update(p *Project) error

Update updates project

type Run

type Run struct {
	Model
	Date    time.Time     `json:"date"`
	TestID  uint          `json:"testID" gorm:"type:integer REFERENCES tests(id)"`
	Test    *Test         `json:"-"`
	Count   uint64        `json:"count"`
	Total   time.Duration `json:"total"`
	Average time.Duration `json:"average"`
	Fastest time.Duration `json:"fastest"`
	Slowest time.Duration `json:"slowest"`
	Rps     float64       `json:"rps"`

	Status Status `json:"status" validate:"oneof=ok fail"`

	Options *Options `json:"options,omitempty" gorm:"-"`

	ErrorDist      map[string]int `json:"errorDistribution,omitempty" gorm:"-"`
	StatusCodeDist map[string]int `json:"statusCodeDistribution,omitempty" gorm:"-"`

	LatencyDistribution []*LatencyDistribution `json:"latencyDistribution"`
	Histogram           []*Bucket              `json:"histogram"`

	// temp conversion vars
	ErrorDistJSON      string `json:"-" gorm:"column:error_dist"`
	StatusCodeDistJSON string `json:"-" gorm:"column:status_code_dist"`
	OptionsJSON        string `json:"-" gorm:"column:options"`
}

Run represents a project

func (*Run) AfterFind

func (r *Run) AfterFind() error

AfterFind is called by GORM after a query

func (*Run) AfterSave

func (r *Run) AfterSave() error

AfterSave is called by GORM after model is saved during create or update

func (*Run) BeforeSave

func (r *Run) BeforeSave(scope *gorm.Scope) error

BeforeSave is called by GORM before save

func (*Run) GetThresholdValues

func (r *Run) GetThresholdValues() (time.Duration, time.Duration)

GetThresholdValues gets median and 95th

func (*Run) HasErrors

func (r *Run) HasErrors() bool

HasErrors returns whether run has any errors

type RunService

type RunService struct {
	DB *gorm.DB
}

RunService is our implementation

func (*RunService) Count

func (rs *RunService) Count(tid uint) (uint, error)

Count returns the total number of runs

func (*RunService) Create

func (rs *RunService) Create(r *Run) error

Create creates a new run

func (*RunService) Delete

func (rs *RunService) Delete(r *Run) error

Delete deletes a run

func (*RunService) FindByID

func (rs *RunService) FindByID(id uint) (*Run, error)

FindByID finds run by id

func (*RunService) FindByTestID

func (rs *RunService) FindByTestID(tid, num, page uint, populate bool) ([]*Run, error)

FindByTestID finds tests by project

func (*RunService) FindByTestIDSorted

func (rs *RunService) FindByTestIDSorted(tid, num, page uint, sortField, order string,
	histogram bool, latency bool) ([]*Run, error)

FindByTestIDSorted lists tests using sorting

func (*RunService) FindLatest

func (rs *RunService) FindLatest(tid uint) (*Run, error)

FindLatest returns the latest created run for test

func (*RunService) Update

func (rs *RunService) Update(r *Run) error

Update updates a run

type Status

type Status string

Status represents a status of a test, whether its latest run failed the threshold settings

func StatusFromString

func StatusFromString(str string) Status

StatusFromString creates a Status from a string

func (Status) MarshalJSON

func (t Status) MarshalJSON() ([]byte, error)

MarshalJSON formats a Threshold value into a JSON string

func (Status) String

func (t Status) String() string

String() is the string representation of threshold

func (*Status) UnmarshalJSON

func (t *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON prases a Threshold value from JSON string

type Test

type Test struct {
	Model
	ProjectID       uint                            `json:"projectID" gorm:"type:integer REFERENCES projects(id);unique_index:test_name"`
	Project         *Project                        `json:"-"`
	Name            string                          `json:"name" gorm:"unique_index:test_name;not null" validate:"required"`
	Description     string                          `json:"description"`
	Status          Status                          `json:"status" validate:"oneof=ok fail"`
	Thresholds      map[Threshold]*ThresholdSetting `json:"thresholds,omitempty" gorm:"-"`
	KeyMetric       Threshold                       `json:"keyMetric"`
	FailOnError     bool                            `json:"failOnError"`
	FailOnThreshold bool                            `json:"failOnThreshold"`
	FailOnKeyMetric bool                            `json:"failOnKeyMetric"`
	ThresholdsJSON  string                          `json:"-" gorm:"column:thresholds"`
}

Test represents a test

func (*Test) AfterFind

func (t *Test) AfterFind() error

AfterFind is called by GORM after a query

func (*Test) AfterSave

func (t *Test) AfterSave() error

AfterSave is called by GORM after model is saved during create or update

func (*Test) BeforeCreate

func (t *Test) BeforeCreate() error

BeforeCreate is a GORM hook called when a model is created

func (*Test) BeforeSave

func (t *Test) BeforeSave(scope *gorm.Scope) error

BeforeSave is called by GORM before save

func (*Test) BeforeUpdate

func (t *Test) BeforeUpdate() error

BeforeUpdate is a GORM hook called when a model is updated

func (*Test) SetStatus

func (t *Test) SetStatus(tMean, tMedian, t95, fastest, slowest time.Duration, rps float64, hasError bool)

SetStatus sets this test's status based on the settings and the values in params

func (*Test) UnmarshalJSON

func (t *Test) UnmarshalJSON(data []byte) error

UnmarshalJSON prases a Test value from JSON string

type TestService

type TestService struct {
	DB *gorm.DB
}

TestService is our implementation

func (*TestService) Count

func (ts *TestService) Count(pid uint) (uint, error)

Count returns the total number of tests

func (*TestService) Create

func (ts *TestService) Create(t *Test) error

Create creates a new tests

func (*TestService) Delete

func (ts *TestService) Delete(t *Test) error

Delete deletes tests

func (*TestService) FindByID

func (ts *TestService) FindByID(id uint) (*Test, error)

FindByID finds test by id

func (*TestService) FindByName

func (ts *TestService) FindByName(pid uint, name string) (*Test, error)

FindByName finds test by name

func (*TestService) FindByProjectID

func (ts *TestService) FindByProjectID(pid, num, page uint) ([]*Test, error)

FindByProjectID finds tests by project

func (*TestService) FindByProjectIDSorted

func (ts *TestService) FindByProjectIDSorted(pid, num, page uint, sortField, order string) ([]*Test, error)

FindByProjectIDSorted lists tests using sorting

func (*TestService) Update

func (ts *TestService) Update(t *Test) error

Update updates tests

type Threshold

type Threshold string

Threshold represends a threshold limit we may care about

type ThresholdSetting

type ThresholdSetting struct {
	Status             Status        `json:"status" validate:"oneof=ok fail"`
	Threshold          time.Duration `json:"threshold,omitempty"`
	NumericalThreshold float64       `json:"numericalThreshold,omitempty"`
}

ThresholdSetting setting

func (*ThresholdSetting) UnmarshalJSON

func (m *ThresholdSetting) UnmarshalJSON(data []byte) error

UnmarshalJSON prases a ThresholdSetting value from JSON string

Jump to

Keyboard shortcuts

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