interceptor

package
v1.32.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 58 Imported by: 0

Documentation

Overview

Package interceptor is a generated GoMock package.

Package interceptor is a generated GoMock package.

Index

Constants

View Source
const (
	// DCRedirectionPolicyDefault means no redirection
	DCRedirectionPolicyDefault = ""
	// DCRedirectionPolicyNoop means no redirection
	DCRedirectionPolicyNoop = "noop"
	// DCRedirectionPolicySelectedAPIsForwarding means forwarding the following APIs based namespace
	// 1. StartWorkflowExecution
	// 2. SignalWithStartWorkflowExecution
	// 3. SignalWorkflowExecution
	// 4. RequestCancelWorkflowExecution
	// 5. TerminateWorkflowExecution
	// 6. QueryWorkflow
	// please also reference selectedAPIsForwardingRedirectionPolicyWhitelistedAPIs
	DCRedirectionPolicySelectedAPIsForwarding = "selected-apis-forwarding"

	// DCRedirectionPolicyAllAPIsForwarding means forwarding all APIs based on namespace active cluster
	DCRedirectionPolicyAllAPIsForwarding = "all-apis-forwarding"
)
View Source
const (
	// ResourceExhaustedCauseHeader is added to rpc response if request returns ResourceExhausted error.
	ResourceExhaustedCauseHeader = "X-Resource-Exhausted-Cause"

	// ResourceExhaustedScopeHeader is added to rpc response if request returns ResourceExhausted error.
	ResourceExhaustedScopeHeader = "X-Resource-Exhausted-Scope"
)
View Source
const (
	DCRedirectionContextHeaderName    = "xdc-redirection"
	DCRedirectionAPIHeaderName        = "xdc-redirection-api"
	DCRedirectionSourceCellHeaderName = "xdc-redirection-source-cell"
)

Note the nexusoperations component references these headers and adds them to a list of disallowed headers for users to set. If any other headers are added for internal use, they should be added to the disallowed headers list.

View Source
const (
	NamespaceRateLimitDefaultToken = 1
)
View Source
const (
	RateLimitDefaultToken = 1
)

Variables

View Source
var (
	ErrNamespaceCountLimitServerBusy = &serviceerror.ResourceExhausted{
		Cause:   enumspb.RESOURCE_EXHAUSTED_CAUSE_CONCURRENT_LIMIT,
		Scope:   enumspb.RESOURCE_EXHAUSTED_SCOPE_NAMESPACE,
		Message: "namespace concurrent poller limit exceeded",
	}
)
View Source
var (
	ErrNamespaceRateLimitServerBusy = &serviceerror.ResourceExhausted{
		Cause:   enumspb.RESOURCE_EXHAUSTED_CAUSE_RPS_LIMIT,
		Scope:   enumspb.RESOURCE_EXHAUSTED_SCOPE_NAMESPACE,
		Message: "namespace rate limit exceeded",
	}
)
View Source
var (
	RateLimitServerBusy = &serviceerror.ResourceExhausted{
		Cause:   enumspb.RESOURCE_EXHAUSTED_CAUSE_RPS_LIMIT,
		Scope:   enumspb.RESOURCE_EXHAUSTED_SCOPE_SYSTEM,
		Message: "service rate limit exceeded",
	}
)

Functions

func AddRoutingKeyToContext

func AddRoutingKeyToContext(ctx context.Context, routingKey namespace.RoutingKey) context.Context

AddRoutingKeyToContext adds the routing Key to the context

func AddTelemetryContext

func AddTelemetryContext(ctx context.Context, metricsHandler metrics.Handler) context.Context

func CreateUnaryMetricsHandlerLogTags

func CreateUnaryMetricsHandlerLogTags(
	baseMetricsHandler metrics.Handler,
	req any,
	fullMethod string,
	methodName string,
	nsName namespace.Name,
) (metrics.Handler, []tag.Tag)

