Documentation
¶
Overview ¶
A token bucket implementation that supports token debt Token debt is negative tokens that must be repaid before any more tokens can be taken Token debt is repaid by the passage of time
Throughput package tracks and stores relay-per-second data for each application It shares throughput reports through pubsub and aggregates all reports from other middleware instances
Index ¶
- Variables
- func ValidateThroughputLimitConfig(config ThroughputLimitConfig) error
- type ConnectDone
- type ConnectStart
- type ConnectionReport
- type DNSDone
- type DNSReport
- type DNSStart
- type GotConnection
- type Key
- type Limiter
- type NetworkReport
- type NetworkTracer
- type NetworkTracerConfig
- type NewLimiter
- type PortalAppGetter
- type Recorder
- type RecorderConfig
- type Relay
- type RelayRequest
- type RelayResult
- type RoundTripReport
- type Sample
- type ServerReport
- type Stats
- type TLSReport
- type ThroughputAllower
- type ThroughputLimitConfig
- type ThroughputMetric
- type ThroughputReport
- type ThroughputStore
- type TokenBucket
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrApplicationNotFound = errors.New("Application not found") ErrThroughputLimitConfigRate = errors.New("Throughput rate must be specified and above 0") ErrThroughputLimitSendInterval = errors.New("Throughput report send interval must be specified and above 10") ErrThroughputRateMetricMinimum = errors.New("Throughput Rate Metric Minimum must be above 0") ErrThroughputRateTrackerHistorySize = errors.New("Throughput Rate Tracker History Size must be greater or equal to 5") )
View Source
var (
ErrTimestampNotFound = fmt.Errorf("Timestamp not found")
)
Functions ¶
func ValidateThroughputLimitConfig ¶ added in v0.0.183
func ValidateThroughputLimitConfig(config ThroughputLimitConfig) error
Types ¶
type ConnectDone ¶ added in v0.0.183
type ConnectStart ¶ added in v0.0.183
type ConnectionReport ¶ added in v0.0.183
type GotConnection ¶ added in v0.0.183
type Limiter ¶ added in v0.0.183
type Limiter interface {
Take(timestamp time.Time, tokens int64)
Allow(timestamp time.Time, tokens int64) bool
}
func NewTokenBucket ¶ added in v0.0.183
type NetworkReport ¶ added in v0.0.183
type NetworkReport struct {
DNSReport `json:"dns,omitempty"`
ConnectionReport `json:"connection,omitempty"`
TLSReport `json:"tls,omitempty"`
ServerReport `json:"node,omitempty"`
RoundTripReport `json:"roundtrip,omitempty"`
}
func (*NetworkReport) String ¶ added in v0.0.183
func (n *NetworkReport) String() string
type NetworkTracer ¶ added in v0.0.183
type NetworkTracer interface {
protocol.NetworkTracer
Start()
}
func NewNetworkTracer ¶ added in v0.0.183
func NewNetworkTracer(config NetworkTracerConfig, logger *logger.Logger) NetworkTracer
type NetworkTracerConfig ¶ added in v0.0.183
type NetworkTracerConfig struct {
Workers int
MaxMeasurements int
Adjustments int
PublishIntervalSeconds int
}
func (NetworkTracerConfig) IsEmpty ¶ added in v0.0.183
func (n NetworkTracerConfig) IsEmpty() bool
type NewLimiter ¶ added in v0.0.183
type PortalAppGetter ¶ added in v0.0.183
type PortalAppGetter interface {
GetPortalAppByID(portalAppID types.PortalAppID) (types.PortalAppLite, error)
}
type Recorder ¶
type Recorder interface {
RecordRelay(relay Relay) error
RecordSample(sample Sample) error
GetSessionOutputChannel() chan<- provider.Session
}
func NewMetricsRecorder ¶
func NewMetricsRecorder(nc, gnc *nats.Conn, config RecorderConfig, samplesChan chan Sample, metrics exporter.MetricExporter, portalRegion string, logger *logger.Logger) (Recorder, error)
TODO: REFACTOR: remove dependency on nats package
type RecorderConfig ¶ added in v0.0.183
type RecorderConfig struct {
RelaysChanSize int `json:"relays_chan_size"`
SamplesChanSize int `json:"samples_chan_size"`
WorkerPoolSize int `json:"worker_pool_size"`
SessionPublishers int `json:"session_publishers"`
PercentageReportedToGlobalNats int `json:"percentage_reported_to_global_nats"`
}
func (*RecorderConfig) SetDefaults ¶ added in v0.0.183
func (r *RecorderConfig) SetDefaults()
type Relay ¶ added in v0.0.183
type Relay struct {
RequestID string `json:"requestID"`
PoktChainID types.RelayChainID `json:"poktChainID"`
SessionKey string `json:"sessionKey"`
ProtocolPublicKey types.GigastakeAppPublicKey `json:"protocolPublicKey"`
PoktNodePublicKey string `json:"poktNodePublicKey"`
// TODO: change field name to Host: the URL contains the App ID, which is captured separately
RelaySourceURL string `json:"relaySourceUrl"`
// TODO: need better field names
RelayStartDatetime time.Time `json:"relayStartDatetime"`
RelayReturnDatetime time.Time `json:"relayReturnDatetime"`
NodeSendTime time.Time `json:"nodeSendTime"`
NodeReceiveTime time.Time `json:"nodeReceiveTime"`
AltruistSendTime time.Time `json:"altruistSendTime"`
AltruistReceiveTime time.Time `json:"altruistReceiveTime"`
RelayRequest RelayRequest `json:"relayRequest"`
RelayMethods []types.Method `json:"relayMethods"`
RelaySize int `json:"relaySize"`
// Note: if the relay eventually succeeds, this will be false,
// but the ErrorType/Subtype will still provide data on any failures.
// an example is when node response fails validation, and altruist is used successfully.
IsError bool `json:"isError"`
ErrorCode int `json:"errorCode,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
ErrorType relay.ErrorType `json:"errorType,omitempty"`
ErrorSubtype relay.ErrorSubtype `json:"errorSubtype,omitempty"`
// TODO: use error types instead
BlockingPlugin string `json:"blockingPlugin"`
RelayURLIsPublicEndpoint bool `json:"relayUrlIsPublicEndpoint"`
IsAltruistRelay bool `json:"isAltruistRelay"`
IsUserRelay bool `json:"isUserRelay"`
PortalRegionName string `json:"portalRegionName"`
AccountID types.AccountID `json:"accountID"`
PoktNodeDomain string `json:"poktNodeDomain"`
PoktNodeAddress string `json:"poktNodeAddress"`
PoktNodeURL string `json:"poktNodeURL"`
SessionHeight int `json:"sessionHeight,omitempty"`
PoktTxID string `json:"poktTxID"`
}
func (*Relay) LoadFromLog ¶ added in v0.0.183
type RelayRequest ¶ added in v0.0.183
type RoundTripReport ¶ added in v0.0.183
type RoundTripReport struct {
RoundTripStats Stats
// contains filtered or unexported fields
}
type Sample ¶ added in v0.0.96
type Sample struct {
Key
RequestID string
Latency float64
Result RelayResult
}
func GetSampleFromRelay ¶ added in v0.0.183
type ServerReport ¶ added in v0.0.183
type ServerReport struct {
LatencyStats Stats
// contains filtered or unexported fields
}
type TLSReport ¶ added in v0.0.183
type TLSReport struct {
HandshakeStats Stats
// contains filtered or unexported fields
}
type ThroughputAllower ¶ added in v0.0.183
type ThroughputLimitConfig ¶ added in v0.0.183
type ThroughputLimitConfig struct {
// How often throughput reports are sent to pubsub
SendInterval int `json:"send_interval"`
// Default free tier rate interval should it not be present in the db
FreeTierRate int `json:"free_tier_rate"`
// Minimum rate a free tier app must maintain to be tracked in prometheus
RateMetricMinimum float64 `json:"rate_metric_minimum"`
// RateTrackerHistorySize is how many seconds the rate tracker uses to calculate rate
RateTrackerHistorySize int `json:"rate_tracker_history_size"`
}
type ThroughputMetric ¶ added in v0.0.183
type ThroughputReport ¶ added in v0.0.183
type ThroughputReport struct {
Hostname string
SendTime time.Time
Throughputs ThroughputMetric
}
type ThroughputStore ¶ added in v0.0.183
type ThroughputStore struct {
// contains filtered or unexported fields
}
func NewThroughputStore ¶ added in v0.0.183
func NewThroughputStore(sendChan chan ThroughputReport, recvChan chan ThroughputReport, config ThroughputLimitConfig, newLimiter NewLimiter, rateTracker ratetracker.RateTracker, backend PortalAppGetter, metrics exporter.MetricExporter, logger *logger.Logger) *ThroughputStore
func (*ThroughputStore) IsRelayAllowed ¶ added in v0.0.183
func (t *ThroughputStore) IsRelayAllowed(appId string, limit int32, count int) (allowed bool)
IsRelayAllowed checks if a relay is allowed to be sent (is not rate-limited) This function also records the relay in localThroughputs
func (*ThroughputStore) Start ¶ added in v0.0.183
func (t *ThroughputStore) Start()
Start runs a goroutine that sends and receives throughput reports
type TokenBucket ¶ added in v0.0.183
type TokenBucket struct {
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package exporter provides a unified interface to export metric types Counter, Summary and Histogram are wrappers around the respective prometheus types, providing a simpler interface
|
Package exporter provides a unified interface to export metric types Counter, Summary and Histogram are wrappers around the respective prometheus types, providing a simpler interface |
|
feedback package is temporarily created to work around cyclic dependency issues
|
feedback package is temporarily created to work around cyclic dependency issues |
|
Package ratetracker provides a simple type that tracks a per-second event rate for multiple elements.
|
Package ratetracker provides a simple type that tracks a per-second event rate for multiple elements. |
Click to show internal directories.
Click to hide internal directories.