daemon

package
v0.0.0-...-c4caace Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const FlushTimeout time.Duration = 5 * time.Second

FlushTimeout is the amount of time to wait for a flush to complete.

Variables

This section is empty.

Functions

This section is empty.

Types

type Daemon

type Daemon struct {
	MetricAgent *metrics.ServerlessMetricAgent

	TraceAgent *trace.ServerlessTraceAgent

	// RuntimeWg is used to keep track of whether the runtime is currently handling an invocation.
	// It should be reset when we start a new invocation, as we may start a new invocation before hearing that the last one finished.
	RuntimeWg *sync.WaitGroup

	// FlushWg is used to keep track of whether there is currently a flush in progress
	FlushWg *sync.WaitGroup

	ExtraTags *serverlessLog.Tags

	ExecutionContext *serverlessLog.ExecutionContext

	// TellDaemonRuntimeDoneOnce asserts that TellDaemonRuntimeDone will be called at most once per invocation (at the end of the function OR after a timeout)
	// this should be reset before each invocation
	TellDaemonRuntimeDoneOnce sync.Once
	// contains filtered or unexported fields
}

Daemon is the communcation server for between the runtime and the serverless Agent. The name "daemon" is just in order to avoid serverless.StartServer ...

func StartDaemon

func StartDaemon(addr string) *Daemon

StartDaemon starts an HTTP server to receive messages from the runtime. The DogStatsD server is provided when ready (slightly later), to have the hello route available as soon as possible. However, the HELLO route is blocking to have a way for the runtime function to know when the Serverless Agent is ready.

func (*Daemon) AutoSelectStrategy

func (d *Daemon) AutoSelectStrategy() flush.Strategy

AutoSelectStrategy uses the invocation interval of the function to select the best flush strategy. This function doesn't mind if the flush strategy has been overridden through configuration / environment var, the caller is responsible for that.

func (*Daemon) ComputeGlobalTags

func (d *Daemon) ComputeGlobalTags(configTags []string)

ComputeGlobalTags extracts tags from the ARN, merges them with any user-defined tags and adds them to traces, logs and metrics

func (*Daemon) GetFlushStrategy

func (d *Daemon) GetFlushStrategy() string

GetFlushStrategy returns the flush stategy

func (*Daemon) HandleRuntimeDone

func (d *Daemon) HandleRuntimeDone()

HandleRuntimeDone should be called when the runtime is done handling the current invocation. It will tell the daemon that the runtime is done, and may also flush telemetry.

func (*Daemon) InvocationInterval

func (d *Daemon) InvocationInterval() time.Duration

InvocationInterval computes the invocation interval of the current function. This function returns 0 if not enough invocations were done.

func (*Daemon) RestoreCurrentStateFromFile

func (d *Daemon) RestoreCurrentStateFromFile() error

RestoreCurrentStateFromFile loads the current context from a file

func (*Daemon) SaveCurrentExecutionContext

func (d *Daemon) SaveCurrentExecutionContext() error

SaveCurrentExecutionContext stores the current context to a file

func (*Daemon) SetExecutionContext

func (d *Daemon) SetExecutionContext(arn string, requestID string)

SetExecutionContext sets the current context to the daemon

func (*Daemon) SetFlushStrategy

func (d *Daemon) SetFlushStrategy(strategy flush.Strategy)

SetFlushStrategy sets the flush strategy to use.

func (*Daemon) SetStatsdServer

func (d *Daemon) SetStatsdServer(metricAgent *metrics.ServerlessMetricAgent)

SetStatsdServer sets the DogStatsD server instance running when it is ready.

func (*Daemon) SetTraceAgent

func (d *Daemon) SetTraceAgent(traceAgent *trace.ServerlessTraceAgent)

SetTraceAgent sets the Agent instance for submitting traces

func (*Daemon) SetupLogCollectionHandler

func (d *Daemon) SetupLogCollectionHandler(route string, logsChan chan *logConfig.ChannelMessage, logsEnabled bool, enhancedMetricsEnabled bool)

SetupLogCollectionHandler configures the log collection route handler

func (*Daemon) ShouldFlush

func (d *Daemon) ShouldFlush(moment flush.Moment, t time.Time) bool

ShouldFlush indicated whether or a flush is needed

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop causes the Daemon to gracefully shut down. After a delay, the HTTP server is shut down, data is flushed a final time, and then the agents are shut down.

func (*Daemon) StoreInvocationTime

func (d *Daemon) StoreInvocationTime(t time.Time) bool

StoreInvocationTime stores the given invocation time in the list of previous invocations. It is used to compute the invocation interval of the current function. It is automatically removing entries when too much have been already stored (more than maxInvocationsStored). When trying to store a new point, if it is older than the last one stored, it is ignored. Returns if the point has been stored.

func (*Daemon) TellDaemonRuntimeDone

func (d *Daemon) TellDaemonRuntimeDone()

TellDaemonRuntimeDone tells the daemon that the runtime finished handling an invocation

func (*Daemon) TellDaemonRuntimeStarted

func (d *Daemon) TellDaemonRuntimeStarted()

TellDaemonRuntimeStarted tells the daemon that the runtime started handling an invocation

func (*Daemon) TriggerFlush

func (d *Daemon) TriggerFlush(isLastFlushBeforeShutdown bool)

TriggerFlush triggers a flush of the aggregated metrics, traces and logs. If the flush times out, the daemon will stop waiting for the flush to complete, but the flush may be continued on the next invocation. In some circumstances, it may switch to another flush strategy after the flush.

func (*Daemon) UpdateStrategy

func (d *Daemon) UpdateStrategy()

UpdateStrategy will update the current flushing strategy

func (*Daemon) UseAdaptiveFlush

func (d *Daemon) UseAdaptiveFlush(enabled bool)

UseAdaptiveFlush sets whether we use the adaptive flush or not. Set it to false when the flush strategy has been forced through configuration.

func (*Daemon) WaitForDaemon

func (d *Daemon) WaitForDaemon()

WaitForDaemon waits until the daemon has finished handling the current invocation

type Flush

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

Flush is a route called by the Lambda Library when the runtime is done handling an invocation. It is no longer used, but the route is maintained for backwards compatibility.

func (*Flush) ServeHTTP

func (f *Flush) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP - see type Flush comment.

type Hello

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

Hello is a route called by the Lambda Library when it starts. It is no longer used, but the route is maintained for backwards compatibility.

func (*Hello) ServeHTTP

func (h *Hello) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP - see type Hello comment.

Jump to

Keyboard shortcuts

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