rpc

package
v1.2.14-prerelease10 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package rpc contains a concurrent RPC client, and handles mapping to/from the Any-typed request details so other packages do not have to concern themselves with those details.

Package rpc is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregatorWeightsToAny

func AggregatorWeightsToAny(response map[algorithm.Limit]algorithm.HostUsage) (*types.Any, error)

AggregatorWeightsToAny converts the algorithm.RequestWeighted.HostWeights response (for an in-bound Update request) to an Any-type compatible with RPC.

func AnyToAggregatorUpdate

func AnyToAggregatorUpdate(request *types.Any) (algorithm.UpdateParams, error)

AnyToAggregatorUpdate converts an in-bound ratelimiter's Any-typed data to the structure that algorithm.RequestWeighted.Update expects.

func TestAnyToWeights

func TestAnyToWeights(t *testing.T, response *types.Any) (map[shared.GlobalKey]UpdateEntry, error)

TestAnyToWeights is exposed for handler tests, use anyToWeights in internal code instead

func TestUpdateToAny

func TestUpdateToAny(t *testing.T, host string, elapsed time.Duration, load map[shared.GlobalKey]Calls) (*types.Any, error)

TestUpdateToAny is exposed for handler tests, use updateToAny in internal code instead.

Types

type Calls

type Calls struct {
	Allowed  int
	Rejected int
}

type Client

type Client interface {
	// Update performs concurrent calls to all aggregating peers to send load info
	// and retrieve new per-key weights from the rest of the cluster.
	// This is intended to be called periodically in the background per process,
	// not synchronously or concurrently (per set of keys anyway), as it is fairly
	// high cost to shard keys and send so many requests.
	//
	// Currently, there are no truly fatal errors so this API does not return `error`.
	// Even in the presence of errors, some successful data may have been loaded,
	// and that will be part of the UpdateResult struct.
	Update(ctx context.Context, period time.Duration, load map[shared.GlobalKey]Calls) UpdateResult
}

func New

func New(
	historyClient history.Client,
	resolver history.PeerResolver,
	logger log.Logger,
	met metrics.Client,
) Client

type MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

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

func (*MockClient) Update

func (m *MockClient) Update(ctx context.Context, period time.Duration, load map[shared.GlobalKey]Calls) UpdateResult

Update mocks base method.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) Update

func (mr *MockClientMockRecorder) Update(ctx, period, load interface{}) *gomock.Call

Update indicates an expected call of Update.

type RPCError

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

RPCError wraps errors to mark them as coming from RPC, i.e. basically expected.

func (*RPCError) Error

func (e *RPCError) Error() string

func (*RPCError) Unwrap

func (e *RPCError) Unwrap() error

type SerializationError

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

SerializationError wraps errors to mark them as coming from (de)serialization.

In practice this should not ever occur, as it should imply one of: - incorrect Any Value/ValueType pairing, which should not pass tests - non-backwards-compatible type changes deployed in an unsafe way - incompatible Thrift-binary changes

func (*SerializationError) Error

func (e *SerializationError) Error() string

func (*SerializationError) Unwrap

func (e *SerializationError) Unwrap() error

type UpdateEntry added in v1.2.13

type UpdateEntry struct {
	Weight  float64
	UsedRPS float64
}

type UpdateResult

type UpdateResult struct {
	// all successfully-returned weights.
	// this may be populated and is safe to use even if Errors is present,
	// as some shards may have succeeded.
	Weights map[shared.GlobalKey]UpdateEntry
	// Any unexpected errors encountered, or nil if none.
	// Weights is valid even if this is present, though it may be empty.
	//
	// This should always be nil aside from major programming or rollout
	// errors, e.g. failures to serialize or deserialize data (coding errors
	// or incompatible server versions).
	Err error
}

UpdateResult holds all successes and errors encountered, to be distinct from fatal errors that imply unusable results (i.e. a normal error return).

Jump to

Keyboard shortcuts

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