logsapi

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ProcessPlatformReport

func ProcessPlatformReport(metadataContainer *apmproxy.MetadataContainer, functionData *extension.NextEventResponse, platformReport LogEvent) (apmproxy.AgentData, error)

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,
	apmClient *apmproxy.Client,
	metadataContainer *apmproxy.MetadataContainer,
	runtimeDoneSignal chan struct{},
	prevEvent *extension.NextEventResponse,
) error

ProcessLogs consumes events until a RuntimeDone event corresponding to requestID is received, or ctx is canceled, and then returns.

func (*Client) Shutdown

func (lc *Client) Shutdown() error

Shutdown shutdowns the log service gracefully.

func (*Client) StartService

func (lc *Client) StartService(eventTypes []EventType, 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 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.

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 EventType

type EventType string

EventType represents the type of logs in Lambda

const (
	// Platform is to receive logs emitted by the platform
	Platform EventType = "platform"
	// Function is to receive logs emitted by the function
	Function EventType = "function"
	// Extension is to receive logs emitted by the extension
	Extension EventType = "extension"
)

type LogEvent

type LogEvent struct {
	Time         time.Time    `json:"time"`
	Type         SubEventType `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 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 SubEventType

type SubEventType string

SubEventType is a Logs API sub event type

const (
	// RuntimeDone event is sent when lambda function is finished it's execution
	RuntimeDone SubEventType = "platform.runtimeDone"
	Fault       SubEventType = "platform.fault"
	Report      SubEventType = "platform.report"
	Start       SubEventType = "platform.start"
)

type SubscribeRequest

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

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

Jump to

Keyboard shortcuts

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