go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/servenv Index | Files

package servenv

import "gopkg.in/src-d/go-vitess.v1/vt/servenv"

Package servenv contains functionality that is common for all Vitess server programs. It defines and initializes command line flags that control the runtime environment.

After a server program has called flag.Parse, it needs to call env.Init to make env use the command line variables to initialize the environment. It also needs to call env.Close before exiting.

Note: If you need to plug in any custom initialization/cleanup for a vitess distribution, register them using OnInit and onClose. A clean way of achieving that is adding to this package a file with an init() function that registers the hooks.

Index

Package Files

buildinfo.go flush_logutil.go flushlogs.go grpc_auth.go grpc_server.go grpc_server_auth_static.go jquery.go pid_file.go pprof.go purgelogs.go rpc_utils.go run.go servenv.go service_map.go status.go unix_socket.go

Constants

const JQueryIncludes = "" /* 289 byte string literal not displayed */

JQueryIncludes is the include to use to be able to use jquery and jquery-ui

Variables

var (
    // GRPCPort is the port to listen on for gRPC. If not set or zero, don't listen.
    GRPCPort = flag.Int("grpc_port", 0, "Port to listen on for gRPC calls")

    // GRPCCert is the cert to use if TLS is enabled
    GRPCCert = flag.String("grpc_cert", "", "certificate to use, requires grpc_key, enables TLS")

    // GRPCKey is the key to use if TLS is enabled
    GRPCKey = flag.String("grpc_key", "", "key to use, requires grpc_cert, enables TLS")

    // GRPCCA is the CA to use if TLS is enabled
    GRPCCA = flag.String("grpc_ca", "", "ca to use, requires TLS, and enforces client cert check")

    // GRPCAuth which auth plugin to use (at the moment now only static is supported)
    GRPCAuth = flag.String("grpc_auth_mode", "", "Which auth plugin implementation to use (eg: static)")

    // GRPCServer is the global server to serve gRPC.
    GRPCServer *grpc.Server

    // GRPCMaxConnectionAge is the maximum age of a client connection, before GoAway is sent.
    // This is useful for L4 loadbalancing to ensure rebalancing after scaling.
    GRPCMaxConnectionAge = flag.Duration("grpc_max_connection_age", time.Duration(math.MaxInt64), "Maximum age of a client connection before GoAway is sent.")

    // GRPCMaxConnectionAgeGrace is an additional grace period after GRPCMaxConnectionAge, after which
    // connections are forcibly closed.
    GRPCMaxConnectionAgeGrace = flag.Duration("grpc_max_connection_age_grace", time.Duration(math.MaxInt64), "Additional grace period after grpc_max_connection_age, after which connections are forcibly closed.")

    // GRPCInitialConnWindowSize ServerOption that sets window size for a connection.
    // The lower bound for window size is 64K and any value smaller than that will be ignored.
    GRPCInitialConnWindowSize = flag.Int("grpc_server_initial_conn_window_size", 0, "grpc server initial connection window size")

    // GRPCInitialWindowSize ServerOption that sets window size for stream.
    // The lower bound for window size is 64K and any value smaller than that will be ignored.
    GRPCInitialWindowSize = flag.Int("grpc_server_initial_window_size", 0, "grpc server initial window size")

    // EnforcementPolicy MinTime that sets the keepalive enforcement policy on the server.
    // This is the minimum amount of time a client should wait before sending a keepalive ping.
    GRPCKeepAliveEnforcementPolicyMinTime = flag.Duration("grpc_server_keepalive_enforcement_policy_min_time", 5*time.Minute, "grpc server minimum keepalive time")

    // EnforcementPolicy PermitWithoutStream - If true, server allows keepalive pings
    // even when there are no active streams (RPCs). If false, and client sends ping when
    // there are no active streams, server will send GOAWAY and close the connection.
    GRPCKeepAliveEnforcementPolicyPermitWithoutStream = flag.Bool("grpc_server_keepalive_enforcement_policy_permit_without_stream", false, "grpc server permit client keepalive pings even when there are no active streams (RPCs)")
)

This file handles gRPC server, on its own port. Clients register servers, based on service map:

