baseserver

package
v0.0.0-...-f33e45f Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FAILURE_CODE   = -10
	ENV_CH_NUM_CPU = "CH_NUM_CPU"
)
View Source
const (
	MS_LOG_PREFIX = "baseserver.metaserver "
)

Variables

View Source
var BaseServerConfigurationDefaults = BaseServerConfiguration{
	LogToStdout:             true,
	LogLevel:                "debug",
	MetricsDestination:      "syslog",
	MetaListen:              "localhost:0",
	LegacyHealthCheckListen: "",
	ShutdownSettleTime:      1 * time.Second,
	HealthCheckStartupDelay: 5 * time.Second,
	HealthCheckPeriod:       30 * time.Second,
	HealthCheckTimeout:      5 * time.Second,
	PropsRefreshPeriod:      5 * time.Minute,
	OllyDataset:             "",
	OllyWriteKey:            "",
}
View Source
var ENV_BLACKLIST = []string{
	"connection_string",
	"secret",
	"password",
	"token",
	"credential",
	"pg_connection",
	"pg_write_connection",
	"mailer",
	"alert_connection",
}

All lowercase here please

Functions

func GetGlobalFeatureService

func GetGlobalFeatureService() features.FeatureService

GetGlobalFeatureService looks up the feature service on globalBaseServer. If it doesn't exist (i.e. during tests), that's ok, give us an empty one.

func GetGlobalPropertyService

func GetGlobalPropertyService() properties.PropertyService

GetGlobalPropertyService looks up the property service on globalBaseServer. If it doesn't exist (i.e. during tests), that's ok, give us an empty one.

func InitGlobalBaseServerTestingOnly

func InitGlobalBaseServerTestingOnly(propertyMap map[string]string, defaultPropertyBacking properties.PropertyBacking)

InitGlobalBaseServerTestingOnly is for tests to create a BaseServer and play with its PropertyService and FeatureService.

func ResetGlobalBaseServerTestingOnly

func ResetGlobalBaseServerTestingOnly()

ResetGlobalBaseServerTestingOnly should be defered after a call to InitGlobalBaseServerTestingOnly.

Types

type BaseServer

type BaseServer struct {
	*BaseServerConfiguration

	Logger *logger.Logger
	// contains filtered or unexported fields
}

func Boilerplate

func Boilerplate(serviceName string, versionInfo version.VersionInfo, defaultPropertyBacking properties.PropertyBacking) *BaseServer

Perform baseserver initialization steps -- hopefully 9 out of 10 services can just call this and Run()

func BoilerplateWithPrefix

func BoilerplateWithPrefix(serviceName string, versionInfo version.VersionInfo, metricsPrefix string, defaultPropertyBacking properties.PropertyBacking) *BaseServer

For when you need to set metrics prefix.

func GetGlobalBaseServer

func GetGlobalBaseServer() *BaseServer

func NewBaseServer

func NewBaseServer(serviceName string, version version.VersionInfo, metricsPrefix string, defaultPropertyBacking properties.PropertyBacking) *BaseServer

func (*BaseServer) Fail

func (bs *BaseServer) Fail(msg string)

func (*BaseServer) FinishLogger

func (bs *BaseServer) FinishLogger()

func (*BaseServer) FinishOlly

func (bs *BaseServer) FinishOlly()

func (*BaseServer) GetFeatureService

func (bs *BaseServer) GetFeatureService() features.FeatureService

func (*BaseServer) GetHealthCheckHandler

func (bs *BaseServer) GetHealthCheckHandler() func(w http.ResponseWriter, r *http.Request)

func (*BaseServer) GetPropertyService

func (bs *BaseServer) GetPropertyService() properties.PropertyService

func (*BaseServer) Init

func (bs *BaseServer) Init()

Perform some early initialization steps -- things it makes sense to do before callers start building/initializing anything from the actual service. Most things should probably be started from Run(). Called by Boilerplate().

func (*BaseServer) InitLogger

func (bs *BaseServer) InitLogger(stdout bool, loglevel string)

