daemon

package
v0.0.0-...-007c8aa Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 19 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.

View Source
const LocalTestEnvVar = "DD_LOCAL_TEST"

Variables

View Source
var ShutdownDelay = 200 * time.Millisecond

ShutdownDelay is the amount of time we wait before shutting down the HTTP server after we receive a Shutdown event. This allows time for the final log messages to arrive from the Logs API.

Functions

This section is empty.

Types

type Daemon

type Daemon struct {
	MetricAgent *metrics.ServerlessMetricAgent

	LogsAgent logsAgent.ServerlessLogsAgent

	TraceAgent trace.ServerlessTraceAgent

	ColdStartCreator *trace.ColdStartSpanCreator

	OTLPAgent *otlp.ServerlessOTLPAgent

	// Stopped represents whether the Daemon has been Stopped
	Stopped bool

	// LambdaLibraryDetected represents whether the Datadog Lambda Library was detected in the environment
	LambdaLibraryDetected bool

	// LambdaLibraryStateLock keeps track of whether the Datadog Lambda Library was detected in the environment
	LambdaLibraryStateLock sync.Mutex

	// ExecutionSpanStateLock keeps track of whether the serverless Invocation routes have been hit to complete the execution span
	ExecutionSpanStateLock sync.Mutex

	// 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

	// FlushLock is used to keep track of whether there is currently a flush in progress
	FlushLock sync.Mutex

	ExtraTags *serverlessLog.Tags

	// ExecutionContext stores the context of the current invocation
	ExecutionContext *executioncontext.ExecutionContext

	// TellDaemonRuntimeDoneOnce asserts that TellDaemonRuntimeDone will be called at most once per invocation (at the end of the function OR after a timeout).
	// We store a pointer to a sync.Once, which should be reset to a new pointer at the beginning of each invocation.
	// Note that overwriting the actual underlying sync.Once is not thread safe,
	// so we must use a pointer here to create a new sync.Once without overwriting the old one when resetting.
	TellDaemonRuntimeDoneOnce *sync.Once

	// InvocationProcessor is used to handle lifecycle events, either using the proxy or the lifecycle API
	InvocationProcessor invocationlifecycle.InvocationProcessor
	// contains filtered or unexported fields
}

Daemon is the communication server between the runtime and the serverless agent and coordinates the flushing of telemetry.

func StartDaemon

func StartDaemon(addr string) *Daemon

StartDaemon starts an HTTP server to receive messages from the runtime and coordinate the flushing of telemetry.

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 strategy

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

func (d *Daemon) IsExecutionSpanIncomplete() bool

IsExecutionSpanIncomplete checks if the Lambda execution span was finished

func (*Daemon) IsLambdaLibraryDetected

func (d *Daemon) IsLambdaLibraryDetected() bool

IsLambdaLibraryDetected returns if the Lambda Library is in use

func (*Daemon) SetColdStartSpanCreator

func (d *Daemon) SetColdStartSpanCreator(creator *trace.ColdStartSpanCreator)

func (*Daemon) SetExecutionSpanIncomplete

func (d *Daemon) SetExecutionSpanIncomplete(spanIncomplete bool)

SetExecutionSpanIncomplete keeps track of whether the Extension completed the Lambda execution span

func (*Daemon) SetFlushStrategy

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

SetFlushStrategy sets the flush strategy to use.

func (*Daemon) SetLogsAgent

func (d *Daemon) SetLogsAgent(logsAgent logsAgent.ServerlessLogsAgent)

SetLogsAgent sets the logs agent instance running when it is ready.

func (*Daemon) SetOTLPAgent

func (d *Daemon) SetOTLPAgent(otlpAgent *otlp.ServerlessOTLPAgent)

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, lambdaInitMetricChan chan<- *serverlessLog.LambdaInitMetric)

SetupLogCollectionHandler configures the log collection route handler

func (*Daemon) ShouldFlush

func (d *Daemon) ShouldFlush(moment flush.Moment) bool

ShouldFlush indicated whether or a flush is needed

func (*Daemon) StartLogCollection

func (d *Daemon) StartLogCollection()

StartLogCollection begins processing the logs we have already received from the Lambda Logs API. This should be called after an ARN and RequestId is available. Can safely be called multiple times.

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 EndInvocation

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

EndInvocation is a route that can be called at the end of an invocation to enable the invocation lifecycle feature without the use of the proxy.

func (*EndInvocation) ServeHTTP

func (e *EndInvocation) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Flush

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

Flush is a route called by the Datadog 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(_ http.ResponseWriter, _ *http.Request)

type Hello

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

Hello is a route called by the Datadog Lambda Library when it starts. It is used to detect the Datadog Lambda Library in the environment.

func (*Hello) ServeHTTP

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

type StartInvocation

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

StartInvocation is a route that can be called at the beginning of an invocation to enable the invocation lifecyle feature without the use of the proxy.

func (*StartInvocation) ServeHTTP

func (s *StartInvocation) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TraceContext

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

TraceContext is a route called by tracer so it can retrieve the tracing context

func (*TraceContext) ServeHTTP

func (tc *TraceContext) ServeHTTP(w http.ResponseWriter, _ *http.Request)

Jump to

Keyboard shortcuts

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