proxy

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

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

func WrapRESTConfig added in v0.2.0

func WrapRESTConfig(cfg *rest.Config, wrapper http.RoundTripper)

WrapRESTConfig attaches a transport wrapper to the provided rest.Config. For proxy.RoundTripper it also wires the previous transport into Base.

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 RoundTripper added in v0.2.0

type RoundTripper struct {
	Name            string
	Base            http.RoundTripper
	ProxyMode       ProxyMode
	Rewriter        *rewriter.RuleBasedRewriter
	MetricsProvider MetricsProvider
	// contains filtered or unexported fields
}

RoundTripper rewrites Kubernetes API requests and responses without an HTTP sidecar proxy. It is intended to wrap kubeclient transport in-process.

func NewProxyRoundTripper added in v0.2.0

func NewProxyRoundTripper(name string, mode ProxyMode, rules *rewriter.RewriteRules) *RoundTripper

func (*RoundTripper) RoundTrip added in v0.2.0

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

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

func (*StreamHandler) Rewrite added in v0.2.0

func (s *StreamHandler) Rewrite(ctx context.Context, dst io.Writer, resp *http.Response, targetReq *rewriter.TargetRequest) error

Rewrite reads a watch stream from resp, rewrites its events and writes them to dst.

Jump to

Keyboard shortcuts

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