Initialize logging.

func (*BaseServer) InitMaxProcs

func (bs *BaseServer) InitMaxProcs()

Set the number of cpus this process can use.

func (*BaseServer) InitMetrics

func (bs *BaseServer) InitMetrics()

Initialize metrics.

func (*BaseServer) InitOlly

func (bs *BaseServer) InitOlly()

Initialize olly observability.

func (*BaseServer) OllyBuilder

func (bs *BaseServer) OllyBuilder() *olly.Builder

func (*BaseServer) ParseFlags

func (bs *BaseServer) ParseFlags()

Parse standard golang command line flags (both those defined by the service and baseserver). Exits if the resulting configuration is broken or eg. if -v is specified

func (*BaseServer) Run

func (bs *BaseServer) Run(service Service)

Finish initializing and run until signaled otherwise. Spawns sub routines.

func (*BaseServer) Shutdown

func (bs *BaseServer) Shutdown(reason string)

func (*BaseServer) WaitUntilReady

func (bs *BaseServer) WaitUntilReady(timeout time.Duration)

type BaseServerConfiguration

type BaseServerConfiguration struct {
	// base service properties
	ServiceName string
	VersionInfo version.VersionInfo

	// operational
	ShutdownSettleTime time.Duration

	// logging
	LogToStdout bool
	LogLevel    string
	LogPrefix   string

	// metrics
	MetricsPrefix      string
	MetricsDestination string

	// olly
	OllyWriteKey string
	OllyDataset  string

	// meta server properties
	MetaListen string

	// healthchecks
	HealthCheckStartupDelay time.Duration
	HealthCheckPeriod       time.Duration
	HealthCheckTimeout      time.Duration

	// legacy healthcheck
	LegacyHealthCheckListen string

	// for tests
	SkipParseFlags bool

	// props
	PropsRefreshPeriod time.Duration

	// Skip env dump
	SkipEnvDump bool
}

type HealthCheckExecutor

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

func NewHealthCheckExecutor

func NewHealthCheckExecutor(service Service, startupDelay time.Duration, period time.Duration, timeout time.Duration) *HealthCheckExecutor

func (*HealthCheckExecutor) GetResult

func (hce *HealthCheckExecutor) GetResult() *HealthCheckResult

func (*HealthCheckExecutor) Run

func (hce *HealthCheckExecutor) Run(ctx context.Context)

type HealthCheckResult

type HealthCheckResult struct {
	Stamp   time.Time `json:"stamp"`
	Success bool      `json:"success"`
	Error   string    `json:"error"`
}

func (*HealthCheckResult) Fail

func (hcr *HealthCheckResult) Fail(message string)

Fail this healthcheck execution with the given message and panics.

func (*HealthCheckResult) FailOnError

func (hcr *HealthCheckResult) FailOnError(description string, err error)

Fail this healthcheck execution and panics if err is not nil.

func (*HealthCheckResult) FailOnSqlDbError

func (hcr *HealthCheckResult) FailOnSqlDbError(ctx context.Context, description string, db *sql.DB)

Fail this healthcheck execution and panics if the given sql.DB is dead

type MetaServer

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

func NewMetaServer

func NewMetaServer(listen string, serviceName string, version version.VersionInfo, service Service, log *logger.Logger, initialLogLevel logger.Level, hce *HealthCheckExecutor) *MetaServer

func (*MetaServer) Run

func (ms *MetaServer) Run(ctx context.Context) error

type Service

type Service interface {
	// Run this service until the given context is closed, after which the service cannot be re-started. Blocks.
	Run(ctx context.Context) error

	GetStatus() []byte                                             // for legacy healthcheck
	RunHealthCheck(ctx context.Context, result *HealthCheckResult) // new style healthcheck

	Close() // deprecated; select fron ctx.Done() in Run() instead

	HttpInfo(w http.ResponseWriter, req *http.Request) // Hook to provide http info via metaserver
}

Service interface - baseserver/metaserver use these methods to interact with actual services

Jump to

Keyboard shortcuts

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