reflection

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package reflection provides a way to receive complete service descriptions via gRPC reflection suitable for use with grpcbridge's routers. For more information regarding the gRPC reflection protocol, see the official "GRPC Server Reflection Protocol" spec.

Both v1 and v1alpha reflection versions are supported, with the resolver being able to switch between the two and remembering the previously used version. See Resolver and ResolverOpts for more details and the available features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

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

Resolver is the gRPC reflection-based description resolver, initialized using a ResolverBuilder. It polls the target for which it was created for in a separate poller goroutine which is created during initialization, and must be destroyed using Resolver.Close to avoid a goroutine leak. By default polling happens with an interval specified by ResolverOpts.PollInterval, but this can be disabled by setting ResolverOpts.PollManually to true, in which case Resolver.ResolveNow can be used to trigger new polls.

func (*Resolver) Close

func (r *Resolver) Close()

Close closes the resolver, releasing any associated resources (i.e. the poller goroutine). It waits for the poller goroutine to acknowledge the closure, to avoid potential resource leakage. Calling Close() more than once will panic.

func (*Resolver) ResolveNow

func (r *Resolver) ResolveNow()

ResolveNow triggers a new poll to be performed after the current one, if any, is finished. This method doesn't block and just writes a signal which will be handled by the poller goroutine in the background.

type ResolverBuilder

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

ResolverBuilder is a builder for [Resolver]s, present to simplify their creation by moving all the shared parameters to the builder itself.

func NewResolverBuilder

func NewResolverBuilder(pool grpcadapter.ClientPool, opts ResolverOpts) *ResolverBuilder

NewResolverBuilder initializes a new Resolver builder with the specified connection pool and options, both of which will be inherited by the resolvers later created using ResolverBuilder.Build.

func (*ResolverBuilder) Build

func (rb *ResolverBuilder) Build(target string, watcher Watcher) *Resolver

Build initializes a new Resolver for the specified target and launches its poller goroutine. The new resolver will use the pool specified in NewResolverBuilder to retrieve connections to the target.

type ResolverOpts

type ResolverOpts struct {
	// Logs are discarded by default.
	Logger bridgelog.Logger
	// 5 minutes by default, 1 second minimum.
	// A random jitter of ±10% will be added to the interval to spread out all the polling
	// requests resolvers have to do, avoiding spikes in resource usage.
	PollInterval time.Duration
	// If PollManually is true, the resolver will perform a single initial iteration,
	// after which ResolveNow has to be manually called for polling to happen.
	PollManually bool
	// 10 seconds by default, 1ms minimum.
	ReqTimeout time.Duration
	// Prefixes of service names to ignore additionally to administrative gRPC services (grpc.health, grpc.reflection, grpc.channelz, ...).
	IgnorePrefixes []string
	// Request only service names without the full method/message definitions.
	// Suitable only for use with pure-proto marshaling/unmarshaling, which retains all the unknown fields.
	// False by default.
	OnlyServices bool
	// Limit on the depth of the dependency chain of the retrieved file descriptors when working
	// with misbehaving servers such as python grpclib (see https://github.com/vmagamedov/grpclib/issues/187) which do not return the whole transitive dependency chain when asked to.
	// 100 by default, 0 minimum (only a single FileContainingSymbol request will be made and it will be expected to return the whole dependency chain).
	RecursionLimit int
}

ResolverOpts define all the optional settings which can be set for Resolver.

type Watcher

type Watcher interface {
	// UpdateDesc is called when the resolver has successfully received new descriptions.
	UpdateDesc(*bridgedesc.Target)
	// ReportError is called when the resolver encounters an error, it can be safely ignored by the watcher.
	ReportError(error)
}

Watcher defines the interface of a watcher which is notified by the resolver of updates.

Jump to

Keyboard shortcuts

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