daemon

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 14 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

	// InvcWg is used to keep track of whether the daemon is doing any pending work
	// before finishing an invocation
	InvcWg *sync.WaitGroup

	ExtraTags *serverlessLog.Tags

	ExecutionContext *serverlessLog.ExecutionContext
	// 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. If the Flush route is called before the statsd server has been set, a 503 is returned by the HTTP route.

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 of 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) FinishInvocation

func (d *Daemon) FinishInvocation()

FinishInvocation finishes the current invocation

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) LogFlushStategy

func (d *Daemon) LogFlushStategy() string

LogFlushStategy returns the flush stategy

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) SetClientReady

func (d *Daemon) SetClientReady(isReady bool)

SetClientReady indicates that the client library has initialised and called the /hello route on the agent

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) StartInvocation

func (d *Daemon) StartInvocation()

StartInvocation tells the daemon the invocation began

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) 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 invocation finished any pending work

func (*Daemon) WaitUntilClientReady

func (d *Daemon) WaitUntilClientReady(timeout time.Duration) bool

WaitUntilClientReady will wait until the client library has called the /hello route, or timeout

type Flush

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

Flush is the route to call to do an immediate flush on the serverless agent. Returns 503 if the DogStatsD is not ready yet, 200 otherwise.

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 implements the basic Hello route, creating a way for the Datadog Lambda Library to know that the serverless agent is running. It is blocking until the DogStatsD daemon is ready.

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