models

package
v0.0.0-...-ceb5cd5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnsemblerStandardType = "standard"
	EnsemblerDockerType   = "docker"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Model

	Environment       string  `json:"environment" validate:"required"`
	Team              string  `json:"team" validate:"required"`
	Service           string  `json:"service"`
	Metric            Metric  `json:"metric" validate:"oneof=throughput latency95p error_rate cpu_util memory_util"`
	WarningThreshold  float64 `json:"warning_threshold"`
	CriticalThreshold float64 `json:"critical_threshold"`
	// Duration to wait after the threshold is violated before firing the alert.
	// The duration format is a sequence of decimal numbers followed by a time unit suffix.
	// For instance: 5m
	Duration string `json:"duration" validate:"required"`
}

Alert contains policy that determines the "type of notification" and the "metric condition" that will trigger notifications for a particular service.

There are 5 provided metrics that can be used as conditions for triggering the alert:

- throughput: when current request per second is lower than the threshold - latency95p: when the 95-th percentile millisecond latency is higher than the threshold - error_rate: when the error percentage of all requests is higher than the threshold - cpu_util: when the percentage of cpu utilization is higher than the threshold - memory_util: when the percentage of memory utilization is higher than the threshold

There are "warning" and "critical" thresholds that can be specified. A value of 0 or less will deactivate that particular type of alert. "warning" and "critical" will usually send alerts to different notifications channels.

Environment, Team, Service, Metric and Duration are required in order to generate the correct query for the metric values and to direct the alert to the correct recipients.

func (Alert) Group

func (alert Alert) Group() schema.AlertGroup

Group creates an AlertGroup from the Alert specification. An alert group follows the alerting rule format in prometheus: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/

func (Alert) Validate

func (alert Alert) Validate() error

type BigQueryConfig

type BigQueryConfig struct {
	// BigQuery table to write to, as a fully qualified BQ Table string.
	// e.g. project.dataset.table
	Table string `json:"table"`
	// Service account secret name (correct to merlin) for writing to BQ.
	ServiceAccountSecret string `json:"service_account_secret"`
	// Whether to perform batch or streaming writes.
	BatchLoad bool `json:"batch_load"`
}

BigQueryConfig contains the configuration to log results to BigQuery.

type Enricher

type Enricher struct {
	Model
	// Fully qualified docker image string used by the enricher, in the
	// format registry/repository:version.
	Image string `json:"image" validate:"required"`
	// Resource requests  for the deployment of the enricher.
	ResourceRequest *ResourceRequest `json:"resource_request" validate:"required"`
	// Endpoint to query.
	Endpoint string `json:"endpoint" validate:"required"`
	// Request timeout as a valid quantity string.
	Timeout string `json:"timeout" validate:"required"`
	// Port to query.
	Port int `json:"port" validate:"required"`
	// Environment variables to inject into the pod.
	Env EnvVars `json:"env" validate:"required"`
	// (optional) ServiceAccount specifies the name of the secret registered in the MLP project containing the service
	// account. The service account will be mounted into the container and the env variable
	// GOOGLE_APPLICATION_CREDENTIALS will point to the service account file.
	ServiceAccount string `json:"service_account"`
}

Enricher contains the configuration for a preprocessor for a Turing Router.

type Ensembler

type Ensembler struct {
	Model
	Type           EnsemblerType            `json:"type" validate:"required"`
	StandardConfig *EnsemblerStandardConfig `json:"standard_config"` // Ensembler config when Type is "standard"
	DockerConfig   *EnsemblerDockerConfig   `json:"docker_config"`   // Ensembler config when Type is "docker"
}

Ensembler contains the configuration for a post-processor for a Turing Router.

type EnsemblerDockerConfig

type EnsemblerDockerConfig struct {
	Image string `json:"image" validate:"required"`
	// Resource requests for ensembler container deployed
	ResourceRequest *ResourceRequest `json:"resource_request" validate:"required"`
	// URL path for the endpoint, e.g "/"
	Endpoint string `json:"endpoint" validate:"required"`
	// Request timeout in duration format e.g. 60s
	Timeout string `json:"timeout" validate:"required"`
	// Port number the container listens to for requests
	Port int `json:"port" validate:"required"`
	// Environment variables to set in the container
	Env EnvVars `json:"env" validate:"required"`
	// secret name in MLP containing service account key
	ServiceAccount string `json:"service_account"`
}

func (*EnsemblerDockerConfig) Scan

func (c *EnsemblerDockerConfig) Scan(value interface{}) error

Scan implements sql.Scanner interface so database tools like go-orm knows how to de-serialize the struct object from the database

func (EnsemblerDockerConfig) Value

func (c EnsemblerDockerConfig) Value() (driver.Value, error)

