From ff09ef4024b3dbf30da91ab7c4e9a105811dd032 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Tue, 2 Aug 2022 00:26:25 +0200 Subject: [PATCH 1/4] feat: make buffer size for agent data configurable Add ELASTIC_APM_LAMBDA_AGENT_DATA_BUFFER_SIZE variable to set the buffer size. --- apm-lambda-extension/apmproxy/client.go | 3 ++- apm-lambda-extension/apmproxy/option.go | 7 +++++++ apm-lambda-extension/app/app.go | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apm-lambda-extension/apmproxy/client.go b/apm-lambda-extension/apmproxy/client.go index d9309354..f362a4f2 100644 --- a/apm-lambda-extension/apmproxy/client.go +++ b/apm-lambda-extension/apmproxy/client.go @@ -30,6 +30,7 @@ const ( defaultDataReceiverTimeout time.Duration = 15 * time.Second defaultDataForwarderTimeout time.Duration = 3 * time.Second defaultReceiverAddr = ":8200" + defaultAgentBufferSize int = 100 ) // Client is the client used to communicate with the apm server. @@ -53,7 +54,7 @@ func NewClient(opts ...Option) (*Client, error) { bufferPool: sync.Pool{New: func() interface{} { return &bytes.Buffer{} }}, - DataChannel: make(chan AgentData, 100), + DataChannel: make(chan AgentData, defaultAgentBufferSize), client: &http.Client{ Transport: http.DefaultTransport.(*http.Transport).Clone(), }, diff --git a/apm-lambda-extension/apmproxy/option.go b/apm-lambda-extension/apmproxy/option.go index 08ef47ed..3de18a0a 100644 --- a/apm-lambda-extension/apmproxy/option.go +++ b/apm-lambda-extension/apmproxy/option.go @@ -65,3 +65,10 @@ func WithReceiverAddress(addr string) Option { c.receiver.Addr = addr } } + +// WithAgentDataBufferSize sets the agent data buffer size. +func WithAgentDataBufferSize(size int) Option { + return func(c *Client) { + c.DataChannel = make(chan AgentData, size) + } +} diff --git a/apm-lambda-extension/app/app.go b/apm-lambda-extension/app/app.go index d1cf74d4..29af7ccc 100644 --- a/apm-lambda-extension/app/app.go +++ b/apm-lambda-extension/app/app.go @@ -84,6 +84,14 @@ func New(opts ...configOption) (*App, error) { apmOpts = append(apmOpts, apmproxy.WithReceiverAddress(fmt.Sprintf(":%s", port))) } + if bufferSize := os.Getenv("ELASTIC_APM_LAMBDA_AGENT_DATA_BUFFER_SIZE"); bufferSize != "" { + if size, err := strconv.Atoi(bufferSize); err != nil { + return nil, err + } else { + apmOpts = append(apmOpts, apmproxy.WithAgentDataBufferSize(size)) + } + } + apmOpts = append(apmOpts, apmproxy.WithURL(os.Getenv("ELASTIC_APM_LAMBDA_APM_SERVER"))) ac, err := apmproxy.NewClient(apmOpts...) From f223e2f003af05debb4736a66247ff046900fd0e Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 3 Aug 2022 22:07:18 +0200 Subject: [PATCH 2/4] lint: remove if else statement --- apm-lambda-extension/app/app.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apm-lambda-extension/app/app.go b/apm-lambda-extension/app/app.go index 29af7ccc..d75ecdf6 100644 --- a/apm-lambda-extension/app/app.go +++ b/apm-lambda-extension/app/app.go @@ -85,11 +85,12 @@ func New(opts ...configOption) (*App, error) { } if bufferSize := os.Getenv("ELASTIC_APM_LAMBDA_AGENT_DATA_BUFFER_SIZE"); bufferSize != "" { - if size, err := strconv.Atoi(bufferSize); err != nil { + size, err := strconv.Atoi(bufferSize) + if err != nil { return nil, err - } else { - apmOpts = append(apmOpts, apmproxy.WithAgentDataBufferSize(size)) } + + apmOpts = append(apmOpts, apmproxy.WithAgentDataBufferSize(size)) } apmOpts = append(apmOpts, apmproxy.WithURL(os.Getenv("ELASTIC_APM_LAMBDA_APM_SERVER"))) From 5eda35a4a3d7ed53a84c7cc8509ab2b3cb9f827d Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 3 Aug 2022 22:12:44 +0200 Subject: [PATCH 3/4] changelog: add changelog entry --- apm-lambda-extension/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/apm-lambda-extension/CHANGELOG.asciidoc b/apm-lambda-extension/CHANGELOG.asciidoc index 6b802f80..ef058fb1 100644 --- a/apm-lambda-extension/CHANGELOG.asciidoc +++ b/apm-lambda-extension/CHANGELOG.asciidoc @@ -24,6 +24,7 @@ https://github.com/elastic/apm-aws-lambda/compare/v1.0.2...main[View commits] - Added support for Secret Manager {pull}208[208] - Added support for Lambda platform metrics {pull}202[202] - Migrated to AWS SDK for Go v2 {pull}232[232] +- Make buffer size for agent data configurable {pull}262[262] [float] ==== Bug fixes From 301395dfeba9db7ce888a85ca00297e6e099b759 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Wed, 3 Aug 2022 22:16:50 +0200 Subject: [PATCH 4/4] docs: add documentation for ELASTIC_APM_LAMBDA_AGENT_DATA_BUFFER_SIZE --- docs/monitoring-aws-lambda.asciidoc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/monitoring-aws-lambda.asciidoc b/docs/monitoring-aws-lambda.asciidoc index 256610cb..8d8935ab 100644 --- a/docs/monitoring-aws-lambda.asciidoc +++ b/docs/monitoring-aws-lambda.asciidoc @@ -45,6 +45,9 @@ The following configuration options are particularly relevant for the {apm-lambd === `ELASTIC_APM_LAMBDA_APM_SERVER` This required config option controls where the {apm-lambda-ext} will ship data. This should be the URL of the final APM Server destination for your telemetry. +=== `ELASTIC_APM_LAMBDA_AGENT_DATA_BUFFER_SIZE` +The size of the buffer that stores APM agent data to be forwarded to the APM server. The _default_ is `100`. + [[aws-lambda-config-authentication-keys]] === `ELASTIC_APM_SECRET_TOKEN` or `ELASTIC_APM_API_KEY` One of these (or, alternatively, the corresponding settings for the AWS Secrets Manager IDs) needs to be set as the authentication method that the {apm-lambda-ext} uses when sending data to the URL configured via `ELASTIC_APM_LAMBDA_APM_SERVER`. Alternatively, you can store your APM Server credentials <> and use the <> config options, instead. Sending data to the APM Server if none of these options is set is possible, but your APM agent must be allowed to send data to your APM server in https://www.elastic.co/guide/en/apm/guide/current/configuration-anonymous.html[anonymous mode]. @@ -121,4 +124,4 @@ That's it. With the first invocation (cold start) of your Lambda function you sh [source, yml] ---- "Using the APM secret token retrieved from Secrets Manager." ----- \ No newline at end of file +----