CreateUnaryMetricsHandlerLogTags creates metrics handler and log tags for unary RPC calls

func CustomErrorStreamInterceptor

func CustomErrorStreamInterceptor(
	srv any,
	serverStream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

func FromStatus

func FromStatus(st *status.Status) error

FromStatus converts gRPC Status to service error.

func GetMetricsHandlerFromContext

func GetMetricsHandlerFromContext(
	ctx context.Context,
	logger log.Logger,
) metrics.Handler

func GetNamespaceName

func GetNamespaceName(
	namespaceRegistry namespace.Registry,
	req any,
) (namespace.Name, error)

func GetRoutingKeyFromContext

func GetRoutingKeyFromContext(ctx context.Context) namespace.RoutingKey

GetRoutingKeyFromContext retrieves the routing Key from the context. Returns a zero-value RoutingKey if not found.

func IsLongPollDescribeActivityExecutionRequest

func IsLongPollDescribeActivityExecutionRequest(
	req any,
) bool

func IsLongPollGetWorkflowExecutionHistoryRequest

func IsLongPollGetWorkflowExecutionHistoryRequest(
	req any,
) bool

func MustGetNamespaceName

func MustGetNamespaceName(
	namespaceRegistry namespace.Registry,
	req any,
) namespace.Name

MustGetNamespaceName returns request namespace name or EmptyName if there's error when retrieving namespace name, e.g. unable to find namespace

func NewFrontendServiceErrorInterceptor

func NewFrontendServiceErrorInterceptor(
	logger log.Logger,
) grpc.UnaryServerInterceptor

NewFrontendServiceErrorInterceptor returns a gRPC interceptor that has two responsibilities:

  1. Mask certain internal service error details.
  2. Propagate resource exhaustion details via gRPC headers.

func NewHealthSignalAggregator

func NewHealthSignalAggregator(
	logger log.Logger,
	aggregatorEnabled dynamicconfig.BoolPropertyFn,
	percentilesEnabled dynamicconfig.BoolPropertyFn,
	getSettings dynamicconfig.TypedPropertyFn[health.Settings],
	windowSize time.Duration,
	maxBufferSize int,
) *healthSignalAggregatorImpl

NewHealthSignalAggregator creates a new instance of HealthSignalAggregatorImpl

func PopulateCallerInfo

func PopulateCallerInfo(
	ctx context.Context,
	nsNameGetter func() string,
	methodGetter func() string,
) context.Context

PopulateCallerInfo gets current caller info value from the context and updates any that are missing. Namespace name and method are passed as functions to avoid expensive lookups if those values are already set.

func StreamErrorInterceptor

func StreamErrorInterceptor(
	ctx context.Context,
	desc *grpc.StreamDesc,
	cc *grpc.ClientConn,
	method string,
	streamer grpc.Streamer,
	opts ...grpc.CallOption,
) (grpc.ClientStream, error)

func TrailerToContextMetadataInterceptor

func TrailerToContextMetadataInterceptor(logger log.Logger) grpc.UnaryClientInterceptor

TrailerToContextMetadataInterceptor reads metadata from gRPC response trailers and propagates it to the calling context using contextutil.ContextMetadataSet.

Requires the context to be pre-wrapped with contextutil.WithMetadataContext() before the RPC call. This is typically done by server-side interceptors (e.g., ContextMetadataInterceptor).

Types

type CallerInfoInterceptor

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

func NewCallerInfoInterceptor

func NewCallerInfoInterceptor(
	namespaceRegistry namespace.Registry,
) *CallerInfoInterceptor

func (*CallerInfoInterceptor) Intercept

func (i *CallerInfoInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type ClientStreamErrorInterceptor

type ClientStreamErrorInterceptor struct {
	grpc.ClientStream
}

func NewClientStreamErrorInterceptor

func NewClientStreamErrorInterceptor(
	clientStream grpc.ClientStream,
) *ClientStreamErrorInterceptor

func (*ClientStreamErrorInterceptor) CloseSend

func (c *ClientStreamErrorInterceptor) CloseSend() error

func (*ClientStreamErrorInterceptor) RecvMsg

func (c *ClientStreamErrorInterceptor) RecvMsg(m any) error

func (*ClientStreamErrorInterceptor) SendMsg

func (c *ClientStreamErrorInterceptor) SendMsg(m any) error

type ConcurrentRequestLimitInterceptor

type ConcurrentRequestLimitInterceptor struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConcurrentRequestLimitInterceptor intercepts requests to the server and enforces a limit on the number of requests that can be in-flight at any given time, according to the configured quotas.

func NewConcurrentRequestLimitInterceptor

func NewConcurrentRequestLimitInterceptor(
	namespaceRegistry namespace.Registry,
	memberCounter calculator.MemberCounter,
	logger log.Logger,
	perInstanceQuota func(ns string) int,
	globalQuota func(ns string) int,
	tokens map[string]int,
) *ConcurrentRequestLimitInterceptor

func (*ConcurrentRequestLimitInterceptor) Allow

func (ni *ConcurrentRequestLimitInterceptor) Allow(
	namespaceName namespace.Name,
	methodName string,
	mh metrics.Handler,
	req any,
) (func(), error)

func (*ConcurrentRequestLimitInterceptor) Intercept

func (ni *ConcurrentRequestLimitInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type ContextMetadataInterceptor

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

func NewContextMetadataInterceptor

func NewContextMetadataInterceptor(setTrailer bool, logger log.Logger) *ContextMetadataInterceptor

NewContextMetadataInterceptor creates a new ContextMetadataInterceptor

func (*ContextMetadataInterceptor) Intercept

func (c *ContextMetadataInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

Intercept wraps the request context with metadata storage and invokes the handler. When setTrailer is enabled, accumulated metadata is written to gRPC response trailers.

type DCRedirectionPolicy

type DCRedirectionPolicy interface {
	WithNamespaceIDRedirect(ctx context.Context, namespaceID namespace.ID, apiName string, req any, call func(string) error) error
	WithNamespaceRedirect(ctx context.Context, namespaceName namespace.Name, apiName string, req any, call func(string) error) error
}

DCRedirectionPolicy is a DC redirection policy interface

func RedirectionPolicyGenerator

func RedirectionPolicyGenerator(
	clusterMetadata cluster.Metadata,
	enabledForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	selectedAPIsOnlyForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	namespaceRegistry namespace.Registry,
	policy config.DCRedirectionPolicy,
) DCRedirectionPolicy

RedirectionPolicyGenerator generate corresponding redirection policy

type ErrorHandler

type ErrorHandler interface {
	HandleError(
		req any,
		fullMethod string,
		metricsHandler metrics.Handler,
		logTags []tag.Tag,
		err error,
		nsName namespace.Name,
	)
}

ErrorHandler defines the interface for handling request errors

type HealthCheckInterceptor

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

HealthCheckInterceptor is a gRPC interceptor that records health metrics

func NewHealthCheckInterceptor

func NewHealthCheckInterceptor(healthSignalAggregator HealthSignalAggregator) *HealthCheckInterceptor

NewHealthCheckInterceptor creates a new health check interceptor

func (*HealthCheckInterceptor) UnaryIntercept

func (h *HealthCheckInterceptor) UnaryIntercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

UnaryIntercept implements the gRPC unary interceptor interface

type HealthInterceptor

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

HealthInterceptor rejects frontend requests if the host has not been marked as healthy.

func NewHealthInterceptor

func NewHealthInterceptor() *HealthInterceptor

NewHealthInterceptor returns a new HealthInterceptor. It starts with state not healthy.

func (*HealthInterceptor) Intercept

func (i *HealthInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

func (*HealthInterceptor) SetHealthy

func (i *HealthInterceptor) SetHealthy(healthy bool)

type HealthSignalAggregator

type HealthSignalAggregator interface {
	Record(rpcMethod string, latency time.Duration, err error)
	AverageLatency() float64
	LatencyQuantile(quantile float64) (float64, bool)
	LatencyQuantileByGroup(groupName string, quantile float64) (float64, bool)
	ErrorRatio() (float64, bool)
	ErrorRatioByGroup(groupName string) (float64, bool)
	Stop()
}

HealthSignalAggregator interface for aggregating health signals. The accessors return false when no signal is available, which callers must not confuse with a healthy zero reading.

type MaskInternalErrorDetailsInterceptor

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

func NewMaskInternalErrorDetailsInterceptor

func NewMaskInternalErrorDetailsInterceptor(
	maskErrorSetting dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	namespaceRegistry namespace.Registry,
	logger log.Logger,
) *MaskInternalErrorDetailsInterceptor

func (*MaskInternalErrorDetailsInterceptor) Intercept

func (mi *MaskInternalErrorDetailsInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type MockDCRedirectionPolicy

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

MockDCRedirectionPolicy is a mock of DCRedirectionPolicy interface.

func NewMockDCRedirectionPolicy

func NewMockDCRedirectionPolicy(ctrl *gomock.Controller) *MockDCRedirectionPolicy

NewMockDCRedirectionPolicy creates a new mock instance.

func (*MockDCRedirectionPolicy) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDCRedirectionPolicy) WithNamespaceIDRedirect

func (m *MockDCRedirectionPolicy) WithNamespaceIDRedirect(ctx context.Context, namespaceID namespace.ID, apiName string, req any, call func(string) error) error

WithNamespaceIDRedirect mocks base method.

func (*MockDCRedirectionPolicy) WithNamespaceRedirect

func (m *MockDCRedirectionPolicy) WithNamespaceRedirect(ctx context.Context, namespaceName namespace.Name, apiName string, req any, call func(string) error) error

WithNamespaceRedirect mocks base method.

type MockDCRedirectionPolicyMockRecorder

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

MockDCRedirectionPolicyMockRecorder is the mock recorder for MockDCRedirectionPolicy.

func (*MockDCRedirectionPolicyMockRecorder) WithNamespaceIDRedirect

func (mr *MockDCRedirectionPolicyMockRecorder) WithNamespaceIDRedirect(ctx, namespaceID, apiName, req, call any) *gomock.Call

WithNamespaceIDRedirect indicates an expected call of WithNamespaceIDRedirect.

func (*MockDCRedirectionPolicyMockRecorder) WithNamespaceRedirect

func (mr *MockDCRedirectionPolicyMockRecorder) WithNamespaceRedirect(ctx, namespaceName, apiName, req, call any) *gomock.Call

WithNamespaceRedirect indicates an expected call of WithNamespaceRedirect.

type MockErrorHandler

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

MockErrorHandler is a mock of ErrorHandler interface.

func NewMockErrorHandler

func NewMockErrorHandler(ctrl *gomock.Controller) *MockErrorHandler

NewMockErrorHandler creates a new mock instance.

func (*MockErrorHandler) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockErrorHandler) HandleError

func (m *MockErrorHandler) HandleError(req any, fullMethod string, metricsHandler metrics.Handler, logTags []tag.Tag, err error, nsName namespace.Name)

HandleError mocks base method.

type MockErrorHandlerMockRecorder

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

MockErrorHandlerMockRecorder is the mock recorder for MockErrorHandler.

func (*MockErrorHandlerMockRecorder) HandleError

func (mr *MockErrorHandlerMockRecorder) HandleError(req, fullMethod, metricsHandler, logTags, err, nsName any) *gomock.Call

HandleError indicates an expected call of HandleError.

type NamespaceHandoverInterceptor

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

NamespaceHandoverInterceptor handles the namespace in handover replication state

func NewNamespaceHandoverInterceptor

func NewNamespaceHandoverInterceptor(
	dc *dynamicconfig.Collection,
	namespaceRegistry namespace.Registry,
	metricsHandler metrics.Handler,
	logger log.Logger,
	timeSource clock.TimeSource,
	requestErrorHandler ErrorHandler,
	additionalAllowedMethodsDuringHandover []string,
) *NamespaceHandoverInterceptor

func (*NamespaceHandoverInterceptor) Intercept

func (i *NamespaceHandoverInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (_ any, retError error)

func (*NamespaceHandoverInterceptor) WithAdditionalServicePrefixes

func (i *NamespaceHandoverInterceptor) WithAdditionalServicePrefixes(prefixes ...string) *NamespaceHandoverInterceptor

WithAdditionalServicePrefixes returns a copy of the interceptor whose handover gate also applies to methods under the given gRPC service prefixes (besides WorkflowService). Embedders use this to extend the gate to other transports without this package referencing them.

type NamespaceIDGetter

type NamespaceIDGetter interface {
	GetNamespaceId() string
}

gRPC method request must implement either NamespaceNameGetter or NamespaceIDGetter for namespace specific metrics to be reported properly

type NamespaceLogInterceptor

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

func NewNamespaceLogInterceptor

func NewNamespaceLogInterceptor(namespaceRegistry namespace.Registry, logger log.Logger) *NamespaceLogInterceptor

func (*NamespaceLogInterceptor) Intercept

func (nli *NamespaceLogInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type NamespaceNameGetter

type NamespaceNameGetter interface {
	GetNamespace() string
}

gRPC method request must implement either NamespaceNameGetter or NamespaceIDGetter for namespace specific metrics to be reported properly

type NamespaceRateLimitInterceptor

type NamespaceRateLimitInterceptor interface {
	Intercept(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error)
	Allow(namespaceName namespace.Name, methodName string, headerGetter headers.HeaderGetter) error
	Wait(ctx context.Context, namespaceName namespace.Name, methodName string, headerGetter headers.HeaderGetter) error
}

func NewNamespaceRateLimitInterceptor

func NewNamespaceRateLimitInterceptor(
	namespaceRegistry namespace.Registry,
	rateLimiter quotas.RequestRateLimiter,
	tokens map[string]int,
	pollMethods map[string]struct{},
	pollWaitForToken dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	metricsHandler metrics.Handler,
) NamespaceRateLimitInterceptor

type NamespaceRateLimitInterceptorImpl

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

func (*NamespaceRateLimitInterceptorImpl) Allow

func (ni *NamespaceRateLimitInterceptorImpl) Allow(namespaceName namespace.Name, methodName string, headerGetter headers.HeaderGetter) error

func (*NamespaceRateLimitInterceptorImpl) Intercept

func (ni *NamespaceRateLimitInterceptorImpl) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

func (*NamespaceRateLimitInterceptorImpl) Wait

func (ni *NamespaceRateLimitInterceptorImpl) Wait(ctx context.Context, namespaceName namespace.Name, methodName string, headerGetter headers.HeaderGetter) error

type NamespaceValidatorInterceptor

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

NamespaceValidatorInterceptor contains NamespaceValidateIntercept and StateValidationIntercept

func NewNamespaceValidatorInterceptor

func NewNamespaceValidatorInterceptor(
	namespaceRegistry namespace.Registry,
	enableTokenNamespaceEnforcement dynamicconfig.BoolPropertyFn,
	maxNamespaceLength dynamicconfig.IntPropertyFn,
	additionalAllowedMethodsDuringHandover []string,
) *NamespaceValidatorInterceptor

func (*NamespaceValidatorInterceptor) NamespaceValidateIntercept

func (ni *NamespaceValidatorInterceptor) NamespaceValidateIntercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

func (*NamespaceValidatorInterceptor) StateValidationIntercept

func (ni *NamespaceValidatorInterceptor) StateValidationIntercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

StateValidationIntercept runs ValidateState - see docstring for that method.

func (*NamespaceValidatorInterceptor) ValidateName

func (ni *NamespaceValidatorInterceptor) ValidateName(ns string) error

ValidateName validates a namespace name (currently only a max length check).

func (*NamespaceValidatorInterceptor) ValidateState

func (ni *NamespaceValidatorInterceptor) ValidateState(namespaceEntry *namespace.Namespace, fullMethod string, businessID string) error

ValidateState validates: 1. Namespace is specified in task token if there is a `task_token` field. 2. Namespace is specified in request if there is a `namespace` field and no `task_token` field. 3. Namespace exists. 4. Namespace from request match namespace from task token, if check is enabled with dynamic config. 5. Namespace is in correct state.

type NoopRedirectionPolicy

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

NoopRedirectionPolicy is DC redirection policy which does nothing

func NewNoopRedirectionPolicy

func NewNoopRedirectionPolicy(currentClusterName string) *NoopRedirectionPolicy

NewNoopRedirectionPolicy is DC redirection policy which does nothing

func (*NoopRedirectionPolicy) WithNamespaceIDRedirect

func (policy *NoopRedirectionPolicy) WithNamespaceIDRedirect(_ context.Context, _ namespace.ID, _ string, _ any, call func(string) error) error

WithNamespaceIDRedirect redirect the API call based on namespace ID

func (*NoopRedirectionPolicy) WithNamespaceRedirect

func (policy *NoopRedirectionPolicy) WithNamespaceRedirect(_ context.Context, _ namespace.Name, _ string, _ any, call func(string) error) error

WithNamespaceRedirect redirect the API call based on namespace name

type RateLimitInterceptor

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

func NewRateLimitInterceptor

func NewRateLimitInterceptor(
	rateLimiter quotas.RequestRateLimiter,
	tokens map[string]int,
) *RateLimitInterceptor

func (*RateLimitInterceptor) Allow

func (i *RateLimitInterceptor) Allow(
	methodName string,
	headerGetter headers.HeaderGetter,
) error

func (*RateLimitInterceptor) Intercept

func (i *RateLimitInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type Redirection

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

Redirection is simple wrapper over frontend service, doing redirection based on policy

func NewRedirection

func NewRedirection(
	enabledForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	selectedAPIsOnlyForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	namespaceCache namespace.Registry,
	policy config.DCRedirectionPolicy,
	logger log.Logger,
	clientBean client.Bean,
	metricsHandler metrics.Handler,
	timeSource clock.TimeSource,
	clusterMetadata cluster.Metadata,
) *Redirection

NewRedirection creates DC redirection interceptor

func (*Redirection) AfterCall

func (i *Redirection) AfterCall(
	metricsHandler metrics.Handler,
	startTime time.Time,
	targetClusterName string,
	namespaceName string,
	retError error,
)

func (*Redirection) BeforeCall

func (i *Redirection) BeforeCall(
	operation string,
) (metrics.Handler, time.Time)

func (*Redirection) Intercept

func (i *Redirection) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (_ any, retError error)

func (*Redirection) RedirectionAllowed

func (i *Redirection) RedirectionAllowed(
	ctx context.Context,
) bool

func (*Redirection) WithRedirectResponses

func (i *Redirection) WithRedirectResponses(responses map[string]func() any) *Redirection

WithRedirectResponses returns a copy of the interceptor that treats the given fullMethod -> response-constructor entries as globally-redirectable APIs, keyed by full gRPC method so they don't collide with the bare-method-name maps. The registered requests must expose their namespace (via NamespaceNameGetter/NamespaceIDGetter) so it can be resolved for redirection.

type RequestErrorHandler

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

RequestErrorHandler handles error recording and logging for RPC interceptors

func NewRequestErrorHandler

func NewRequestErrorHandler(
	logger log.Logger,
	logAllReqErrors dynamicconfig.BoolPropertyFnWithNamespaceFilter,
) *RequestErrorHandler

NewRequestErrorHandler creates a new RequestErrorHandler

func (*RequestErrorHandler) HandleError

func (eh *RequestErrorHandler) HandleError(
	req any,
	fullMethod string,
	metricsHandler metrics.Handler,
	logTags []tag.Tag,
	err error,
	nsName namespace.Name,
)

HandleError handles error recording and logging

type RetryableInterceptor

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

func NewRetryableInterceptor

func NewRetryableInterceptor(
	policy backoff.RetryPolicy,
	isRetryable backoff.IsRetryable,
) *RetryableInterceptor

func (*RetryableInterceptor) Intercept

func (i *RetryableInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type RoutingKeyExtractor

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

func NewRoutingKeyExtractor

func NewRoutingKeyExtractor() RoutingKeyExtractor

func (RoutingKeyExtractor) Extract

Extract extracts routing key from the request using the specified pattern. Returns a zero-value namespace.RoutingKey if not found.

type RoutingKeyExtractorFunc

type RoutingKeyExtractorFunc func(ctx context.Context, req any, fullMethod string) namespace.RoutingKey

RoutingKeyExtractorFunc extracts routing key from a request. Returns a zero-value RoutingKey if this extractor doesn't handle the request.

func WorkflowServiceExtractor

func WorkflowServiceExtractor(extractor RoutingKeyExtractor) RoutingKeyExtractorFunc

WorkflowServiceExtractor returns a RoutingKeyExtractorFunc that extracts the routing key from WorkflowService API requests using the provided RoutingKeyExtractor.

type RoutingKeyInterceptor

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

RoutingKeyInterceptor extracts routing key from requests and adds it to context. It iterates through a list of extractor functions until one returns a non-empty routing key.

func NewRoutingKeyInterceptor

func NewRoutingKeyInterceptor(
	extractors []RoutingKeyExtractorFunc,
	logger log.Logger,
) *RoutingKeyInterceptor

NewRoutingKeyInterceptor creates a new RoutingKeyInterceptor with the given extractor functions. Extractors are called in order until one returns a non-empty routing key.

func (*RoutingKeyInterceptor) Intercept

func (i *RoutingKeyInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

Intercept extracts routing key from the request and adds it to the context. It tries each extractor in order until one returns a non-empty routing key.

func (*RoutingKeyInterceptor) WithExtractors

func (i *RoutingKeyInterceptor) WithExtractors(extractors ...RoutingKeyExtractorFunc) *RoutingKeyInterceptor

WithExtractors returns a new interceptor with additional extractors prepended. The new extractors will be tried before the existing ones.

type RoutingKeyPattern

type RoutingKeyPattern int

RoutingKeyPattern defines the expected interface pattern for extracting routing key

const (
	// PatternNone indicates no routing key extraction is needed
	PatternNone RoutingKeyPattern = iota
	// PatternWorkflowID indicates extraction via GetWorkflowId() method
	PatternWorkflowID
	// PatternExecution indicates extraction via GetExecution().GetWorkflowId()
	PatternExecution
	// PatternTaskToken indicates extraction via deserializing GetTaskToken()
	PatternTaskToken
	// PatternMultiOperation indicates extraction from ExecuteMultiOperationRequest
	PatternMultiOperation
	// PatternNamespace indicates extraction via GetNamespace() - used when we want to send all calls to a particular api and namespace to a single cell at a time.
	PatternNamespace
)

type SDKVersionInterceptor

type SDKVersionInterceptor struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSDKVersionInterceptor

func NewSDKVersionInterceptor() *SDKVersionInterceptor

NewSDKVersionInterceptor creates a new SDKVersionInterceptor with default max set size

func (*SDKVersionInterceptor) GetAndResetSDKInfo

func (vi *SDKVersionInterceptor) GetAndResetSDKInfo() []versioninfo.SDKInfo

GetAndResetSDKInfo gets all recorded name, version tuples and resets internal records

func (*SDKVersionInterceptor) Intercept

func (vi *SDKVersionInterceptor) Intercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

Intercept a grpc request

func (*SDKVersionInterceptor) RecordSDKInfo

func (vi *SDKVersionInterceptor) RecordSDKInfo(name, version string)

RecordSDKInfo records name and version tuple in memory

type SelectedAPIsForwardingRedirectionPolicy

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

SelectedAPIsForwardingRedirectionPolicy is a DC redirection policy which (based on namespace) forwards selected APIs calls to active cluster

func NewAllAPIsForwardingPolicy

func NewAllAPIsForwardingPolicy(
	currentClusterName string,
	enabledForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	selectedAPIsOnlyForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	namespaceRegistry namespace.Registry,
) *SelectedAPIsForwardingRedirectionPolicy

NewAllAPIsForwardingPolicy creates a forwarding policy for all APIs based on namespace

func NewSelectedAPIsForwardingPolicy

func NewSelectedAPIsForwardingPolicy(
	currentClusterName string,
	enabledForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	selectedAPIsOnlyForNS dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	namespaceRegistry namespace.Registry,
) *SelectedAPIsForwardingRedirectionPolicy

NewSelectedAPIsForwardingPolicy creates a forwarding policy for selected APIs based on namespace

func (*SelectedAPIsForwardingRedirectionPolicy) WithNamespaceIDRedirect

func (policy *SelectedAPIsForwardingRedirectionPolicy) WithNamespaceIDRedirect(ctx context.Context, namespaceID namespace.ID, apiName string, _ any, call func(string) error) error

WithNamespaceIDRedirect redirect the API call based on namespace ID

func (*SelectedAPIsForwardingRedirectionPolicy) WithNamespaceRedirect

func (policy *SelectedAPIsForwardingRedirectionPolicy) WithNamespaceRedirect(ctx context.Context, namespaceName namespace.Name, apiName string, _ any, call func(string) error) error

WithNamespaceRedirect redirect the API call based on namespace name

type ServiceErrorInterceptor

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

func NewServiceErrorInterceptor

func NewServiceErrorInterceptor(
	maxMessageLength dynamicconfig.IntPropertyFn,
	metricsHandler metrics.Handler,
	logger log.Logger,
) *ServiceErrorInterceptor

func (*ServiceErrorInterceptor) Intercept

func (i *ServiceErrorInterceptor) Intercept(
	ctx context.Context,
	req any,
	_ *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type SlowRequestLoggerInterceptor

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

func NewSlowRequestLoggerInterceptor

func NewSlowRequestLoggerInterceptor(
	logger log.Logger,
	slowRequestThreshold dynamicconfig.DurationPropertyFn,
) *SlowRequestLoggerInterceptor

func (*SlowRequestLoggerInterceptor) Intercept

func (i *SlowRequestLoggerInterceptor) Intercept(
	ctx context.Context,
	request any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

type TaskTokenGetter

type TaskTokenGetter interface {
	GetTaskToken() []byte
}

type TelemetryInterceptor

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

func NewTelemetryInterceptor

func NewTelemetryInterceptor(
	namespaceRegistry namespace.Registry,
	metricsHandler metrics.Handler,
	logger log.Logger,
	logAllReqErrors dynamicconfig.BoolPropertyFnWithNamespaceFilter,
	requestErrorHandler ErrorHandler,
) *TelemetryInterceptor

func (*TelemetryInterceptor) RecordLatencyMetrics

func (ti *TelemetryInterceptor) RecordLatencyMetrics(ctx context.Context, startTime time.Time, metricsHandler metrics.Handler)

func (*TelemetryInterceptor) StreamIntercept

func (ti *TelemetryInterceptor) StreamIntercept(
	service any,
	serverStream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

func (*TelemetryInterceptor) UnaryIntercept

func (ti *TelemetryInterceptor) UnaryIntercept(
	ctx context.Context,
	req any,
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (any, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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