Value implements sql.driver.Valuer interface so database tools like go-orm knows how to serialize the struct object for storage in the database

type EnsemblerStandardConfig

type EnsemblerStandardConfig struct {
	ExperimentMappings []ExperimentMapping `json:"experiment_mappings" validate:"required,dive"`
}

func (*EnsemblerStandardConfig) Scan

func (c *EnsemblerStandardConfig) Scan(value interface{}) error

Scan implements sql.Scanner interface so database tools like go-orm knows how to de-serialize the struct object from the database

func (EnsemblerStandardConfig) Value

Value implements sql.driver.Valuer interface so database tools like go-orm knows how to serialize the struct object for storage in the database

type EnsemblerType

type EnsemblerType string

type EnvVar

type EnvVar struct {
	// Name of the environment variable.
	Name string `json:"name"`

	// Value of the environment variable.
	// Defaults to "".
	Value string `json:"value"`
}

EnvVar represents an environment variable present in a container.

type EnvVars

type EnvVars []*EnvVar

EnvVars is a list of environment variables to set in the container.

func (*EnvVars) Scan

func (evs *EnvVars) Scan(value interface{}) error

func (EnvVars) ToKubernetesEnvVars

func (evs EnvVars) ToKubernetesEnvVars() []k8scorev1.EnvVar

ToKubernetesEnvVars returns the representation of Kubernetes' v1.EnvVars.

func (EnvVars) Value

func (evs EnvVars) Value() (driver.Value, error)

type Event

type Event struct {
	Model

	// Router id this event is for
	RouterID uint    `json:"-"`
	Router   *Router `json:"-"`

	// Version of router that triggered this deployment event.
	// May not necessarily pertain to the resource described by the event,
	// e.g. for removal of old versions, version will point to the new version
	// that triggered the event.
	Version uint `json:"version"`

	// Type of event
	EventType EventType `json:"event_type"`

	// Stage of deployment/undeployment
	Stage EventStage `json:"stage"`

	// Message describing the event
	Message string `json:"message"`
}

Event is a log of an event taking place during deployment or undeployment of a router.

func NewErrorEvent

func NewErrorEvent(stage EventStage, message string, args ...interface{}) *Event

NewErrorEvent creates a new error event

func NewInfoEvent

func NewInfoEvent(stage EventStage, message string, args ...interface{}) *Event

NewInfoEvent creates a new info event

func (*Event) SetRouter

func (e *Event) SetRouter(router *Router)

func (*Event) SetVersion

func (e *Event) SetVersion(version uint)

type EventStage

type EventStage string
const (
	EventStageDeployingDependencies      EventStage = "deploying dependencies"
	EventStageDeployingServices          EventStage = "deploying services"
	EventStageDeploymentSuccess          EventStage = "deployment success"
	EventStageDeploymentFailed           EventStage = "deployment failed"
	EventStageRollback                   EventStage = "rollback deployment"
	EventStageUpdatingEndpoint           EventStage = "updating endpoint"
	EventStageUndeployingPreviousVersion EventStage = "undeploying previous version"
	EventStageDeletingDependencies       EventStage = "deleting dependencies"
	EventStageUndeployingServices        EventStage = "undeploying services"
	EventStageDeletingEndpoint           EventStage = "deleting endpoint"
	EventStageUndeploymentFailed         EventStage = "undeployment failed"
	EventStageUndeploymentSuccess        EventStage = "undeployment success"
)

type EventType

type EventType string
const (
	EventTypeError EventType = "error"
	EventTypeInfo  EventType = "info"
)

type ExperimentEngine

type ExperimentEngine struct {
	// Type of Experiment Engine. Currently supports "litmus", "xp" and "nop".
	Type ExperimentEngineType `json:"type"`
	// Config contains the configs for the selected experiment engine (other than "nop").
	Config *manager.TuringExperimentConfig `json:"config,omitempty"`
}

ExperimentEngine contains the type and configuration for the Experiment engine powering the router.

func (*ExperimentEngine) Scan

func (eec *ExperimentEngine) Scan(value interface{}) error

func (ExperimentEngine) Value

func (eec ExperimentEngine) Value() (driver.Value, error)

type ExperimentEngineType

type ExperimentEngineType string

EngineType is used to capture the types of the supported experimentation engines Need to expose this value in turing-router engines/router/missionctl/experiment/experiment.go

const (
	ExperimentEngineTypeNop    ExperimentEngineType = "nop"
	ExperimentEngineTypeLitmus ExperimentEngineType = "litmus"
	ExperimentEngineTypeXp     ExperimentEngineType = "xp"
)

type ExperimentMapping

