proxy

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Subsystem = defaultSubsystem

Functions

func BytesCounterReaderWrap

func BytesCounterReaderWrap(r io.Reader) io.ReadCloser

func BytesCounterWriterWrap

func BytesCounterWriterWrap(w io.Writer) io.Writer

func CounterReset

func CounterReset(wrapped interface{})

func CounterValue

func CounterValue(wrapped interface{}) int

func FromTargetAction

func FromTargetAction(proxyMode ProxyMode) rewriter.Action

func LoggerWithCommonAttrs

func LoggerWithCommonAttrs(ctx context.Context, attrs ...any) *slog.Logger

func RegisterMetrics

func RegisterMetrics()

func ToTargetAction

func ToTargetAction(proxyMode ProxyMode) rewriter.Action

func WatchLabel

func WatchLabel(isWatch bool) string

Types

type Handler

type Handler struct {
	Name string
	// ProxyPass is a target http client to send requests to.
	// An allusion to nginx proxy_pass directive.
	TargetClient    *http.Client
	TargetURL       *url.URL
	ProxyMode       ProxyMode
	Rewriter        *rewriter.RuleBasedRewriter
	MetricsProvider MetricsProvider
	// contains filtered or unexported fields
}

func (*Handler) Init

func (h *Handler) Init()

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type MetricsProvider

type MetricsProvider interface {
	NewClientRequestsTotal(name, resource, method, watch, decision string) prometheus.Counter
	NewTargetResponsesTotal(name, resource, method, watch, decision, status, error string) prometheus.Counter
	NewTargetResponseInvalidJSONTotal(name, resource, method, watch, status string) prometheus.Counter
	NewRequestsHandledTotal(name, resource, method, watch, decision, status, error string) prometheus.Counter
	NewRequestsHandlingSeconds(name, resource, method, watch, decision, status string) prometheus.Observer
	NewRewritesTotal(name, resource, method, watch, side, operation, error string) prometheus.Counter
	NewRewritesDurationSeconds(name, resource, method, watch, side, operation string) prometheus.Observer
	NewFromClientBytesTotal(name, resource, method, watch, decision string) prometheus.Counter
	NewToTargetBytesTotal(name, resource, method, watch, decision string) prometheus.Counter
	NewFromTargetBytesTotal(name, resource, method, watch, decision string) prometheus.Counter
	NewToClientBytesTotal(name, resource, method, watch, decision string) prometheus.Counter
}

func NewMetricsProvider

func NewMetricsProvider() MetricsProvider

func NoopMetricsProvider

func NoopMetricsProvider() MetricsProvider

type ProxyMetrics

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

func NewProxyMetrics

func NewProxyMetrics(ctx context.Context, provider MetricsProvider) *ProxyMetrics

func (*ProxyMetrics) ClientRequestRewriteDuration

func (p *ProxyMetrics) ClientRequestRewriteDuration(dur time.Duration)

func (*ProxyMetrics) ClientRequestRewriteError

func (p *ProxyMetrics) ClientRequestRewriteError()

func (*ProxyMetrics) ClientRequestRewriteSuccess

func (p *ProxyMetrics) ClientRequestRewriteSuccess()

func (*ProxyMetrics) FromClientBytesAdd

func (p *ProxyMetrics) FromClientBytesAdd(decision string, count int)

func (*ProxyMetrics) FromTargetBytesAdd

func (p *ProxyMetrics) FromTargetBytesAdd(count int)

func (*ProxyMetrics) GotClientRequest

func (p *ProxyMetrics) GotClientRequest()

func (*ProxyMetrics) RequestDuration

func (p *ProxyMetrics) RequestDuration(dur time.Duration)

func (*ProxyMetrics) RequestHandleError

func (p *ProxyMetrics) RequestHandleError()

func (*ProxyMetrics) RequestHandleSuccess

func (p *ProxyMetrics) RequestHandleSuccess()

func (*ProxyMetrics) TargetResponseError

func (p *ProxyMetrics) TargetResponseError()

func (*ProxyMetrics) TargetResponseInvalidJSON

func (p *ProxyMetrics) TargetResponseInvalidJSON(status int)

func (*ProxyMetrics) TargetResponseRewriteDuration

func (p *ProxyMetrics) TargetResponseRewriteDuration(dur time.Duration)

func (*ProxyMetrics) TargetResponseRewriteError

func (p *ProxyMetrics) TargetResponseRewriteError()

func (*ProxyMetrics) TargetResponseRewriteSuccess

func (p *ProxyMetrics) TargetResponseRewriteSuccess()

func (*ProxyMetrics) TargetResponseSuccess

func (p *ProxyMetrics) TargetResponseSuccess(decision string)

func (*ProxyMetrics) ToClientBytesAdd

func (p *ProxyMetrics) ToClientBytesAdd(count int)

func (*ProxyMetrics) ToTargetBytesAdd

func (p *ProxyMetrics) ToTargetBytesAdd(decision string, count int)

type ProxyMode

type ProxyMode string
const (
	// ToOriginal mode indicates that resource should be restored when passed to target and renamed when passing back to client.
	ToOriginal ProxyMode = "original"
	// ToRenamed mode indicates that resource should be renamed when passed to target and restored when passing back to client.
	ToRenamed ProxyMode = "renamed"
)

type StreamHandler

type StreamHandler struct {
	Rewriter        *rewriter.RuleBasedRewriter
	MetricsProvider MetricsProvider
}

StreamHandler reads a stream from the target, transforms events and sends them to the client.

func (*StreamHandler) Handle

Handle starts a go routine to pass rewritten Watch Events from server to client. Sources: k8s.io/apimachinery@v0.26.1/pkg/watch/streamwatcher.go:100 receive method k8s.io/kubernetes@v1.13.0/staging/src/k8s.io/client-go/rest/request.go:537 wrapperFn, create framer. k8s.io/kubernetes@v1.13.0/staging/src/k8s.io/client-go/rest/request.go:598 instantiate watch NewDecoder

Jump to

Keyboard shortcuts

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