utils

package
v2.30.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 20 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`

func TimeToMicrosecondsSinceEpochInt64 added in v1.5.0

func TimeToMicrosecondsSinceEpochInt64(t time.Time) int64

TimeToMicrosecondsSinceEpochInt64 converts Go time.Time to a long representing time since epoch in microseconds, which is used expected in the Jaeger spans encoded as Thrift.

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 NewAgentClientUDPWithParams

func NewAgentClientUDPWithParams(params AgentClientUDPParams) (*AgentClientUDP, error)

NewAgentClientUDPWithParams 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) EmitBatch

func (a *AgentClientUDP) EmitBatch(ctx context.Context, batch *jaeger.Batch) error

EmitBatch implements EmitBatch() of Agent interface

func (*AgentClientUDP) EmitZipkinBatch

func (a *AgentClientUDP) EmitZipkinBatch(context.Context, []*zipkincore.Span) error

EmitZipkinBatch implements EmitZipkinBatch() of Agent interface

type AgentClientUDPParams

type AgentClientUDPParams struct {
	HostPort                   string
	MaxPacketSize              int
	Logger                     log.Logger
	DisableAttemptReconnecting bool
	AttemptReconnectInterval   time.Duration
}

AgentClientUDPParams allows specifying options for initializing an AgentClientUDP. An instance of this struct should be passed to NewAgentClientUDPWithParams.

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.

TODO (breaking change) remove this interface in favor of public struct below

Deprecated, use ReconfigurableRateLimiter.

type ReconfigurableRateLimiter

type ReconfigurableRateLimiter struct {
	// contains filtered or unexported fields
}

ReconfigurableRateLimiter is a 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.

TODO (breaking change) rename to RateLimiter once the interface is removed

func NewRateLimiter

func NewRateLimiter(creditsPerSecond, maxBalance float64) *ReconfigurableRateLimiter

NewRateLimiter creates a new ReconfigurableRateLimiter.

func (*ReconfigurableRateLimiter) CheckCredit

func (rl *ReconfigurableRateLimiter) CheckCredit(itemCost float64) bool

CheckCredit tries to reduce the current balance by itemCost provided that the current balance is not lest than itemCost.

func (*ReconfigurableRateLimiter) Update

func (rl *ReconfigurableRateLimiter) Update(creditsPerSecond, maxBalance float64)

Update changes the main parameters of the rate limiter in-place, while retaining the current accumulated balance (pro-rated to the new maxBalance value). Using this method instead of creating a new rate limiter helps to avoid thundering herd when sampling strategies are updated.

Jump to

Keyboard shortcuts

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