utils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2016 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const UDPPacketMaxLength = 65000

UDPPacketMaxLength is the max size of UDP packet we want to send, synced with jaeger-agent

Variables

View Source
var (
	// ErrEmptyIP an error for empty ip strings
	ErrEmptyIP = errors.New("empty string given for ip")

	// ErrNotHostColonPort an error for invalid host port string
	ErrNotHostColonPort = errors.New("expecting host:port")

	// ErrNotFourOctets an error for the wrong number of octets after splitting a string
	ErrNotFourOctets = errors.New("Wrong number of octets")
)

Functions

func GetJSON

func GetJSON(url string, out interface{}) error

GetJSON makes an HTTP call to the specified URL and parses the returned JSON into `out`.

func HostIP

func HostIP() (net.IP, error)

HostIP tries to find an IP that can be used by other machines to reach this machine.

func NewRand

func NewRand(seed int64) *rand.Rand

NewRand returns a rand.Rand that is threadsafe.

func PackIPAsUint32

func PackIPAsUint32(ip net.IP) uint32

PackIPAsUint32 packs an IPv4 as uint32

func ParseIPToUint32

func ParseIPToUint32(ip string) (uint32, error)

ParseIPToUint32 converts a string ip (e.g. "x.y.z.w") to an uint32

func ParsePort

func ParsePort(portString string) (uint16, error)

ParsePort converts port number from string to uin16

func ReadJSON

func ReadJSON(resp *http.Response, out interface{}) error

ReadJSON reads JSON from http.Response and parses it into `out`

Types

type AgentClientUDP

type AgentClientUDP struct {
	agent.Agent
	io.Closer
	// contains filtered or unexported fields
}

AgentClientUDP is a UDP client to Jaeger agent that implements agent.Agent interface.

func NewAgentClientUDP

func NewAgentClientUDP(hostPort string, maxPacketSize int) (*AgentClientUDP, error)

NewAgentClientUDP creates a client that sends spans to Jaeger Agent over UDP.

func (*AgentClientUDP) Close

func (a *AgentClientUDP) Close() error

Close implements Close() of io.Closer and closes the underlying UDP connection.

func (*AgentClientUDP) EmitZipkinBatch

func (a *AgentClientUDP) EmitZipkinBatch(spans []*zipkincore.Span) error

EmitZipkinBatch implements EmitZipkinBatch() of Agent interface

type RateLimiter

type RateLimiter interface {
	CheckCredit(itemCost float64) bool
}

RateLimiter is a filter used to check if a message that is worth itemCost units is within the rate limits.

func NewRateLimiter

func NewRateLimiter(creditsPerSecond float64) RateLimiter

NewRateLimiter creates a new rate limiter based on leaky bucket algorithm, formulated in terms of a credits balance that is replenished every time CheckCredit() method is called (tick) by the amount proportional to the time elapsed since the last tick, up to max of creditsPerSecond. A call to CheckCredit() takes a cost of an item we want to pay with the balance. If the balance exceeds the cost of the item, the item is "purchased" and the balance reduced, indicated by returned value of true. Otherwise the balance is unchanged and return false.

This can be used to limit a rate of messages emitted by a service by instantiating the Rate Limiter with the max number of messages a service is allowed to emit per second, and calling CheckCredit(1.0) for each message to determine if the message is within the rate limit.

It can also be used to limit the rate of traffic in bytes, by setting creditsPerSecond to desired throughput as bytes/second, and calling CheckCredit() with the actual message size.

Jump to

Keyboard shortcuts

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