Documentation ¶
Overview ¶
Package bytecounter contains code to track the number of bytes sent and received by a probe.
Index ¶
- func MaybeWrapConn(conn net.Conn, counter *Counter) net.Conn
- func MaybeWrapHTTPTransport(txp model.HTTPTransport, counter *Counter) model.HTTPTransport
- func MaybeWrapSystemResolver(reso model.Resolver, counter *Counter) model.Resolver
- func MaybeWrapWithContextAwareDialer(enabled bool, dialer model.Dialer) model.Dialer
- func MaybeWrapWithContextByteCounters(ctx context.Context, conn net.Conn) net.Conn
- func WithExperimentByteCounter(ctx context.Context, counter *Counter) context.Context
- func WithSessionByteCounter(ctx context.Context, counter *Counter) context.Context
- func WrapConn(conn net.Conn, counter *Counter) net.Conn
- func WrapHTTPTransport(txp model.HTTPTransport, counter *Counter) model.HTTPTransport
- func WrapSystemResolver(reso model.Resolver, counter *Counter) model.Resolver
- func WrapWithContextAwareDialer(dialer model.Dialer) *contextAwareDialer
- func WrapWithContextAwareSystemResolver(reso model.Resolver) model.Resolver
- type ContextAwareSystemResolver
- func (r *ContextAwareSystemResolver) Address() string
- func (r *ContextAwareSystemResolver) CloseIdleConnections()
- func (r *ContextAwareSystemResolver) LookupHTTPS(ctx context.Context, domain string) (*model.HTTPSSvc, error)
- func (r *ContextAwareSystemResolver) LookupHost(ctx context.Context, hostname string) (addrs []string, err error)
- func (r *ContextAwareSystemResolver) LookupNS(ctx context.Context, domain string) ([]*net.NS, error)
- func (r *ContextAwareSystemResolver) Network() string
- type Counter
- func (c *Counter) BytesReceived() int64
- func (c *Counter) BytesSent() int64
- func (c *Counter) CountBytesReceived(count int)
- func (c *Counter) CountBytesSent(count int)
- func (c *Counter) CountKibiBytesReceived(count float64)
- func (c *Counter) CountKibiBytesSent(count float64)
- func (c *Counter) KibiBytesReceived() float64
- func (c *Counter) KibiBytesSent() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaybeWrapConn ¶ added in v3.16.0
MaybeWrapConn is like wrap if counter is not nil, otherwise it's a no-op.
func MaybeWrapHTTPTransport ¶ added in v3.18.0
func MaybeWrapHTTPTransport(txp model.HTTPTransport, counter *Counter) 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.
func MaybeWrapSystemResolver ¶ added in v3.18.0
MaybeWrapSystemResolver takes in input a Resolver and either wraps it to perform byte counting, if this counter is not nil, or just returns to the caller the original resolver, when the counter is nil.
Caveat ¶
The returned resolver will only approximately estimate the bytes sent and received by this resolver if this resolver is the system resolver. For more accurate counting when using DNS over HTTPS, you should instead count at the HTTP transport level. If you are using DNS over TCP, DNS over TLS, or DNS over UDP, you should instead count the bytes by just wrapping the connections you're using.
func MaybeWrapWithContextAwareDialer ¶ added in v3.16.0
MaybeWrapWithContextAwareDialer wraps the given dialer with a ContextAwareDialer if the enabled argument is true and otherwise just returns the given dialer.
Caveat ¶
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.
As such, this implementation should only be used when measuring.
func MaybeWrapWithContextByteCounters ¶ added in v3.14.0
MaybeWrapWithContextByteCounters wraps a conn with the byte counters that have previosuly been configured into a context.
func WithExperimentByteCounter ¶ added in v3.14.0
WithExperimentByteCounter assigns the experiment byte counter to the context.
func WithSessionByteCounter ¶ added in v3.14.0
WithSessionByteCounter assigns the session byte counter to the context.
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 WrapSystemResolver ¶ added in v3.18.0
WrapSystemResolver creates a new byte-counting-aware resolver. This function returns a resolver with the same bugs of MaybeWrapSystemResolver.
func WrapWithContextAwareDialer ¶ added in v3.16.0
WrapWithContextAwareDialer creates a new ContextAwareDialer. See the docs of MaybeWrapWithContextAwareDialer for a list of caveats.
func WrapWithContextAwareSystemResolver ¶ added in v3.21.0
WrapWithContextAwareSystemResolver wraps the given resolver with a resolver that is aware of context-byte counting. See MaybeWrapSystemResolver for a list of caveats.
Types ¶
type ContextAwareSystemResolver ¶ added in v3.21.0
ContextAwareSystemResolver is a model.Resolver that knows how to count bytes sent and received. We typically use this for the system resolver only because for other resolvers we are better off just wrapping their connections.
func (*ContextAwareSystemResolver) Address ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) Address() string
Address implements model.Resolver.
func (*ContextAwareSystemResolver) CloseIdleConnections ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) CloseIdleConnections()
CloseIdleConnections implements model.Resolver.
func (*ContextAwareSystemResolver) LookupHTTPS ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) LookupHTTPS(ctx context.Context, domain string) (*model.HTTPSSvc, error)
LookupHTTPS implements model.Resolver.
func (*ContextAwareSystemResolver) LookupHost ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) LookupHost(ctx context.Context, hostname string) (addrs []string, err error)
LookupHost implements model.Resolver.
func (*ContextAwareSystemResolver) LookupNS ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) LookupNS(ctx context.Context, domain string) ([]*net.NS, error)
LookupNS implements model.Resolver.
func (*ContextAwareSystemResolver) Network ¶ added in v3.21.0
func (r *ContextAwareSystemResolver) Network() string
Network implements model.Resolver.
type Counter ¶
type Counter struct { // Received contains the bytes received. You MUST initialize // this field, or you can just use the New factory. Received *atomic.Int64 // Sent contains the bytes sent. You MUST initialize // this field, or you can just use the New factory. Sent *atomic.Int64 }
Counter counts bytes sent and received.
func ContextExperimentByteCounter ¶ added in v3.14.0
ContextExperimentByteCounter retrieves the possibly-nil experiment byte counter from the context.
func ContextSessionByteCounter ¶ added in v3.14.0
ContextSessionByteCounter retrieves the possibly-nil session byte counter from the context.
func (*Counter) BytesReceived ¶
BytesReceived returns the bytes received so far.
func (*Counter) CountBytesReceived ¶
CountBytesReceived adds count to the bytes received counter.
func (*Counter) CountBytesSent ¶
CountBytesSent adds count to the bytes sent counter.
func (*Counter) CountKibiBytesReceived ¶
CountKibiBytesReceived adds 1024*count to the bytes received counter.
func (*Counter) CountKibiBytesSent ¶
CountKibiBytesSent adds 1024*count to the bytes sent counter.
func (*Counter) KibiBytesReceived ¶
KibiBytesReceived returns the KiB received so far.
func (*Counter) KibiBytesSent ¶
KibiBytesSent returns the KiB sent so far.