bytecounter

package
v3.16.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package bytecounter contains code to track the number of bytes sent and received by a probe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaybeWrapConn added in v3.16.0

func MaybeWrapConn(conn net.Conn, counter *Counter) net.Conn

MaybeWrapConn is like wrap if counter is not nil, otherwise it's a no-op.

func MaybeWrapWithContextAwareDialer added in v3.16.0

func MaybeWrapWithContextAwareDialer(enabled bool, dialer model.Dialer) model.Dialer

MaybeWrapWithContextAwareDialer wraps the given dialer with a ContextAwareDialer if the enabled argument is true and otherwise just returns the given dialer.

Bug

This implementation cannot properly account for the bytes that are sent by persistent connections, because they stick to the counters set when the connection was established. This typically means we miss the bytes sent and received when submitting a measurement. Such bytes are specifically not seen by the experiment specific byte counter.

For this reason, this implementation may be heavily changed/removed in the future (<- this message is now ~two years old, though).

func MaybeWrapWithContextByteCounters added in v3.14.0

func MaybeWrapWithContextByteCounters(ctx context.Context, conn net.Conn) net.Conn

MaybeWrapWithContextByteCounters wraps a conn with the byte counters that have previosuly been configured into a context.

func WithExperimentByteCounter added in v3.14.0

func WithExperimentByteCounter(ctx context.Context, counter *Counter) context.Context

WithExperimentByteCounter assigns the experiment byte counter to the context.

func WithSessionByteCounter added in v3.14.0

func WithSessionByteCounter(ctx context.Context, counter *Counter) context.Context

WithSessionByteCounter assigns the session byte counter to the context.

func WrapConn added in v3.16.0

func WrapConn(conn net.Conn, counter *Counter) net.Conn

WrapConn returns a new conn that uses the given counter.

func WrapHTTPTransport added in v3.16.0

func WrapHTTPTransport(txp model.HTTPTransport, counter *Counter) model.HTTPTransport

WrapHTTPTransport creates a new byte-counting-aware HTTP transport.

func WrapWithContextAwareDialer added in v3.16.0

func WrapWithContextAwareDialer(dialer model.Dialer) *contextAwareDialer

WrapWithContextAwareDialer creates a new ContextAwareDialer. See the docs of MaybeWrapWithContextAwareDialer for a list of caveats.

Types

type Counter

type Counter struct {
	// Received contains the bytes received. You MUST initialize
	// this field, or you can just use the New factory.
	Received *atomicx.Int64

	// Sent contains the bytes sent. You MUST initialize
	// this field, or you can just use the New factory.
	Sent *atomicx.Int64
}

Counter counts bytes sent and received.

func ContextExperimentByteCounter added in v3.14.0

func ContextExperimentByteCounter(ctx context.Context) *Counter

ContextExperimentByteCounter retrieves the experiment byte counter from the context

func ContextSessionByteCounter added in v3.14.0

func ContextSessionByteCounter(ctx context.Context) *Counter

ContextSessionByteCounter retrieves the session byte counter from the context

func New

func New() *Counter

New creates a new Counter.

func (*Counter) BytesReceived

func (c *Counter) BytesReceived() int64

BytesReceived returns the bytes received so far.

func (*Counter) BytesSent

func (c *Counter) BytesSent() int64

BytesSent returns the bytes sent so far.

func (*Counter) CountBytesReceived

func (c *Counter) CountBytesReceived(count int)

CountBytesReceived adds count to the bytes received counter.

func (*Counter) CountBytesSent

func (c *Counter) CountBytesSent(count int)

CountBytesSent adds count to the bytes sent counter.

func (*Counter) CountKibiBytesReceived

func (c *Counter) CountKibiBytesReceived(count float64)

CountKibiBytesReceived adds 1024*count to the bytes received counter.

func (*Counter) CountKibiBytesSent

func (c *Counter) CountKibiBytesSent(count float64)

CountKibiBytesSent adds 1024*count to the bytes sent counter.

func (*Counter) KibiBytesReceived

func (c *Counter) KibiBytesReceived() float64

KibiBytesReceived returns the KiB received so far.

func (*Counter) KibiBytesSent

func (c *Counter) KibiBytesSent() float64

KibiBytesSent returns the KiB sent so far.

func (*Counter) MaybeWrapHTTPTransport added in v3.16.0

func (c *Counter) MaybeWrapHTTPTransport(txp model.HTTPTransport) model.HTTPTransport

MaybeWrapHTTPTransport takes in input an HTTPTransport and either wraps it to perform byte counting, if this counter is not nil, or just returns to the caller the original transport, when the counter is nil.

Jump to

Keyboard shortcuts

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