serverless

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportInitError

func ReportInitError(id ID, errorEnum ErrorEnum) error

ReportInitError reports an init error to the environment.

func SubscribeLogs

func SubscribeLogs(id ID, httpAddr string, logsType []string) error

SubscribeLogs subscribes to the logs collection on the platform. We send a request to AWS to subscribe for logs, indicating on which port we are opening an HTTP server, to receive logs from AWS. When we are receiving logs on this HTTP server, we're pushing them in a channel tailed by the Logs Agent pipeline, these logs then go through the regular Logs Agent pipeline to finally be sent on the intake when we receive a FLUSH call from the Lambda function / client. logsType contains the type of logs for which we are subscribing, possible value: platform, extension and function.

func WaitForNextInvocation

func WaitForNextInvocation(stopCh chan struct{}, daemon *Daemon, metricsChan chan []metrics.MetricSample, id ID) error

WaitForNextInvocation makes a blocking HTTP call to receive the next event from AWS. Note that for now, we only subscribe to INVOKE and SHUTDOWN events. Write into stopCh to stop the main thread of the running program.

Types

type Daemon

type Daemon struct {

	// Wait on this WaitGroup in controllers to be sure that the Daemon is ready.
	// (i.e. that the DogStatsD server is properly instantiated)
	ReadyWg *sync.WaitGroup
	// 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(stopCh chan struct{}) *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) EnableLogsCollection

func (d *Daemon) EnableLogsCollection() (string, chan aws.LogMessage, error)

EnableLogsCollection is adding the HTTP route on which the HTTP server will receive logs from AWS. Returns the HTTP URL on which AWS should send the logs.

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

func (d *Daemon) SetAggregator(aggregator *aggregator.BufferedAggregator)

SetAggregator sets the aggregator used within the DogStatsD server. Use this aggregator `GetChannels()` or `GetBufferedChannels()` to send metrics directly to the aggregator, with caution.

func (*Daemon) SetFlushStrategy

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

SetFlushStrategy sets the flush strategy to use.

func (*Daemon) SetStatsdServer

func (d *Daemon) SetStatsdServer(statsdServer *dogstatsd.Server)

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

func (*Daemon) SetTraceAgent

func (d *Daemon) SetTraceAgent(traceAgent *traceAgent.Agent)

SetTraceAgent sets the Agent instance for submitting traces

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(ctx context.Context, shutdown bool)

TriggerFlush triggers a flush of the aggregated metrics, traces and logs. They are flushed concurrently. In some circumstances, it may switch to another flush strategy after the flush. shutdown indicates whether this is the last flush before the shutdown or not.

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.

type ErrorEnum

type ErrorEnum string

ErrorEnum are errors reported to the AWS Extension environment.

const (

	// FatalNoAPIKey is the error reported to the AWS Extension environment when
	// no API key has been set. Unused until we can report error
	// without stopping the extension.
	FatalNoAPIKey ErrorEnum = "Fatal.NoAPIKey"
	// FatalDogstatsdInit is the error reported to the AWS Extension environment when
	// DogStatsD fails to initialize properly. Unused until we can report error
	// without stopping the extension.
	FatalDogstatsdInit ErrorEnum = "Fatal.DogstatsdInit"
	// FatalBadEndpoint is the error reported to the AWS Extension environment when
	// bad endpoints have been configured. Unused until we can report error
	// without stopping the extension.
	FatalBadEndpoint ErrorEnum = "Fatal.BadEndpoint"
	// FatalConnectFailed is the error reported to the AWS Extension environment when
	// a connection failed.
	FatalConnectFailed ErrorEnum = "Fatal.ConnectFailed"
)

func (ErrorEnum) String

func (e ErrorEnum) String() string

String returns the string value for this ErrorEnum.

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.

type ID

type ID string

ID is the extension ID within the AWS Extension environment.

func Register

func Register() (ID, error)

Register registers the serverless daemon and subscribe to INVOKE and SHUTDOWN messages. Returns either (the serverless ID assigned by the serverless daemon + the api key as read from the environment) or an error.

func (ID) String

func (i ID) String() string

String returns the string value for this ID.

type LogsCollection

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

LogsCollection is the route on which the AWS environment is sending the logs for the extension to collect them. It is attached to the main HTTP server already receiving hits from the libraries client.

func (*LogsCollection) ServeHTTP

func (l *LogsCollection) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP - see type LogsCollection comment.

type Payload

type Payload struct {
	EventType          string `json:"eventType"`
	DeadlineMs         int64  `json:"deadlineMs"`
	InvokedFunctionArn string `json:"invokedFunctionArn"`
	ShutdownReason     string `json:"shutdownReason"`
}

Payload is the payload read in the response while subscribing to the AWS Extension env.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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