api

package
v0.0.0-...-0b31ed0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TODO: make all time-related parameters configurable
	TTL_DAILY_METRICS_DEFAULT_SECONDS  = 900
	TTL_TODAYS_METRICS_DEFAULT_SECONDS = 600

	MAX_PAST_DAYS_METRICS_DEFAULT_DAYS = 30
)
View Source
const (
	DATE_LAYOUT    = time.RFC3339
	PARAMETER_FROM = "from"
	PARAMETER_TO   = "to"
)

Variables

View Source
var (
	ErrLoadBalancerNotFound = errors.New("loadbalancer/endpoint not found")
)

Functions

func AdjustTimePeriod

func AdjustTimePeriod(from, to time.Time) (time.Time, time.Time, error)

AdjustTimePeriod sets the two parameters, i.e. from and to, according to the following rules:

  • From is adjusted to the start of the day that it originally specifies
  • To is adjusted to the start of the next day from the day it originally specifies

func GetHttpServer

func GetHttpServer(meter RelayMeter, l *logger.Logger) func(w http.ResponseWriter, req *http.Request)

TODO: Return 404 on Application not found error TODO: Return 304, i.e. Not Modified, if relevant TODO: 'Accepts' Header in the request serves: /relays/apps

Types

type ApiError

type ApiError error

TODO: move these custom error codes to the api package

var (
	AppNotFound    ApiError = fmt.Errorf("Application not found")
	InvalidRequest ApiError = fmt.Errorf("Invalid request")
)

type AppRelaysResponse

type AppRelaysResponse struct {
	Count       RelayCounts
	From        time.Time
	To          time.Time
	Application string
}

TODO: refactor common fields

type Backend

type Backend interface {
	//TODO: reverse map keys order, i.e. map[app]-> map[day]RelayCounts, at PG level
	DailyUsage(from, to time.Time) (map[time.Time]map[string]RelayCounts, error)
	TodaysUsage() (map[string]RelayCounts, error)
	// Is expected to return the list of applicationIDs owned by the user
	UserApps(user string) ([]string, error)
	// LoadBalancer returns the full load balancer struct
	LoadBalancer(endpoint string) (*repository.LoadBalancer, error)
	LoadBalancers() ([]*repository.LoadBalancer, error)
}

type ErrorResponse

type ErrorResponse struct {
	Message string
}

type LoadBalancerRelaysResponse

type LoadBalancerRelaysResponse struct {
	Count        RelayCounts
	From         time.Time
	To           time.Time
	Endpoint     string
	Applications []string
}

type RelayCounts

type RelayCounts struct {
	Success int64
	Failure int64
}

type RelayMeter

type RelayMeter interface {
	// AppRelays returns total number of relays for the app over the specified time period
	AppRelays(app string, from, to time.Time) (AppRelaysResponse, error)
	AllAppsRelays(from, to time.Time) ([]AppRelaysResponse, error)
	UserRelays(user string, from, to time.Time) (UserRelaysResponse, error)
	TotalRelays(from, to time.Time) (TotalRelaysResponse, error)
	// LoadBalancerRelays returns the metrics for an Endpoint, AKA loadbalancer
	LoadBalancerRelays(endpoint string, from, to time.Time) (LoadBalancerRelaysResponse, error)
	AllLoadBalancersRelays(from, to time.Time) ([]LoadBalancerRelaysResponse, error)
}

func NewRelayMeter

func NewRelayMeter(backend Backend, logger *logger.Logger, options RelayMeterOptions) RelayMeter

type RelayMeterOptions

type RelayMeterOptions struct {
	LoadInterval     time.Duration
	DailyMetricsTTL  time.Duration
	TodaysMetricsTTL time.Duration
	MaxPastDays      time.Duration
}

type TotalRelaysResponse

type TotalRelaysResponse struct {
	Count RelayCounts
	From  time.Time
	To    time.Time
}

type UserRelaysResponse

type UserRelaysResponse struct {
	Count        RelayCounts
	From         time.Time
	To           time.Time
	User         string
	Applications []string
}

Jump to

Keyboard shortcuts

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