discovery

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package discovery provides the interface for matching gRPC requests to upstreams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConn added in v0.3.0

type ClientConn struct {
	ConnName        string
	ServeReflection bool
	*grpc.ClientConn
}

ClientConn is a named closable client connection.

func (ClientConn) Name added in v0.3.0

func (n ClientConn) Name() string

Name returns the name of the connection.

func (ClientConn) Reflection added in v0.3.0

func (n ClientConn) Reflection() bool

Reflection returns true if the connection serves reflection.

type Forward added in v0.3.0

type Forward struct {
	Upstream Upstream
	Header   metadata.MD
}

Forward specifies the upstream to forward the request and the parameters to invoke the upstream.

type Matches

type Matches []*Rule

Matches is a set of matches.

func (Matches) MatchMessage

func (m Matches) MatchMessage(bts []byte) (*Rule, bool)

MatchMessage matches the given gRPC request to a rule. It returns the first match and true if the request is matched.

func (Matches) NeedsDeeperMatch

func (m Matches) NeedsDeeperMatch() bool

NeedsDeeperMatch returns true if first RECV message is needed to match the request.

type Mock

type Mock struct {
	Header  metadata.MD
	Trailer metadata.MD
	Body    proto.Message
	Status  *status.Status
}

Mock contains the details of how the handler should reply to the downstream.

type Provider

type Provider interface {
	// Name returns the name of the provider.
	Name() string

	// Events returns the events of the routing rules.
	// It returns the name of the provider to update the routing rules.
	Events(ctx context.Context) <-chan string

	// State returns the current state of the provider.
	State(ctx context.Context) (*State, error)
}

Provider provides routing rules for the Service.

type ProviderMock

type ProviderMock struct {
	// EventsFunc mocks the Events method.
	EventsFunc func(ctx context.Context) <-chan string

	// NameFunc mocks the Name method.
	NameFunc func() string

	// StateFunc mocks the State method.
	StateFunc func(ctx context.Context) (*State, error)
	// contains filtered or unexported fields
}

ProviderMock is a mock implementation of Provider.

func TestSomethingThatUsesProvider(t *testing.T) {

	// make and configure a mocked Provider
	mockedProvider := &ProviderMock{
		EventsFunc: func(ctx context.Context) <-chan string {
			panic("mock out the Events method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		StateFunc: func(ctx context.Context) (*State, error) {
			panic("mock out the State method")
		},
	}

	// use mockedProvider in code that requires Provider
	// and then make assertions.

}

func (*ProviderMock) Events

func (mock *ProviderMock) Events(ctx context.Context) <-chan string

Events calls EventsFunc.

func (*ProviderMock) EventsCalls

func (mock *ProviderMock) EventsCalls() []struct {
	Ctx context.Context
}

EventsCalls gets all the calls that were made to Events. Check the length with:

len(mockedProvider.EventsCalls())

func (*ProviderMock) Name

func (mock *ProviderMock) Name() string

Name calls NameFunc.

func (*ProviderMock) NameCalls

func (mock *ProviderMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedProvider.NameCalls())

func (*ProviderMock) State added in v0.3.0

func (mock *ProviderMock) State(ctx context.Context) (*State, error)

State calls StateFunc.

func (*ProviderMock) StateCalls added in v0.3.0

func (mock *ProviderMock) StateCalls() []struct {
	Ctx context.Context
}

StateCalls gets all the calls that were made to State. Check the length with:

len(mockedProvider.StateCalls())

type RequestMatcher

type RequestMatcher struct {
	// URI defines the fully-qualified method name, e.g.
	// "/package.Service/Method".
	URI *regexp.Regexp

	// IncomingMetadata contains the metadata of the incoming request.
	IncomingMetadata metadata.MD

	// Message contains the expected first RECV message of the request.
	Message proto.Message
}

RequestMatcher defines parameters to match the request to the rule.

func (RequestMatcher) Matches

func (r RequestMatcher) Matches(uri string, md metadata.MD) bool

Matches returns true if the request metadata is matched to the rule.

type Rule

type Rule struct {
	// Name is an optional name of the rule.
	Name string

	// Match defines the request matcher.
	// Any request that matches the matcher will be handled by the rule.
	Match RequestMatcher

	// Mock defines the details of how the handler should reply to the downstream.
	Mock *Mock

	// Forward specifies the upstream to forward the request.
	Forward *Forward
}

Rule is a routing rule for the Service.

func (*Rule) String

func (r *Rule) String() string

String returns the name of the rule.

type Service

type Service struct {
	Providers []Provider
	// contains filtered or unexported fields
}

Service provides routing rules for the Service.

func (*Service) MatchMetadata

func (s *Service) MatchMetadata(uri string, md metadata.MD) Matches

MatchMetadata matches the given gRPC request to an upstream connection.

func (*Service) Run

func (s *Service) Run(ctx context.Context) (err error)

Run starts a blocking loop that updates the routing rules on the signals, received from providers.

func (*Service) Upstreams added in v0.3.0

func (s *Service) Upstreams() []Upstream

Upstreams returns the list of upstream connections.

type State added in v0.3.0

type State struct {
	// Name is the name of the provider.
	Name string

	// Rules contains the routing rules.
	Rules []*Rule

	// Upstreams contains the upstreams.
	Upstreams []Upstream
}

State contains the state of the provider.

type Upstream added in v0.3.0

type Upstream interface {
	Name() string
	Reflection() bool

	Target() string
	Close() error
	grpc.ClientConnInterface
}

Upstream specifies a gRPC client connection.

Directories

Path Synopsis
Package fileprovider provides a file-based discovery provider.
Package fileprovider provides a file-based discovery provider.

Jump to

Keyboard shortcuts

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