core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RootPath    = "/"
	VarzPath    = "/varz"
	HealthzPath = "/healthz"
)

HTTP endpoints

Variables

This section is empty.

Functions

This section is empty.

Types

type Bin

type Bin struct {
	Value float64 `json:"v"`
	Count float64 `json:"c"`
}

Bin holds a float64 value and count

type BridgeStats

type BridgeStats struct {
	StartTime    int64            `json:"start_time"`
	ServerTime   int64            `json:"current_time"`
	UpTime       string           `json:"uptime"`
	RequestCount int64            `json:"request_count"`
	Connections  []ConnectorStats `json:"connectors"`
	HTTPRequests map[string]int64 `json:"http_requests"`
}

BridgeStats wraps the current status of the bridge and all of its connectors

type Connector

type Connector interface {
	Start() error
	Shutdown() error

	CheckConnections() error

	String() string
	ID() string

	Stats() ConnectorStats
}

Connector is the abstraction for all of the bridge connector types

func CreateConnector

func CreateConnector(config conf.ConnectorConfig, bridge *NATSReplicator) (Connector, error)

CreateConnector builds a connector from the supplied configuration

func NewNATS2NATSConnector

func NewNATS2NATSConnector(bridge *NATSReplicator, config conf.ConnectorConfig) Connector

NewNATS2NATSConnector create a new NATS to NATS connector

func NewNATS2StanConnector

func NewNATS2StanConnector(bridge *NATSReplicator, config conf.ConnectorConfig) Connector

NewNATS2StanConnector create a new NATS to STAN connector

func NewStan2NATSConnector

func NewStan2NATSConnector(bridge *NATSReplicator, config conf.ConnectorConfig) Connector

NewStan2NATSConnector create a new stan to a nats subject

func NewStan2StanConnector

func NewStan2StanConnector(bridge *NATSReplicator, config conf.ConnectorConfig) Connector

NewStan2StanConnector create a nats to MQ connector

type ConnectorStats

type ConnectorStats struct {
	Name          string  `json:"name"`
	ID            string  `json:"id"`
	Connected     bool    `json:"connected"`
	Connects      int64   `json:"connects"`
	Disconnects   int64   `json:"disconnects"`
	BytesIn       int64   `json:"bytes_in"`
	BytesOut      int64   `json:"bytes_out"`
	MessagesIn    int64   `json:"msg_in"`
	MessagesOut   int64   `json:"msg_out"`
	RequestCount  int64   `json:"count"`
	MovingAverage float64 `json:"rma"`
	Quintile50    float64 `json:"q50"`
	Quintile75    float64 `json:"q75"`
	Quintile90    float64 `json:"q90"`
	Quintile95    float64 `json:"q95"`
}

ConnectorStats captures the statistics for a single connector times are in nanoseconds, use a holder to get the protection of a lock and to fill in the quantiles

type ConnectorStatsHolder

type ConnectorStatsHolder struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConnectorStatsHolder provides a lock and histogram for a connector to updated it's stats. The holder's Stats() method should be used to get the current values.

func NewConnectorStatsHolder

func NewConnectorStatsHolder(name string, id string) *ConnectorStatsHolder

NewConnectorStatsHolder creates an empty stats holder, and initializes the request time histogram

func (*ConnectorStatsHolder) AddConnect

func (stats *ConnectorStatsHolder) AddConnect()

AddConnect updates the reconnects field locks/unlocks the stats

func (*ConnectorStatsHolder) AddDisconnect

func (stats *ConnectorStatsHolder) AddDisconnect()

AddDisconnect updates the disconnects field locks/unlocks the stats

func (*ConnectorStatsHolder) AddMessageIn

func (stats *ConnectorStatsHolder) AddMessageIn(bytes int64)

AddMessageIn updates the messages in and bytes in fields locks/unlocks the stats

func (*ConnectorStatsHolder) AddMessageOut

func (stats *ConnectorStatsHolder) AddMessageOut(bytes int64)

AddMessageOut updates the messages out and bytes out fields locks/unlocks the stats

func (*ConnectorStatsHolder) AddRequest

func (stats *ConnectorStatsHolder) AddRequest(bytesIn int64, bytesOut int64, reqTime time.Duration)

AddRequest groups addMessageIn, addMessageOut and addRequest time into a single call to reduce locking requirements. locks/unlocks the stats

func (*ConnectorStatsHolder) AddRequestTime

func (stats *ConnectorStatsHolder) AddRequestTime(reqTime time.Duration)

