logsapi

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaVersion20210318 = "2021-03-18"
	SchemaVersionLatest   = SchemaVersion20210318
)

Variables

This section is empty.

Functions

func ProcessFunctionLog added in v1.2.0

func ProcessFunctionLog(
	requestID string,
	invokedFnArn string,
	log LogEvent,
) ([]byte, error)

ProcessFunctionLog processes the `function` log line from lambda logs API and returns a byte array containing the JSON body for the extracted log along with the timestamp. A non nil error is returned when marshaling of the log into JSON fails.

func ProcessPlatformReport

func ProcessPlatformReport(fnARN string, deadlineMs int64, ts time.Time, platformReport LogEvent) ([]byte, error)

ProcessPlatformReport processes the `platform.report` log line from lambda logs API and returns a byte array containing the JSON body for the extracted platform metrics. A non nil error is returned when marshaling of platform metrics into JSON fails.

Types

type BufferingCfg

type BufferingCfg struct {
	// MaxItems is the maximum number of events to be buffered in memory. (default: 10000, minimum: 1000, maximum: 10000)
	MaxItems uint32 `json:"maxItems"`
	// MaxBytes is the maximum size in bytes of the logs to be buffered in memory. (default: 262144, minimum: 262144, maximum: 1048576)
	MaxBytes uint32 `json:"maxBytes"`
	// TimeoutMS is the maximum time (in milliseconds) for a batch to be buffered. (default: 1000, minimum: 100, maximum: 30000)
	TimeoutMS uint32 `json:"timeoutMs"`
}

BufferingCfg is the configuration set for receiving logs from Logs API. Whichever of the conditions below is met first, the logs will be sent

type Client

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

Client is the client used to subscribe to the Logs API.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient returns a new Client with the given URL.

func (*Client) ProcessLogs

func (lc *Client) ProcessLogs(
	ctx context.Context,
	requestID string,
	invokedFnArn string,
	dataChan chan []byte,
	isShutdown bool,
)

ProcessLogs consumes log events until there are no more log events that can be consumed or ctx is cancelled. For INVOKE event this state is reached when runtimeDone event for the current requestID is processed whereas for SHUTDOWN event this state is reached when the platformReport event for the previous requestID is processed.

func (*Client) Shutdown

func (lc *Client) Shutdown() error

Shutdown shutdowns the log service gracefully.

func (*Client) StartService

func (lc *Client) StartService(extensionID string) error

StartService starts the HTTP server listening for log events and subscribes to the Logs API.

type ClientOption

type ClientOption func(*Client)

ClientOption is a config option for a Client.

func WithInvocationLifecycler added in v1.3.0

func WithInvocationLifecycler(l invocationLifecycler) ClientOption

WithInvocationLifecycler configures a lifecycler for acting on certain log events.

func WithListenerAddress

func WithListenerAddress(s string) ClientOption

WithListenerAddress sets the listener address of the server listening for logs event.

func WithLogBuffer

func WithLogBuffer(size int) ClientOption

WithLogBuffer sets the size of the buffer storing queued logs for processing.

func WithLogger

func WithLogger(logger *zap.SugaredLogger) ClientOption

WithLogger sets the logger.

func WithLogsAPIBaseURL

func WithLogsAPIBaseURL(s string) ClientOption

WithLogsAPIBaseURL sets the logs api base url.

func WithSubscriptionTypes added in v1.2.0

func WithSubscriptionTypes(types ...SubscriptionType) ClientOption

WithSubscriptionTypes sets the logstreams that the Logs API will subscribe to.

type Destination

type Destination struct {
	Protocol   string `json:"protocol"`
	URI        string `json:"URI"`
	HTTPMethod string `json:"method"`
	Encoding   string `json:"encoding"`
}

Destination is the configuration for listeners who would like to receive logs with HTTP

type LogEvent

type LogEvent struct {
	Time         time.Time    `json:"time"`
	Type         LogEventType `json:"type"`
	StringRecord string
	Record       LogEventRecord
}

LogEvent represents an event received from the Logs API

func (*LogEvent) UnmarshalJSON

func (le *LogEvent) UnmarshalJSON(data []byte) error

type LogEventRecord

type LogEventRecord struct {
	RequestID string          `json:"requestId"`
	Status    string          `json:"status"`
	Metrics   PlatformMetrics `json:"metrics"`
}

LogEventRecord is a sub-object in a Logs API event

type LogEventType added in v1.2.0

type LogEventType string

LogEventType represents the log type that is received in the log messages

const (
	// PlatformRuntimeDone event is sent when lambda function is finished it's execution
	PlatformRuntimeDone LogEventType = "platform.runtimeDone"
	PlatformFault       LogEventType = "platform.fault"
	PlatformReport      LogEventType = "platform.report"
	PlatformLogsDropped LogEventType = "platform.logsDropped"
	PlatformStart       LogEventType = "platform.start"
	PlatformEnd         LogEventType = "platform.end"
	FunctionLog         LogEventType = "function"
)

type MetricsContainer

type MetricsContainer struct {
	Metrics *model.Metrics `json:"metricset"`
}

func (MetricsContainer) Add

func (mc MetricsContainer) Add(name string, value float64)

Add adds a metric with the given name, labels, and value, The labels are expected to be sorted lexicographically.

func (MetricsContainer) MarshalFastJSON

func (mc MetricsContainer) MarshalFastJSON(json *fastjson.Writer) error

type PlatformMetrics

type PlatformMetrics struct {
	DurationMs       float32 `json:"durationMs"`
	BilledDurationMs int32   `json:"billedDurationMs"`
	MemorySizeMB     int32   `json:"memorySizeMB"`
	MaxMemoryUsedMB  int32   `json:"maxMemoryUsedMB"`
	InitDurationMs   float32 `json:"initDurationMs"`
}

type SchemaVersion

type SchemaVersion string

SchemaVersion is the Lambda runtime API schema version

type SubscribeRequest

type SubscribeRequest struct {
	SchemaVersion SchemaVersion      `json:"schemaVersion"`
	LogTypes      []SubscriptionType `json:"types"`
	BufferingCfg  BufferingCfg       `json:"buffering"`
	Destination   Destination        `json:"destination"`
}

SubscribeRequest is the request body that is sent to Logs API on subscribe

type SubscriptionType added in v1.2.0

type SubscriptionType string

SubscriptionType represents the log streams that the Lambda Logs API provides for subscription

const (
	// Platform logstream records events and errors related to
	// invocations and extensions
	Platform SubscriptionType = "platform"
	// Function logstream records logs written by lambda function
	// to stderr or stdout
	Function SubscriptionType = "function"
	// Extension logstream records logs generated by extension
	Extension SubscriptionType = "extension"
)

Jump to

Keyboard shortcuts

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