grpc

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

+kubebuilder:validation:Optional

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientModule

func ClientModule() fx.Option

ClientModule is an fx module that provides annotated grpc ClientConnectionBuilder.

func GMuxServerModule

func GMuxServerModule() fx.Option

GMuxServerModule is an fx module that provides annotated gRPC Server using gmux provided listener and registers its metrics with the prometheus registry.

func RegisterGRPCServerMetrics

func RegisterGRPCServerMetrics(metrics *grpc_prometheus.ServerMetrics, pr *prometheus.Registry) error

RegisterGRPCServerMetrics registers a collection of metrics provided by grpc_prometheus.ServerMetrics with a prometheus registry.

func RegisterInfoService

func RegisterInfoService(in RegisterInfoServiceIn)

RegisterInfoService registers the InfoService implementation with the provided grpc server.

func ServerModule

func ServerModule() fx.Option

ServerModule is an fx module that provides annotated gRPC Server using the default listener and registers its metrics with the prometheus registry.

Types

type BackoffConfig

type BackoffConfig struct {
	// Base Delay
	BaseDelay config.Duration `json:"base_delay" validate:"gte=0" default:"1s"`
	// Max Delay
	MaxDelay config.Duration `json:"max_delay" validate:"gte=0" default:"120s"`
	// Backoff multiplier
	Multiplier float64 `json:"multiplier" validate:"gte=0" default:"1.6"`
	// Jitter
	Jitter float64 `json:"jitter" validate:"gte=0" default:"0.2"`
}

BackoffConfig holds configuration for gRPC client backoff. swagger:model +kubebuilder:object:generate=true

func (*BackoffConfig) DeepCopy

func (in *BackoffConfig) DeepCopy() *BackoffConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackoffConfig.

func (*BackoffConfig) DeepCopyInto