AddRequestTime register a time, updating the request count, RMA and histogram For information on the running moving average, see https://en.wikipedia.org/wiki/Moving_average locks/unlocks the stats

func (*ConnectorStatsHolder) ID

func (stats *ConnectorStatsHolder) ID() string

ID returns the ID the holder was created with

func (*ConnectorStatsHolder) Name

func (stats *ConnectorStatsHolder) Name() string

Name returns the name the holder was created with

func (*ConnectorStatsHolder) Stats

func (stats *ConnectorStatsHolder) Stats() ConnectorStats

Stats updates the quantiles and returns a copy of the stats locks/unlocks the stats

type Flags

type Flags struct {
	ConfigFile string

	Debug           bool
	Verbose         bool
	DebugAndVerbose bool
}

Flags defines the various flags you can call the account server with. These are used in main and passed down to the server code to process.

type Histogram

type Histogram struct {
	Bins    []Bin  `json:"bins"`
	MaxBins int    `json:"max"`
	Total   uint64 `json:"total"`
}

Histogram stores N bins using the streaming approximate histogram approach The histogram is not thread safe

func NewHistogram

func NewHistogram(n int) *Histogram

NewHistogram returns a new Histogram with a maximum of n bins.

There is no "optimal" bin count, but somewhere between 20 and 80 bins should be sufficient.

func (*Histogram) Add

func (h *Histogram) Add(n float64)

Add a value to the histogram, creating a bucket if necessary

func (*Histogram) Count

func (h *Histogram) Count() float64

Count returns the total number of entries in the histogram

func (*Histogram) Mean

func (h *Histogram) Mean() float64

Mean returns the sample mean of the distribution

func (*Histogram) Quantile

func (h *Histogram) Quantile(q float64) float64

Quantile returns the value for the bin at the provided quantile This is "approximate" in the since that the bin may straddle the quantile value

func (*Histogram) Scale

func (h *Histogram) Scale(s float64)

Scale the buckets by s, this is useful for requests or other values that may be in large numbers ie nanoseconds

type NATS2NATSConnector

type NATS2NATSConnector struct {
	ReplicatorConnector
	// contains filtered or unexported fields
}

NATS2NATSConnector connects a NATS subject to a different NATS subject

func (*NATS2NATSConnector) CheckConnections

func (conn *NATS2NATSConnector) CheckConnections() error

CheckConnections ensures the nats/stan connection and report an error if it is down

func (*NATS2NATSConnector) Shutdown

func (conn *NATS2NATSConnector) Shutdown() error

Shutdown the connector

func (*NATS2NATSConnector) Start

func (conn *NATS2NATSConnector) Start() error

Start the connector

type NATS2StanConnector

type NATS2StanConnector struct {
	ReplicatorConnector
	// contains filtered or unexported fields
}

NATS2StanConnector connects NATS subject to a nats streaming channel

func (*NATS2StanConnector) CheckConnections

func (conn *NATS2StanConnector) CheckConnections() error

CheckConnections ensures the nats/stan connection and report an error if it is down

func (*NATS2StanConnector) Shutdown

func (conn *NATS2StanConnector) Shutdown() error

Shutdown the connector

func (*NATS2StanConnector) Start

func (conn *NATS2StanConnector) Start() error

Start the connector

type NATSReplicator

type NATSReplicator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

NATSReplicator is the core structure for the server.

func NewNATSReplicator

func NewNATSReplicator() *NATSReplicator

NewNATSReplicator creates a new account server with a default logger

func (*NATSReplicator) ApplyConfigFile

func (server *NATSReplicator) ApplyConfigFile(configFile string) error

ApplyConfigFile applies the config file to the server's config

func (*NATSReplicator) CheckNATS

func (server *NATSReplicator) CheckNATS(name string) bool

CheckNATS returns true if the bridge is connected to nats

func (*NATSReplicator) CheckStan

func (server *NATSReplicator) CheckStan(name string) bool

CheckStan returns true if the bridge is connected to stan

func (*NATSReplicator) ConnectorError

func (server *NATSReplicator) ConnectorError(connector Connector, err error)

ConnectorError is called by a connector if it has a failure that requires a reconnect

func (*NATSReplicator) GetMonitoringRootURL

func (server *NATSReplicator) GetMonitoringRootURL() string

GetMonitoringRootURL returns the protocol://host:port for the monitoring server, useful for testing

func (*NATSReplicator) HandleHealthz