type ExperimentMapping struct {
	Experiment string `json:"experiment" validate:"required"` // Experiment name from the experiment engine
	Treatment  string `json:"treatment" validate:"required"`  // Treatment name for the experiment
	Route      string `json:"route" validate:"required"`      // Route ID to select for the experiment treatment
}

type KafkaConfig

type KafkaConfig struct {
	// List of brokers for the kafka to write logs to
	Brokers string `json:"brokers"`
	// Topic to write logs to
	Topic string `json:"topic"`
}

type LogConfig

type LogConfig struct {
	// LogLevel of the router.
	LogLevel routercfg.LogLevel `json:"log_level"`
	// Enable custom metrics for the router. Defaults to false.
	CustomMetricsEnabled bool `json:"custom_metrics_enabled"`
	// Enable debug logs for Fiber. Defaults to false.
	FiberDebugLogEnabled bool `json:"fiber_debug_log_enabled"`
	// Enable Jaeger tracing.
	JaegerEnabled bool `json:"jaeger_enabled"`
	// Result Logger type. The associated config must not be null.
	ResultLoggerType ResultLogger `json:"result_logger_type"`
	// Configuration necessary to log results to BigQuery. Cannot be empty if
	// ResultLoggerType is set to "bigquery".
	BigQueryConfig *BigQueryConfig `json:"bigquery_config,omitempty"`
	// Configuration necessary to log results to kafka. Cannot be empty if
	// ResultLoggerType is set to "kafka"
	KafkaConfig *KafkaConfig `json:"kafka_config,omitempty"`
}

LogConfig contains all log configuration necessary for a deployment of the Turing Router.

func (*LogConfig) Scan

func (l *LogConfig) Scan(value interface{}) error

func (LogConfig) Value

func (l LogConfig) Value() (driver.Value, error)

type Metric

type Metric string
const (
	MetricThroughput Metric = "throughput"
	MetricLatency95p Metric = "latency95p"
	MetricErrorRate  Metric = "error_rate"
	MetricCPUUtil    Metric = "cpu_util"
	MetricMemoryUtil Metric = "memory_util"
)

type Model

type Model struct {
	// Id of the entity
	ID uint `json:"id"`
	// Created timestamp. Populated when the object is saved to the db.
	CreatedAt time.Time `json:"created_at"`
	// Last updated timestamp. Updated when the object is updated in the db.
	UpdatedAt time.Time `json:"updated_at"`
}

Model is a struct containing the basic fields for a persisted entity defined in the API.

type ResourceRequest

type ResourceRequest struct {
	// Minimum number of replica of inference service
	MinReplica int `json:"min_replica"`
	// Maximum number of replica of inference service
	MaxReplica int `json:"max_replica"`

	// CPU request of inference service
	CPURequest resource.Quantity `json:"cpu_request"`
	// Memory request of inference service
	MemoryRequest resource.Quantity `json:"memory_request"`
}

func (*ResourceRequest) Scan

func (r *ResourceRequest) Scan(value interface{}) error

func (ResourceRequest) Value

func (r ResourceRequest) Value() (driver.Value, error)

type ResultLogger

type ResultLogger string

ResultLogger is the type used to capture the supported response logging destinations

const (
	// BigQueryLogger logs the responses to BigQuery
	BigQueryLogger ResultLogger = "bigquery"
	// ConsoleLogger logs the responses to console
	ConsoleLogger ResultLogger = "console"
	// KafkaLogger logs the responses to kafka
	KafkaLogger ResultLogger = "kafka"
	// NopLogger disables response logging
	NopLogger ResultLogger = "nop"
)

type Route

type Route struct {
	// Id of the route
	ID string `json:"id"`
	// Type of the route
	Type string `json:"type"`
	// Endpoint to query
	Endpoint string `json:"endpoint"`
	// Request timeout as a valid quantity string.
	Timeout string `json:"timeout"`
}

Route maps onto the fiber.Component.

type Router

type Router struct {
	Model
	// Project id of the project this router belongs to, as retrieved from
	// the MLP API.
	ProjectID int `json:"project_id"`
	// Environment name of the environment this router belongs to, as retrieved
	// from the MLP API.
	EnvironmentName string `json:"environment_name"`
	// Name of the router. Must be unique within the given project and environment.
	Name string `json:"name"`
	// Status of the Router. Indicates the deployment status of the router.
	Status RouterStatus `json:"status"`
	// Endpoint URL where the currently deployed router version is accessible at
	Endpoint string `json:"endpoint,omitempty"`

	// The current version (may be deployed or undeployed)
	CurrRouterVersionID sql.NullInt32  `json:"-"`
	CurrRouterVersion   *RouterVersion `json:"config,omitempty" gorm:"foreignkey:CurrRouterVersionID"`
}

