Documentation
¶
Index ¶
- Constants
- Variables
- func AddError(ctx Context, err error)
- func AddLatencyLog(ctx Context, stats *ServiceStats, key string)
- func ClearErrors(ctx Context)
- func DeepEquals(a, b interface{}) bool
- func End(ctx Context, attrs map[string]string, err error)
- func ExtractAppId(tenant string, allowPartner bool) string
- func ExtractPartnerId(tenant string, allowPartner bool, defaultPartner string) string
- func GetCustomProperties(ctx Context) map[string]interface{}
- func GetErrors(ctx Context) []error
- func GetHttpClient(ctx Context) *http.Client
- func GetResponse(ctx Context, errTmpl map[string]interface{}) []byte
- func GetTenantId(ctx Context) string
- func HitEndpoint(ctx Context, url string, payload string, verb string, ...) (string, int, error)
- func InitGctx(logLevel string)
- func InitHttpTransport(ctx Context)
- func InitHttpTransportWithDial(ctx Context, dial func(network, addr string) (net.Conn, error))
- func NewUUID() (string, error)
- func Record(ctx Context, metric string, attrs map[string]string, val int)
- func RegisterObserver(ctx Context, o Observer)
- func SetDefaultRetrier(retrier Retrier)
- func ToFlatString(v interface{}) string
- func UpdateContext(ctx Context, conf *EelSettings, tenantId string, updateVal bool)
- type Context
- type DefaultContext
- func (c *DefaultContext) AddConfigValue(key interface{}, value interface{})
- func (c *DefaultContext) AddLogValue(key interface{}, value interface{})
- func (c *DefaultContext) AddValue(key interface{}, value interface{})
- func (c *DefaultContext) ConfigValue(key interface{}) interface{}
- func (c *DefaultContext) DisableLogging()
- func (c *DefaultContext) EnableLogging()
- func (c *DefaultContext) HandlePanic()
- func (c *DefaultContext) Id() string
- func (c *DefaultContext) Log() Logger
- func (c *DefaultContext) LogValue(key interface{}) interface{}
- func (c *DefaultContext) SetId(id string)
- func (c *DefaultContext) SubContext() Context
- func (c *DefaultContext) Value(key interface{}) interface{}
- func (c *DefaultContext) WrapPanicHttpHandler(fn func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
- type DefaultLogWriter
- type DefaultLogger
- func (l *DefaultLogger) Debug(args ...interface{})
- func (l *DefaultLogger) Error(args ...interface{})
- func (l *DefaultLogger) Info(args ...interface{})
- func (l *DefaultLogger) Metric(statKey interface{}, args ...interface{})
- func (l *DefaultLogger) RuntimeLogLoop(interval time.Duration, iterations int)
- func (l *DefaultLogger) Warn(args ...interface{})
- type DefaultRetrier
- type DuplicateChecker
- type EelDebugLogParams
- type EelSettings
- type EelTraceLogParams
- type LocalInMemoryDupChecker
- type Logger
- type NetworkError
- type Observer
- type ParseError
- type Retrier
- type RuntimeError
- type ServiceStats
- func (stats *ServiceStats) Add(src *ServiceStats) *ServiceStats
- func (stats *ServiceStats) Clone() *ServiceStats
- func (stats *ServiceStats) IncBytesIn(size int)
- func (stats *ServiceStats) IncBytesOut(size int)
- func (stats *ServiceStats) IncErrors()
- func (stats *ServiceStats) IncInCount()
- func (stats *ServiceStats) IncOutCount()
- func (stats *ServiceStats) IncTimeExternal(nanos int64)
- func (stats *ServiceStats) IncTimeInternal(nanos int64)
- func (stats *ServiceStats) Reset()
- func (stats *ServiceStats) StatsLoop(ctx Context, interval time.Duration, iterations int, label string, ...)
- func (stats *ServiceStats) Subtract(src *ServiceStats) *ServiceStats
- type SyntaxError
Constants ¶
const ( EelFile = "mascot/eel.txt" EelConfigFile = "config-eel/config.json" DefaultConfigFolder = "config-handlers" Eel1MinStats = "Eel.Stats.1Min" Eel5MinStats = "Eel.Stats.5Min" Eel1hrStats = "Eel.Stats.1hr" Eel24hrStats = "Eel.Stats.24hr" EelTotalStats = "Eel.TotalStats" EelPathWhiteList = "Eel.PathWhiteList" EelDispatcher = "Eel.Dispatcher" EelDuplicateChecker = "Eel.DuplicateChecker" EelStartTime = "StartTime" EelConfig = "Eel.Settings" EelHandlerFactory = "HandlerFactory" EelObserver = "Observer" EelHttpClient = "Eel.HttpClient" EelHttpTransport = "Eel.HttpTransport" EelRequestHeader = "Eel.Header" EelRequestQuery = "Eel.Query" EelNamedTransformations = "Eel.NamedTransformations" EelHandlerConfig = "Eel.HandlerConfig" EelTenantId = "Eel.TenantId" EelPartnerId = "Eel.PartnerId" EelCustomProperties = "Eel.CustomProperties" EelRetryService = "Eel.RetryService" EelErrors = "Eel.Errors" EelSyncPath = "Eel.SyncPath" EelTraceLogger = "Eel.TraceLogger" EelCache = "Eel.Cache" EelTenantIds = "Eel.TenantIds" LogTenantId = "gears.app.id" LogPartnerId = "gears.partner.id" )
const ( M_Namespace = "Namespace" M_Metric = "Metric" M_Unit = "Unit" M_Dims = "Dims" M_Val = "Val" )
const ( L_NilLevel = "nil" // log nothing, equivalent to /dev/null L_MetricLevel = "metric" L_ErrorLevel = "error" L_WarnLevel = "warn" L_InfoLevel = "info" L_DebugLevel = "debug" )
const ( // metric names HTTPRequestDuration = "http.request.duration" HTTPHandleDuration = "http.handle.duration" MessageProcessDuration = "message.process.duration" MessageResponseDuration = "message.response.duration" MessageLatency = "message.message.latency" // span names HTTPHandle = "http.handle" HTTPRequest = "http.request" MessageProcess = "message.process" // attribute keys HTTPHostKey = string(semconv.HTTPHostKey) HTTPMethodKey = string(semconv.HTTPMethodKey) HTTPRouteKey = string(semconv.HTTPRouteKey) HTTPStatusCodeKey = string(semconv.HTTPStatusCodeKey) HTTPURLKey = string(semconv.HTTPURLKey) TopicKey = "topic" HandlerKey = "handler" )
Variables ¶
var ( LogLevel = L_InfoLevel Gctx Context Mutex = &sync.RWMutex{} Once sync.Once BasePath = "" ConfigPath = "" HandlerPath = "" HandlerPaths = []string{""} InstanceName = "localhost" EnvName = "default" AppId = "eel" )
var ( StatusQueueFull = map[string]interface{}{"error": "queue full"} StatusInvalidJson = map[string]interface{}{"error": "invalid json"} StatusEmptyBody = map[string]interface{}{"error": "empty body"} StatusProcessed = map[string]interface{}{"status": "processed"} StatusProcessedDummy = map[string]interface{}{"status": "processed", "dummy": true} StatusDuplicateEliminated = map[string]interface{}{"status": "duplicate eliminated"} StatusRequestTooLarge = map[string]interface{}{"error": "request too large"} StatusHttpPostRequired = map[string]interface{}{"error": "http post required"} StatusUnknownTopic = map[string]interface{}{"error": "unknown topic"} StatusAlreadySubscribed = map[string]interface{}{"error": "already subscribed"} StatusNotEvenSubscribed = map[string]interface{}{"error": "not even subscribed"} StatusNoWorkerPool = map[string]interface{}{"error": "not worker pool"} HttpStatusTooManyRequests = 429 )
Functions ¶
func AddError ¶
AddError adds error to list of errors in current transaction in current context for lib use
func AddLatencyLog ¶
func AddLatencyLog(ctx Context, stats *ServiceStats, key string)
func ClearErrors ¶
func ClearErrors(ctx Context)
ClearErrors clears any stale errors from current transacction in case lib user recycles contexts
func DeepEquals ¶
func DeepEquals(a, b interface{}) bool
func ExtractAppId ¶ added in v1.41.0
func ExtractPartnerId ¶ added in v1.41.0
func GetCustomProperties ¶
GetTenant gets tenant id from context if one was passed in as http header.
func GetErrors ¶
GetErrors gets list of errors in current transaction from current context for lib use
func GetHttpClient ¶
func GetResponse ¶
func GetTenantId ¶
GetTenant gets tenant id from context if one was passed in as http header.
func HitEndpoint ¶
func HitEndpoint(ctx Context, url string, payload string, verb string, headers map[string]string, auth map[string]string) (string, int, error)
HitEndpoint helper method for posting payloads to endpoints. Supports other verbs, http headers and basic auth.
func InitHttpTransport ¶
func InitHttpTransport(ctx Context)
InitHttpTransport initializes http transport with some parameters from config.json.
func RegisterObserver ¶ added in v1.42.0
RegisterObserver registers an observer implementation
func SetDefaultRetrier ¶
func SetDefaultRetrier(retrier Retrier)
SetDefaultRetrier sets the default retrier to an external implementation
func ToFlatString ¶
func ToFlatString(v interface{}) string
ToFlatString helper function to convert anything to a flat string representation. Complex types are converted to json.
func UpdateContext ¶ added in v1.42.0
func UpdateContext(ctx Context, conf *EelSettings, tenantId string, updateVal bool)
Types ¶
type Context ¶
type Context interface {
SetId(id string)
Id() string
SubContext() Context
AddValue(key interface{}, value interface{})
AddLogValue(key interface{}, value interface{})
AddConfigValue(key interface{}, value interface{})
Value(key interface{}) interface{}
LogValue(key interface{}) interface{}
ConfigValue(key interface{}) interface{}
Log() Logger
DisableLogging()
EnableLogging()
HandlePanic()
WrapPanicHttpHandler(func(http.ResponseWriter, *http.Request)) http.HandlerFunc
}
Context is the interface for a request context and logging.
func NewDefaultContext ¶
NewDefaultContext creates a default context.
type DefaultContext ¶
DefaultContext simple implementation of the Context interface.
func (*DefaultContext) AddConfigValue ¶
func (c *DefaultContext) AddConfigValue(key interface{}, value interface{})
func (*DefaultContext) AddLogValue ¶
func (c *DefaultContext) AddLogValue(key interface{}, value interface{})
func (*DefaultContext) AddValue ¶
func (c *DefaultContext) AddValue(key interface{}, value interface{})
func (*DefaultContext) ConfigValue ¶
func (c *DefaultContext) ConfigValue(key interface{}) interface{}
func (*DefaultContext) DisableLogging ¶
func (c *DefaultContext) DisableLogging()
func (*DefaultContext) EnableLogging ¶
func (c *DefaultContext) EnableLogging()
func (*DefaultContext) HandlePanic ¶
func (c *DefaultContext) HandlePanic()
func (*DefaultContext) Id ¶
func (c *DefaultContext) Id() string
func (*DefaultContext) Log ¶
func (c *DefaultContext) Log() Logger
func (*DefaultContext) LogValue ¶
func (c *DefaultContext) LogValue(key interface{}) interface{}
func (*DefaultContext) SetId ¶
func (c *DefaultContext) SetId(id string)
func (*DefaultContext) SubContext ¶
func (c *DefaultContext) SubContext() Context
func (*DefaultContext) Value ¶
func (c *DefaultContext) Value(key interface{}) interface{}
func (*DefaultContext) WrapPanicHttpHandler ¶
func (c *DefaultContext) WrapPanicHttpHandler(fn func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
type DefaultLogWriter ¶
DefaultLogWriter wraps the default stdout writer as a singelton (shared by all loggers)
func NewDefaultLogWriter ¶
func NewDefaultLogWriter() *DefaultLogWriter
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger simple implementation of the Logger interface.
func NewDefaultLogger ¶
func NewDefaultLogger(ctx *DefaultContext, level string) *DefaultLogger
NewDefaultLogger creates a new default logger. There is one logger instance per context instance.
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(args ...interface{})
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(args ...interface{})
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(args ...interface{})
func (*DefaultLogger) Metric ¶
func (l *DefaultLogger) Metric(statKey interface{}, args ...interface{})
func (*DefaultLogger) RuntimeLogLoop ¶
func (l *DefaultLogger) RuntimeLogLoop(interval time.Duration, iterations int)
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(args ...interface{})
type DefaultRetrier ¶
type DefaultRetrier struct {
}
func (*DefaultRetrier) Retry ¶
func (*DefaultRetrier) Retry(ctx Context, url string, payload string, verb string, headers map[string]string, auth map[string]string, f func(ctx Context, url string, payload string, verb string, headers map[string]string, auth map[string]string) (string, int, error)) (string, int, error)
Retry implements retry logic with injected request function.
type DuplicateChecker ¶
DuplicateChecker simple interface for duplicate checker.
func NewLocalInMemoryDupChecker ¶
func NewLocalInMemoryDupChecker(ttl int, size int) DuplicateChecker
NewLocalInMemoryDupChecker creates a simple local in-memory de-duplication cache with optional ttl support.
type EelDebugLogParams ¶
type EelDebugLogParams struct {
Lock sync.RWMutex
RefreshSec int
WhiteListTable string
IdWhiteList map[string]string
IdPath string
LogParams map[string]string
}
EelDebugLogParams struct is an optional debug white list and log param config in eel settings
func GetDebugLogParams ¶
func GetDebugLogParams(ctx Context) *EelDebugLogParams
GetDebugLogParams is a helper function to obtain the global debug white list and log information.
type EelSettings ¶
type EelSettings struct {
Name string
AppName string
ElementsPublishEndpoint string
ElementsWebhookEndpoint string
ElementsAuth string
EelWebhook string
Brokers string
FunctionalMonitoringPort int
Endpoint interface{}
MaxAttempts int
InitialDelay time.Duration
InitialBackoff time.Duration
Pad time.Duration
BackoffMethod string
Organization string
EventTopics []string
ActionTopics []string
MaxMessageSize int64
HttpTransactionHeader string
HttpDebugHeader string
HttpTenantHeader string
HttpPartnerHeader string
HttpTimeout time.Duration
ResponseHeaderTimeout time.Duration
MaxIdleConnsPerHost int
CustomProperties map[string]interface{}
Misc map[string]interface{}
LogParams map[string]string
DebugLogParams *EelDebugLogParams
TraceLogParams *EelTraceLogParams
WorkerPoolSize map[string]int
MessageQueueTimeout int
MessageQueueDepth int
TopicPath string
LogStats bool
SendCloudWatchMetrics bool
DuplicateTimeout int
CloseIdleConnectionIntervalSec int
CloseIdleConnectionsStarted bool
RetryQueues []string
RetryServiceAvailable bool
UseRetryQueue bool
Version string
HandlerConfigPath string
AllowPartner bool
DefaultPartner string
}
EelSettings struct representing config.json master config file.
func GetConfig ¶
func GetConfig(ctx Context) *EelSettings
GetConfig is a helper function to obtain the global config from the context.
func GetConfigFromFile ¶
func GetConfigFromFile(ctx Context) *EelSettings
GetConfigFromFile loads config.json from disk and returns a pointer to a EelSettings struct.
type EelTraceLogParams ¶
type EelTraceLogParams struct {
Active bool
FileName string
LogIncoming bool
LogOutgoing bool
LogParams map[string]string
}
EelTraceLogParams struct is an optional trace log config in eel settings to be activated for brief periods of time to capture a full trace of incoming or outgoing events
type LocalInMemoryDupChecker ¶
type LocalInMemoryDupChecker struct {
// contains filtered or unexported fields
}
func (*LocalInMemoryDupChecker) GetTtl ¶
func (d *LocalInMemoryDupChecker) GetTtl() int
GetTtl gets ttl setting for cache.
func (*LocalInMemoryDupChecker) IsDuplicate ¶
func (d *LocalInMemoryDupChecker) IsDuplicate(ctx Context, payload []byte) bool
IsDuplicate checks if payload was seen in past ttl ms.
type Logger ¶
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Error(args ...interface{})
Warn(args ...interface{})
Metric(statKey interface{}, args ...interface{})
RuntimeLogLoop(interval time.Duration, iterations int)
}
Logger is the interface for logging.
type NetworkError ¶
func (NetworkError) Error ¶
func (e NetworkError) Error() string
type Observer ¶ added in v1.42.0
type Observer interface {
Start(ctx Context, trace string, attrs map[string]string) Context
End(ctx Context, attrs map[string]string, err error)
Record(ctx Context, metric string, attrs map[string]string, val int)
}
Observer is the common interface for metrics and tracing
type ParseError ¶
type ParseError struct {
Message string
}
func (ParseError) Error ¶
func (e ParseError) Error() string
type Retrier ¶
type Retrier interface {
RetryEndpoint(Context, string, string, string, map[string]string, map[string]string) (string, int, error)
Retry(Context, string, string, string, map[string]string, map[string]string, func(Context, string, string, string, map[string]string, map[string]string) (string, int, error)) (string, int, error)
}
Retrier is the interface for retrying failed http requests.
type RuntimeError ¶
func (RuntimeError) Error ¶
func (e RuntimeError) Error() string
type ServiceStats ¶
type ServiceStats struct {
InCount uint64
OutCount uint64
ErrorCount uint64
TotalTimeInternal uint64
TotalTimeExternal uint64
TotalBytesIn uint64
TotalBytesOut uint64
}
func (*ServiceStats) Add ¶
func (stats *ServiceStats) Add(src *ServiceStats) *ServiceStats
func (*ServiceStats) Clone ¶
func (stats *ServiceStats) Clone() *ServiceStats
func (*ServiceStats) IncBytesIn ¶
func (stats *ServiceStats) IncBytesIn(size int)
func (*ServiceStats) IncBytesOut ¶
func (stats *ServiceStats) IncBytesOut(size int)
func (*ServiceStats) IncErrors ¶
func (stats *ServiceStats) IncErrors()
func (*ServiceStats) IncInCount ¶
func (stats *ServiceStats) IncInCount()
func (*ServiceStats) IncOutCount ¶
func (stats *ServiceStats) IncOutCount()
func (*ServiceStats) IncTimeExternal ¶
func (stats *ServiceStats) IncTimeExternal(nanos int64)
func (*ServiceStats) IncTimeInternal ¶
func (stats *ServiceStats) IncTimeInternal(nanos int64)
func (*ServiceStats) Reset ¶
func (stats *ServiceStats) Reset()
func (*ServiceStats) StatsLoop ¶
func (stats *ServiceStats) StatsLoop(ctx Context, interval time.Duration, iterations int, label string, getWorkQueueFillLevel propFunc, getNumWorkersIdle propFunc, tenantId string)
StatsLoop logs some basic stats at pre-defined interval. If iterations is negative, the loop is endless. Otherwise the loop terminates after the specified number of iterations.
func (*ServiceStats) Subtract ¶
func (stats *ServiceStats) Subtract(src *ServiceStats) *ServiceStats
type SyntaxError ¶
func (SyntaxError) Error ¶
func (e SyntaxError) Error() string