func (server *NATSReplicator) HandleHealthz(w http.ResponseWriter, r *http.Request)

HandleHealthz returns status 200.

func (*NATSReplicator) HandleRoot

func (server *NATSReplicator) HandleRoot(w http.ResponseWriter, r *http.Request)

HandleRoot will show basic info and links to others handlers.

func (*NATSReplicator) HandleVarz

func (server *NATSReplicator) HandleVarz(w http.ResponseWriter, r *http.Request)

HandleVarz returns statistics about the server.

func (*NATSReplicator) InitializeFromConfig

func (server *NATSReplicator) InitializeFromConfig(config conf.NATSReplicatorConfig) error

InitializeFromConfig initialize the server's configuration to an existing config object, useful for tests Does not change the config at all, use DefaultServerConfig() to create a default config

func (*NATSReplicator) InitializeFromFlags

func (server *NATSReplicator) InitializeFromFlags(flags Flags) error

InitializeFromFlags is called from main to configure the server, the server will decide what needs to happen based on the flags. On reload the same flags are passed

func (*NATSReplicator) Logger

func (server *NATSReplicator) Logger() logging.Logger

Logger hosts a shared logger

func (*NATSReplicator) NATS

func (server *NATSReplicator) NATS(name string) *nats.Conn

NATS hosts a shared nats connection for the connectors

func (*NATSReplicator) SafeStats

func (server *NATSReplicator) SafeStats() BridgeStats

SafeStats grabs the lock then calls stats(), useful for tests

func (*NATSReplicator) Stan

func (server *NATSReplicator) Stan(name string) stan.Conn

Stan hosts a shared streaming connection for the connectors

func (*NATSReplicator) Start

func (server *NATSReplicator) Start() error

Start the server, will lock the server, assumes the config is loaded

func (*NATSReplicator) Stop

func (server *NATSReplicator) Stop()

Stop the replicator

func (*NATSReplicator) StopMonitoring

func (server *NATSReplicator) StopMonitoring() error

StopMonitoring shuts down the http server used for monitoring expects the server lock to be held

type ReplicatorConnector

type ReplicatorConnector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ReplicatorConnector is the base type used for connectors so that they can share code The config, bridge and stats are all fixed at creation, so no lock is required on the connector at this level. The stats do keep a lock to protect their data. The connector has a lock for use by composing types to protect themselves during start/shutdown.

func (*ReplicatorConnector) CheckConnections

func (conn *ReplicatorConnector) CheckConnections() error

CheckConnections is a no-op, designed for overriding This is called when nats or stan goes down the connector should return an error if it has to be shut down

func (*ReplicatorConnector) ID

func (conn *ReplicatorConnector) ID() string

ID returns the id from the stats

func (*ReplicatorConnector) Shutdown

func (conn *ReplicatorConnector) Shutdown() error

Shutdown is a no-op, designed for overriding

func (*ReplicatorConnector) Start

func (conn *ReplicatorConnector) Start() error

Start is a no-op, designed for overriding

func (*ReplicatorConnector) Stats

func (conn *ReplicatorConnector) Stats() ConnectorStats

Stats returns a copy of the current stats for this connector

func (*ReplicatorConnector) String

func (conn *ReplicatorConnector) String() string

String returns the name passed into init

type Stan2NATSConnector

type Stan2NATSConnector struct {
	ReplicatorConnector
	// contains filtered or unexported fields
}

Stan2NATSConnector connects a STAN channel to NATS

func (*Stan2NATSConnector) CheckConnections

func (conn *Stan2NATSConnector) CheckConnections() error

CheckConnections ensures the nats/stan connection and report an error if it is down

func (*Stan2NATSConnector) Shutdown

func (conn *Stan2NATSConnector) Shutdown() error

Shutdown the connector

func (*Stan2NATSConnector) Start

func (conn *Stan2NATSConnector) Start() error

Start the connector

type Stan2StanConnector

type Stan2StanConnector struct {
	ReplicatorConnector
	// contains filtered or unexported fields
}

Stan2StanConnector connects a streaming channel to another streaming channel

func (*Stan2StanConnector) CheckConnections

func (conn *Stan2StanConnector) CheckConnections() error

CheckConnections ensures the nats/stan connection and report an error if it is down

func (*Stan2StanConnector) Shutdown

func (conn *Stan2StanConnector) Shutdown() error

Shutdown the connector

func (*Stan2StanConnector) Start

func (conn *Stan2StanConnector) Start() error

Start the connector

Jump to

Keyboard shortcuts

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