Documentation ¶
Index ¶
- Constants
- Variables
- func GetGlobalFeatureService() features.FeatureService
- func GetGlobalPropertyService() properties.PropertyService
- func InitGlobalBaseServerTestingOnly(propertyMap map[string]string, ...)
- func ResetGlobalBaseServerTestingOnly()
- type BaseServer
- func Boilerplate(serviceName string, versionInfo version.VersionInfo, ...) *BaseServer
- func BoilerplateWithPrefix(serviceName string, versionInfo version.VersionInfo, metricsPrefix string, ...) *BaseServer
- func GetGlobalBaseServer() *BaseServer
- func NewBaseServer(serviceName string, version version.VersionInfo, metricsPrefix string, ...) *BaseServer
- func (bs *BaseServer) Fail(msg string)
- func (bs *BaseServer) FinishLogger()
- func (bs *BaseServer) FinishOlly()
- func (bs *BaseServer) GetFeatureService() features.FeatureService
- func (bs *BaseServer) GetHealthCheckHandler() func(w http.ResponseWriter, r *http.Request)
- func (bs *BaseServer) GetPropertyService() properties.PropertyService
- func (bs *BaseServer) Init(mextra interface{})
- func (bs *BaseServer) InitLogger(stdout bool, loglevel string)
- func (bs *BaseServer) InitMaxProcs()
- func (bs *BaseServer) InitMetrics(extra interface{})
- func (bs *BaseServer) InitOlly()
- func (bs *BaseServer) OllyBuilder() *olly.Builder
- func (bs *BaseServer) Run(service Service)
- func (bs *BaseServer) SetLogTee(logChan chan string)
- func (bs *BaseServer) Shutdown(reason string)
- func (bs *BaseServer) WaitUntilReady(timeout time.Duration)
- type BaseServerConfiguration
- type HealthCheckExecutor
- type HealthCheckResult
- type MetaServer
- type Service
Constants ¶
const ( FAILURE_CODE = -10 ENV_CH_NUM_CPU = "CH_NUM_CPU" )
const (
MS_LOG_PREFIX = "baseserver.metaserver "
)
Variables ¶
var BaseServerConfigurationDefaults = BaseServerConfiguration{ LogToStdout: true, LogLevel: "info", MetricsDestination: "none", MetaListen: "", ShutdownSettleTime: 1 * time.Second, HealthCheckStartupDelay: 5 * time.Second, HealthCheckPeriod: 30 * time.Second, HealthCheckTimeout: 5 * time.Second, PropsRefreshPeriod: 5 * time.Minute, OllyDataset: "", OllyWriteKey: "", }
var ENV_BLACKLIST = []string{
"connection_string",
"secret",
"password",
"token",
"credential",
"pg_connection",
"pg_write_connection",
"mailer",
"alert_connection",
"new_relic_api_key",
}
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, mextra interface{}, cfg *ktranslate.ServerConfig) *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, mextra interface{}, cfg *ktranslate.ServerConfig) *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, cfg *ktranslate.ServerConfig) *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(mextra interface{})
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(extra interface{})
Initialize metrics.
func (*BaseServer) OllyBuilder ¶
func (bs *BaseServer) OllyBuilder() *olly.Builder
func (*BaseServer) Run ¶
func (bs *BaseServer) Run(service Service)
Finish initializing and run until signaled otherwise. Spawns sub routines.
func (*BaseServer) SetLogTee ¶
func (bs *BaseServer) SetLogTee(logChan chan string)
Tell base logger to also log messages along this tee
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 // props PropsRefreshPeriod time.Duration // Skip env dump SkipEnvDump bool }
type HealthCheckExecutor ¶
type HealthCheckExecutor struct {
// contains filtered or unexported fields
}
func NewHealthCheckExecutor ¶
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 ¶
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
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 HttpInfo(w http.ResponseWriter, req *http.Request) // Hook to provide http info via metaserver // These are needed in case we are running under windows. Init(svc.Environment) error Start() error Stop() error }
Service interface - baseserver/metaserver use these methods to interact with actual services