servenv.RegisterGRPCFlags() servenv.OnRun(func() {

if servenv.GRPCCheckServiceMap("XXX") {
  pb.RegisterXXX(servenv.GRPCServer, XXX)
}

}

Note servenv.GRPCServer can only be used in servenv.OnRun, and not before, as it is initialized right before calling OnRun.

var (
    // Port is part of the flags used when calling RegisterDefaultFlags.
    Port *int

    // ListeningURL is filled in when calling Run, contains the server URL.
    ListeningURL url.URL
)
var AppVersion versionInfo

AppVersion is the struct to store build info.

var (
    // SocketFile has the flag used when calling
    // RegisterDefaultSocketFileFlags.
    SocketFile *string
)
var (

    // Version registers the command line flag to expose build info.
    Version = flag.Bool("version", false, "print binary version")
)

func AddStatusFuncs Uses

func AddStatusFuncs(fmap template.FuncMap)

AddStatusFuncs merges the provided functions into the set of functions used to render /debug/status. Call this before AddStatusPart if your template requires custom functions.

func AddStatusPart Uses

func AddStatusPart(banner, frag string, f func() interface{})

AddStatusPart adds a new section to status. frag is used as a subtemplate of the template used to render /debug/status, and will be executed using the value of invoking f at the time of the /debug/status request. frag is parsed and executed with the html/template package. Functions registered with AddStatusFuncs may be used in the template.

func AddStatusSection Uses

func AddStatusSection(banner string, f func() string)

AddStatusSection registers a function that generates extra information for /debug/status. If banner is not empty, it will be used as a header before the information. If more complex output than a simple string is required use AddStatusPart instead.

func CheckServiceMap Uses

func CheckServiceMap(protocol, name string) bool

CheckServiceMap returns if we should register a RPC service (and also logs how to enable / disable it)

func Close Uses

func Close()

Close runs any registered exit hooks in parallel.

func FakeAuthStreamInterceptor Uses

func FakeAuthStreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

FakeAuthStreamInterceptor fake interceptor to test plugin

func FakeAuthUnaryInterceptor Uses

func FakeAuthUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

FakeAuthUnaryInterceptor fake interceptor to test plugin

func FireRunHooks Uses

func FireRunHooks()

FireRunHooks fires the hooks registered by OnHook. Use this in a non-server to run the hooks registered by servenv.OnRun().

func GRPCCheckServiceMap Uses

func GRPCCheckServiceMap(name string) bool

GRPCCheckServiceMap returns if we should register a gRPC service (and also logs how to enable / disable it)

func GetAuthenticator Uses

func GetAuthenticator(name string) func() (Authenticator, error)

GetAuthenticator returns an AuthPlugin by name, or log.Fatalf.

func HandlePanic Uses

func HandlePanic(component string, err *error)

HandlePanic should be called using 'defer' in the RPC code that executes the command.

func Init Uses

func Init()

Init is the first phase of the server startup.

func InitServiceMap Uses

func InitServiceMap(protocol, name string)

InitServiceMap will set the default value for a protocol/name to be served.

func OnClose Uses

func OnClose(f func())

OnClose registers f to be run at the end of the app lifecycle. This happens after the lameduck period just before the program exits. All hooks are run in parallel.

func OnInit Uses

func OnInit(f func())

OnInit registers f to be run at the beginning of the app lifecycle. It should be called in an init() function.

func OnRun Uses

func OnRun(f func())

OnRun registers f to be run right at the beginning of Run. All hooks are run in parallel.

func OnTerm Uses

func OnTerm(f func())

OnTerm registers a function to be run when the process receives a SIGTERM. This allows the program to change its behavior during the lameduck period.

All hooks are run in parallel, and there is no guarantee that the process will wait for them to finish before dying when the lameduck period expires.

See also: OnTermSync

func OnTermSync Uses

func OnTermSync(f func())

OnTermSync registers a function to be run when the process receives SIGTERM. This allows the program to change its behavior during the lameduck period.

All hooks are run in parallel, and the process will do its best to wait (up to -onterm_timeout) for all of them to finish before dying.

See also: OnTerm

func ParseFlags Uses

func ParseFlags(cmd string)

ParseFlags initializes flags and handles the common case when no positional arguments are expected.

func ParseFlagsWithArgs Uses

func ParseFlagsWithArgs(cmd string) []string

ParseFlagsWithArgs initializes flags and returns the positional arguments

func RegisterAuthPlugin Uses

func RegisterAuthPlugin(name string, authPlugin func() (Authenticator, error))

RegisterAuthPlugin registers an implementation of AuthServer.

func RegisterDefaultFlags Uses

func RegisterDefaultFlags()

RegisterDefaultFlags registers the default flags for listening to a given port for standard connections. If calling this, then call RunDefault()

func RegisterDefaultSocketFileFlags Uses

func RegisterDefaultSocketFileFlags()

RegisterDefaultSocketFileFlags registers the default flags for listening to a socket. This needs to be called before flags are parsed.

func Run Uses

func Run(port int)

Run starts listening for RPC and HTTP requests, and blocks until it the process gets a signal.

func RunDefault Uses

func RunDefault()

RunDefault calls Run() with the parameters from the flags.

func StatusURLPath Uses

func StatusURLPath() string

StatusURLPath returns the path to the status page.

type Authenticator Uses

type Authenticator interface {
    Authenticate(ctx context.Context, fullMethod string) (context.Context, error)
}

Authenticator provides an interface to implement auth in Vitess in grpc server

type StaticAuthConfigEntry Uses

type StaticAuthConfigEntry struct {
    Username string
    Password string
}

StaticAuthConfigEntry is the container for server side credentials. Current implementation matches the the one from the client but this will change in the future as we hooked this pluging into ACL features.

type StaticAuthPlugin Uses

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

StaticAuthPlugin implements static username/password authentication for grpc. It contains an array of username/passwords that will be authorized to connect to the grpc server.

func (*StaticAuthPlugin) Authenticate Uses

func (sa *StaticAuthPlugin) Authenticate(ctx context.Context, fullMethod string) (context.Context, error)

Authenticate implements AuthPlugin interface. This method will be used inside a middleware in grpc_server to authenticate incoming requests.

type WrappedServerStream Uses

type WrappedServerStream struct {
    grpc.ServerStream
    WrappedContext context.Context
}

WrappedServerStream is based on the service stream wrapper from: https://github.com/grpc-ecosystem/go-grpc-middleware

func WrapServerStream Uses

func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*WrappedServerStream) Context Uses

func (w *WrappedServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

Package servenv imports 43 packages (graph) and is imported by 32 packages. Updated 2019-06-05. Refresh now. Tools for package owners.