Router holds the information as to which versions of Router have been deployed, and acts as the top level object for an instance of the Turing Router.

func (*Router) ClearCurrRouterVersion

func (r *Router) ClearCurrRouterVersion()

ClearCurrRouterVersion clears the current version for this router.

func (*Router) ClearCurrRouterVersionID

func (r *Router) ClearCurrRouterVersionID()

func (*Router) MarshalJSON

func (r *Router) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaling function for the Router, to manipulate the endpoint.

func (*Router) SetCurrRouterVersion

func (r *Router) SetCurrRouterVersion(routerVersion *RouterVersion)

SetCurrRouterVersion sets the currently version for this router to the provided routerVersion.

func (*Router) SetCurrRouterVersionID

func (r *Router) SetCurrRouterVersionID(routerVersionID uint)

type RouterResponse

type RouterResponse Router

RouterResponse is an alias for the Router, to enable custom marshaling

type RouterStatus

type RouterStatus string
const (
	RouterStatusPending    RouterStatus = "pending"
	RouterStatusFailed     RouterStatus = "failed"
	RouterStatusDeployed   RouterStatus = "deployed"
	RouterStatusUndeployed RouterStatus = "undeployed"
)

type RouterVersion

type RouterVersion struct {
	Model
	// Router this RouterVersion is associated with.
	RouterID uint    `json:"-"`
	Router   *Router `json:"router" gorm:"association_autoupdate:false"`

	// Version of Router configuration.
	Version uint `json:"version"`

	// Status of the RouterVersion. Indicates the deployment status of the configuration.
	Status RouterVersionStatus `json:"status"`
	// Last known error if the status is error
	Error string `json:"error,omitempty"`
	// Image of the router deployed
	Image string `json:"image"`
	// Downstream endpoints for the router
	Routes Routes `json:"routes"`
	// Default route
	DefaultRouteID string `json:"default_route_id"`
	// Rules for activating some routes based on request conditions.
	TrafficRules TrafficRules `json:"rules,omitempty"`
	// Configuration for the experiment engine queried by the router.
	ExperimentEngine *ExperimentEngine `json:"experiment_engine"`
	// Resource requests for deployment
	ResourceRequest *ResourceRequest `json:"resource_request"`
	// Request timeout as a valid quantity string
	Timeout string `json:"timeout"`
	// Logging configuration for the router
	LogConfig *LogConfig `json:"log_config"`

	// The enricher used by the router
	EnricherID sql.NullInt32 `json:"-"`
	Enricher   *Enricher     `json:"enricher,omitempty"`

	// The ensembler used by the router
	EnsemblerID sql.NullInt32 `json:"-"`
	Ensembler   *Ensembler    `json:"ensembler,omitempty"`
}

RouterVersion contains the configuration of a version of a router. Every change in configuration should always result in a new instance of RouterVersion.

func (*RouterVersion) BeforeCreate

func (r *RouterVersion) BeforeCreate(tx *gorm.DB) error

Sets version before creating

func (*RouterVersion) SetEnricherID

func (r *RouterVersion) SetEnricherID(enricherID uint)

SetEnricherId Sets the id of the associated Enricher

func (*RouterVersion) SetEnsemblerID

func (r *RouterVersion) SetEnsemblerID(ensemblerID uint)

SetEnsemblerId Sets the id of the associated Ensembler

type RouterVersionStatus

type RouterVersionStatus string
const (
	RouterVersionStatusPending    RouterVersionStatus = "pending"
	RouterVersionStatusFailed     RouterVersionStatus = "failed"
	RouterVersionStatusDeployed   RouterVersionStatus = "deployed"
	RouterVersionStatusUndeployed RouterVersionStatus = "undeployed"
)

type Routes

type Routes []*Route

func (*Routes) Scan

func (r *Routes) Scan(value interface{}) error

func (*Routes) ToFiberRoutes

func (r *Routes) ToFiberRoutes() (*fiberconfig.Routes, error)

ToFiberRoutes converts routes to a type compatible with Fiber's config

func (Routes) Value

func (r Routes) Value() (driver.Value, error)

type TrafficRule

type TrafficRule struct {
	Conditions []*router.TrafficRuleCondition `json:"conditions" validate:"required,notBlank,dive"`
	Routes     []string                       `json:"routes" validate:"required,notBlank"`
}

type TrafficRules

type TrafficRules []*TrafficRule

func (*TrafficRules) ConditionalRouteIds

func (r *TrafficRules) ConditionalRouteIds() map[string]bool

func (*TrafficRules) Scan

func (r *TrafficRules) Scan(value interface{}) error

func (TrafficRules) Value

func (r TrafficRules) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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