Documentation
¶
Index ¶
- type Credentials
- type HealthCheck
- type Option
- func WithCredentials(creds Credentials) Option
- func WithHealthCheck(hc HealthCheck) Option
- func WithHealthServices(names ...string) Option
- func WithLogger(log logger.Logger) Option
- func WithServerCodec(c encoding.CodecV2) Option
- func WithService(fn func(grpc.ServiceRegistrar)) Option
- func WithShutdownTimeout(d time.Duration) Option
- func WithStreamInterceptor(in ...grpc.StreamServerInterceptor) Option
- func WithUnaryInterceptor(in ...grpc.UnaryServerInterceptor) Option
- func WithUnknownServiceHandler(h grpc.StreamHandler) Option
- type Reporter
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials interface {
ServerOption() (grpc.ServerOption, error)
Encrypted() bool
}
Credentials produces the grpc.ServerOption used to configure transport security for inbound connections and reports whether that transport is encrypted.
type HealthCheck ¶
type HealthCheck interface {
Interval() time.Duration
Status(context.Context) grpc_health_v1.HealthCheckResponse_ServingStatus
}
HealthCheck reports the server's serving status on a fixed cadence. Interval controls how often Status is invoked to refresh the status exposed via the gRPC health service.
func HealthCheckFunc ¶
func HealthCheckFunc( d time.Duration, fn func(context.Context) grpc_health_v1.HealthCheckResponse_ServingStatus, ) HealthCheck
HealthCheckFunc adapts a function into a HealthCheck that polls at the given interval.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a Server at construction time.
func WithCredentials ¶
func WithCredentials(creds Credentials) Option
WithCredentials sets the transport credentials used for inbound connections.
func WithHealthCheck ¶
func WithHealthCheck(hc HealthCheck) Option
WithHealthCheck sets the HealthCheck used to drive the gRPC health service's serving status.
func WithHealthServices ¶ added in v0.5.0
WithHealthServices names the services the health service answers for, by proto full name. Each gets an entry reporting the same status as the unnamed one. Names accumulate across calls.
func WithLogger ¶
WithLogger sets the logger used by the server.
func WithServerCodec ¶
WithServerCodec forces the codec used for all messages on this server. A pass-through codec paired with WithUnknownServiceHandler enables transparent proxying while locally registered services keep working via codec delegation.
func WithService ¶
func WithService(fn func(grpc.ServiceRegistrar)) Option
WithService registers gRPC services on the server. The callback receives the underlying server as a grpc.ServiceRegistrar, so callers register via the generated pb.RegisterXxxServer(reg, impl) functions.
func WithShutdownTimeout ¶ added in v0.5.0
WithShutdownTimeout bounds how long Server.Stop waits for in-flight calls before dropping them. It defaults to five seconds and is clamped to a 50ms floor. Stop also honours its Context, so the effective budget is whichever expires first; a Context already cancelled forces immediately.
func WithStreamInterceptor ¶
func WithStreamInterceptor(in ...grpc.StreamServerInterceptor) Option
WithStreamInterceptor appends stream server interceptors. They are chained in the order supplied across all calls and run before the handler.
func WithUnaryInterceptor ¶
func WithUnaryInterceptor(in ...grpc.UnaryServerInterceptor) Option
WithUnaryInterceptor appends unary server interceptors. They are chained in the order supplied across all calls and run before the handler.
func WithUnknownServiceHandler ¶
func WithUnknownServiceHandler(h grpc.StreamHandler) Option
WithUnknownServiceHandler installs a catch-all handler invoked for any method that is not a locally registered service. Used to transparently forward unmatched requests.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter records server-layer telemetry to Prometheus: per-RPC latency and completed-request counts by gRPC status code, both labeled by method. The method label set is not known at startup, so handles are resolved per call via WithLabelValues rather than pre-resolved. A Reporter is safe for concurrent use.
Cardinality assumption: method comes from the request line, and the proxy serves every request through a catch-all handler, so any distinct method string a client sends becomes a new series. This is bounded only for trusted callers (real Temporal SDK clients use a fixed method set); a client sending arbitrary method paths can grow the series set without bound. The proxy therefore assumes trusted callers and must not be exposed directly to untrusted clients without first bounding this label. namespace is never a label for the same reason.
func NewReporter ¶
NewReporter builds the Prometheus-backed Reporter. f must already be scoped to the "server" subsystem by the caller.
func (*Reporter) Observe ¶
Observe records one completed RPC: its duration on the method histogram and a count on the (method, code) counter.
func (*Reporter) StreamInterceptor ¶
func (r *Reporter) StreamInterceptor() grpc.StreamServerInterceptor
StreamInterceptor returns a stream server interceptor that times the handler and records the RPC's duration and final gRPC status code. It covers all forwarded traffic, which grpc-go serves through the unknown-service handler as streams. The local health service's unary Check is not metered, since unary calls do not pass through a stream interceptor; its streaming Watch, if a client uses it, would be metered under its own method name.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a gRPC server with a built-in health service and a configurable periodic health check.
func New ¶
New constructs a Server. When no options are supplied, it uses insecure credentials, a default health check that always reports SERVING, a CLI logger, and a five second drain budget.
func (*Server) Start ¶
Start serves on lis and blocks until the server stops. It also kicks off the periodic health check, which runs until ctx is cancelled or Server.Stop is called.
func (*Server) Stop ¶
Stop shuts the server down, halting the health check loop and draining in-flight RPCs. The drain is bounded by whichever expires first: the WithShutdownTimeout budget or ctx. Past that, remaining calls are dropped. A forced shutdown is still a shutdown, so it is reported through a warning rather than an error; the only errors here would be a caller's to handle, and there are none.