func (in *BackoffConfig) DeepCopyInto(out *BackoffConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ClientConnectionBuilder

type ClientConnectionBuilder interface {
	AddOptions(opts ...grpc.DialOption) ClientConnectionBuilder
	Build() ClientConnectionWrapper
}

ClientConnectionBuilder is a convenience builder to gather []grpc.DialOption.

type ClientConnectionWrapper

type ClientConnectionWrapper interface {
	// Context can be nil
	Dial(ctx context.Context, target string, extraOptions ...grpc.DialOption) (*grpc.ClientConn, error)
}

ClientConnectionWrapper is a convenience wrapper to support predefined dial Options provided by ClientConnectionBuilder.

type ClientConstructor

type ClientConstructor struct {
	Name          string
	ConfigKey     string
	DefaultConfig GRPCClientConfig
}

ClientConstructor holds fields to create an annotated instance of ClientConnectionBuilder.

func (ClientConstructor) Annotate

func (c ClientConstructor) Annotate() fx.Option

Annotate creates an annotated instance of gRPC ClientConnectionBuilder.

type GRPCClientConfig

type GRPCClientConfig struct {
	// Minimum connection timeout
	MinConnectionTimeout config.Duration `json:"min_connection_timeout" validate:"gte=0" default:"20s"`
	// Client TLS configuration
	ClientTLSConfig tlsconfig.ClientTLSConfig `json:"tls"`
	// Backoff configuration
	Backoff BackoffConfig `json:"backoff"`
	// Disable ClientTLS
	Insecure bool `json:"insecure" default:"false"`
	// Use HTTP CONNECT Proxy
	UseProxy bool `json:"use_proxy" default:"false"`
}

GRPCClientConfig holds configuration for gRPC Client. swagger:model +kubebuilder:object:generate=true

func (*GRPCClientConfig) DeepCopy

func (in *GRPCClientConfig) DeepCopy() *GRPCClientConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GRPCClientConfig.

func (*GRPCClientConfig) DeepCopyInto

func (in *GRPCClientConfig) DeepCopyInto(out *GRPCClientConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type GRPCServerConfig

type GRPCServerConfig struct {
	// Connection timeout
	ConnectionTimeout config.Duration `json:"connection_timeout" validate:"gte=0s" default:"120s"`
	// Buckets specification in latency histogram
	LatencyBucketsMS []float64 `json:"latency_buckets_ms" validate:"gte=0" default:"[10.0,25.0,100.0,250.0,1000.0]"`
	// Enable Reflection
	EnableReflection bool `json:"enable_reflection" default:"false"`
}

GRPCServerConfig holds configuration for gRPC Server. swagger:model +kubebuilder:object:generate=true

func (*GRPCServerConfig) DeepCopy

func (in *GRPCServerConfig) DeepCopy() *GRPCServerConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GRPCServerConfig.

func (*GRPCServerConfig) DeepCopyInto

func (in *GRPCServerConfig) DeepCopyInto(out *GRPCServerConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type InfoService

type InfoService struct {
	infov1.UnimplementedInfoServiceServer
}

InfoService is the implementation of the infov1.InfoServiceServer interface.

func (*InfoService) Host

func (vh *InfoService) Host(ctx context.Context, req *emptypb.Empty) (*infov1.HostInfo, error)

Host returns the hostname of the service.

func (*InfoService) Process

func (vh *InfoService) Process(ctx context.Context, req *emptypb.Empty) (*infov1.ProcessInfo, error)

Process returns the process info of the service.

func (*InfoService) Version

func (vh *InfoService) Version(ctx context.Context, req *emptypb.Empty) (*infov1.VersionInfo, error)

Version returns the version of the service.

type LogEvent

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

LogEvent wraps *zerolog.Event, so that sending an event also returns an grpc error

LogEvent also forwards _some_ builder-functions (like Str()) to the underlying zerolog.Event. This is just a sugar, as you can always use WithEvent on the whole chain.

func Bug

func Bug() LogEvent

Bug is equivalent to WithLogEvent(log.Bug()).Code(codes.Internal)

Example: return nil, grpc.Bug().Msg("impossible happened").

func BugWithLogger

func BugWithLogger(lg *log.Logger) LogEvent

BugWithLogger is equivalent to WithLogEvent(logger.Bug()).Code(codes.Internal).

func LoggedError

func LoggedError(e *zerolog.Event) LogEvent

LoggedError wraps zerolog.Event so that sending an event will also return a grpc error.

GRPC error code should be provided using Code(), otherwise, the error will use codes.Unknown.

Example:

return nil, grpc.LoggedError(log.Autosample().Warn()).
    Code(codes.InvalidArgument).
    Msg("missing frobnicator")

func (LogEvent) Bool

func (e LogEvent) Bool(key string, b bool) LogEvent

Bool adds the field key with val as a bool to the *Event context.

func (LogEvent) Code

func (e LogEvent) Code(code codes.Code) LogEvent

Code sets the gRPC code to be used in error returned via Msg() or Send()

Additionally, it adds the code field to the event.

func (LogEvent) Err

func (e LogEvent) Err(err error) LogEvent

Err adds the field "error" with serialized err to the *Event context. If err is nil, no field is added.

To customize the key name, change zerolog.ErrorFieldName.

If Stack() has been called before and zerolog.ErrorStackMarshaler is defined, the err is passed to ErrorStackMarshaler and the result is appended to the zerolog.ErrorStackFieldName.

func (LogEvent) Float32

func (e LogEvent) Float32(key string, f float32) LogEvent

Float32 adds the field key with f as a float32 to the *Event context.

func (LogEvent) Float64

func (e LogEvent) Float64(key string, f float64) LogEvent

Float64 adds the field key with f as a float64 to the *Event context.

func (LogEvent) Int

func (e LogEvent) Int(key string, i int) LogEvent

Int adds the field key with i as a int to the *Event context.

func (LogEvent) Interface

func (e LogEvent) Interface(key string, i interface{}) LogEvent

Interface adds the field key with i marshaled using reflection.

func (LogEvent) Msg

func (e LogEvent) Msg(msg string) error

Msg sends the *Event with msg added as the message field if not empty.

Msg returns grpc error using given msg as message and code previously set with Code

NOTICE: once this method is called, the LogEvent should be disposed. Calling Msg twice can have unexpected result.

func (LogEvent) Send

func (e LogEvent) Send() error

Send is equivalent to calling Msg("").

func (LogEvent) Str

func (e LogEvent) Str(key, val string) LogEvent

Str adds the field key with val as a string to the *Event context.

func (LogEvent) Stringer

func (e LogEvent) Stringer(key string, val fmt.Stringer) LogEvent

Stringer adds the field key with val.String() (or null if val is nil) to the *Event context.

type RegisterInfoServiceIn added in v2.16.0

type RegisterInfoServiceIn struct {
	fx.In
	Server *grpc.Server `name:"default"`
}

RegisterInfoServiceIn bundles and annotates parameters.

type ServerConstructor

type ServerConstructor struct {
	// Name of grpc server instance -- empty for main server
	Name string
	// Name of listener instance
	ListenerName string
	// Viper config key/server name
	ConfigKey string
	// Additional server Options
	ServerOptions []grpc.ServerOption
	// UnaryServerInterceptors add after all built-in unary interceptors
	UnaryServerInterceptors []grpc.UnaryServerInterceptor
	// StreamServerInterceptors add after all built-in stream interceptors
	StreamServerInterceptors []grpc.StreamServerInterceptor
	// Default Server Config
	DefaultConfig GRPCServerConfig
}

ServerConstructor holds fields to create an annotated gRPC Server.

func (ServerConstructor) Annotate

func (constructor ServerConstructor) Annotate() fx.Option

Annotate creates an annotated instance of gRPC Server.

Jump to

Keyboard shortcuts

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