streams

package
v0.0.0-...-109c5d9 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Will be set by one of the metrics options to wrap a handler and transport
	MetricsHandlerWrapper func(http.Handler) http.Handler

	MetricsClientTransportWrapper func(tripper http.RoundTripper) http.RoundTripper
)
View Source
var Debug = true

Functions

This section is empty.

Types

type Metric

type Metric interface {
	Add(float64)
}

Metric is an interface for applications updating metrics Expvar is an interface between metric and the collection system.

type MetricProvider

type MetricProvider interface {

	// Can only go up. Current value tracked.
	NewCounter(name, descr string, opts ...string) Metric

	// Like counter, but can go down. Mean, min, max ( and sum, count) are tracked.
	NewGauge(name, descr string, opts ...string) Metric

	// Tracks 50, 90, 99% value of all Add events.
	NewHistogram(name, descr string, opts ...string) Metric
}

Abstract creation of metrics - zserge(minimal with UI) for local, prom or OC for servers. The opts are currently used for in-process time-series. If specified and an in-process implementation exists it'll be used. The parameter is 'total' and 'interval' - total/interval is the number of samples. External timeseries have their own polling interval and aggregation. If metrics are pushed, the first interval is used to control the rate.

var (
	// Singleton factory
	Metrics MetricProvider = &NoMetrics{}
)

type NoMetrics

type NoMetrics struct {
}

func (*NoMetrics) NewCounter

func (*NoMetrics) NewCounter(name, descr string, labels ...string) Metric

func (*NoMetrics) NewGauge

func (*NoMetrics) NewGauge(name, descr string, labels ...string) Metric

func (*NoMetrics) NewHistogram

func (*NoMetrics) NewHistogram(name, descr string, labels ...string) Metric

type ServiceMetrics

type ServiceMetrics struct {
	// Active requests, gauge.
	Active Metric

	// Total requests, counter
	Total  Metric
	Errors Metric

	// Service latency (total).
	Latency Metric
}

Set of metrics used by client or server of a service.

func NewServiceMetrics

func NewServiceMetrics(base string, descr string) *ServiceMetrics

type TcpProxy

type TcpProxy struct {
	ugate.Stream

	OnProxyClose func(proxy *TcpProxy)

	// Client stream reader, data from captured/local app to remote.
	// Set when the proxy is created, based on the captured stream.
	//
	// - For socks or accept capture, a TCPConnection
	// - For accept, a net.Conn
	// - for TCP-over-HTTP server - req.Body
	// - ...
	ClientIn io.ReadCloser

	// A chunk of initial data, to be sent before localIn.
	// Currently not used - SNI proxy and other cases where data is sent along var-len header might use it.
	Initial []byte

	// Client stream writer.
	//
	// - for socks - a TCPConnection
	// - for accept, a net.Conn
	// - for TCP-over-HTTP - a http.Writer.
	//
	// When the remoteIn is closed, the appropriate CloseWrite must be called, to send the FIN to the other side.
	// Note that reading from clientIn might continue.
	ClientOut io.Writer

	// remoteCtx is a context associated with the remote side connection, for example in http cases.
	RemoteCtx context.CancelFunc

	// Address of the connected endpoint, previous hop.
	// OriginIP/OriginPort track the real client, and PrevPath
	// the path.
	ClientAddr net.Addr

	// Original client from the interception -host:port, result of net.JoinHostPort
	//
	// In the origin server it's typically 127.0.0.1:XXXX.
	// When forwarded, it should be translated to VIP : OriginStreamID
	Origin string

	// True if the destination is local, no VPN needed
	// Used for VPN-accepted connections forwarded to directly
	// reachable hosts, disables dialing through other VPNs.
	DestDirectNoVPN bool

	DestIP net.IP

	// DestPort is set
	DestPort int
}

=== L4/TCP common code ===

- Handles SOCKS, HTTP CONNECT, TUN captured - opens a connection to the remote site, proxies packets - keeps stats - buffer reuse. - handles accepted connections sent back over SSHClientConn or direct

Implements ReadCloser over the localIn stream - so it can be passed to http.Post() or used for reading.

func (*TcpProxy) Close

func (tp *TcpProxy) Close() error

Explicit close - for example for idle.

func (*TcpProxy) LocalAddr

func (tp *TcpProxy) LocalAddr() net.Addr

func (*TcpProxy) Proxy

func (tp *TcpProxy) Proxy() error

Proxy will start forwarding the connection to the remote. This is a blocking call - will return when done.

func (*TcpProxy) ProxyConnClose

func (tp *TcpProxy) ProxyConnClose(client net.Conn) error

This is the main function used with the DialProxy interface

func (*TcpProxy) RemoteAddr

func (tp *TcpProxy) RemoteAddr() net.Addr

func (*TcpProxy) SetDeadline

func (tp *TcpProxy) SetDeadline(t time.Time) error

func (*TcpProxy) SetDest

func (tp *TcpProxy) SetDest(dest string) error

func (*TcpProxy) SetDestAddr

func (tp *TcpProxy) SetDestAddr(addr *net.TCPAddr)

func (*TcpProxy) SetReadDeadline

func (tp *TcpProxy) SetReadDeadline(t time.Time) error

func (*TcpProxy) SetWriteDeadline

func (tp *TcpProxy) SetWriteDeadline(t time.Time) error

Jump to

Keyboard shortcuts

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