Back to godoc.org

Package server

v0.0.15
Latest Go to latest

The latest major version is .

Published: Jul 31, 2020 | License: BSD-3-Clause | Module: go.chromium.org/goma/server

Overview

Package server provides functions for goma servers.

Index

Constants

const (
	// same as default sampler
	// https://github.com/census-instrumentation/opencensus-go/blob/master/trace/sampling.go#L21
	DefaultTraceFraction = 1e-4

	// trace API limit is 4800/minutes.
	// https://cloud.google.com/trace/docs/quotas#trace-api-limit
	// 4800/60/(total number of replicas in the project)
	DefaultTraceQPS = 0.05
)

func ClusterName

func ClusterName(ctx context.Context) string

ClusterName returns cluster name where server is running on.

func DefaultDialOption

func DefaultDialOption() []grpc.DialOption

DefaultDialOption is default dial option to record opencensus stats and traces.

func DialContext

func DialContext(ctx context.Context, addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext dials to addr with default dial options.

func Flush

func Flush()

Flush flushes opencensus data.

func GC

func GC(ctx context.Context) int64

GC runs garbage-collector and reports latest measured resident memory size in bytes.

func HostName

func HostName(ctx context.Context) string

HostName returns hostname. in k8s, it is podname.

func Init

func Init(ctx context.Context, projectID, name string) error

Init initializes opencensus instrumentations, and error reporter. If projectID is not empty, it registers stackdriver exporter for the project. It also calls SetupHTTPClient.

func MemoryLimit

func MemoryLimit() (int64, error)

MemoryLimit returns server memory limit, set by cgroup.

func NewHTTP

func NewHTTP(port int, handler http.Handler) *http.Server

NewHTTP creates http server.

func NewLimitedSampler

func NewLimitedSampler(fraction, qps float64) trace.Sampler

NewLimitedSampler returns trace sampler limited by fraction and qps.

func ProjectID

func ProjectID(ctx context.Context) string

ProjectID returns current project id.

func ResidentMemorySize

func ResidentMemorySize() int64

ResidentMemorySize reports latest measured resident memory size in bytes.

func Run

func Run(ctx context.Context, servers ...Server)

Run runs servers. This is typically invoked as the last statement in the server's main function.

func SetupHTTPClient

func SetupHTTPClient()

SetupHTTPClient sets up http default client to monitor by opencensus.

type GRPC

type GRPC struct {
	*grpc.Server
	net.Listener
}

GRPC represents grpc server.

func NewGRPC

func NewGRPC(port int, opts ...grpc.ServerOption) (GRPC, error)

NewGRPC creates grpc server listening on port.

func (GRPC) ListenAndServe

func (g GRPC) ListenAndServe() error

ListenAndServe listens on Listener and handles requests with Server.

func (GRPC) Shutdown

func (g GRPC) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

type Server

type Server interface {
	// ListenAndServe listens and then serve to handle requests on incoming
	// connections.
	ListenAndServe() error

	// Shutdown gracefully shuts down the server.
	Shutdown(context.Context) error
}

Server is interface to control server.

func NewHTTPS

func NewHTTPS(hs *http.Server, certFile, keyFile string) Server

NewHTTPS creates https server.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier