Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace timeout seconds option with timeout durations #294

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ func New(opts ...configOption) (*App, error) {

var apmOpts []apmproxy.Option

receiverTimeoutSeconds, err := getIntFromEnvIfAvailable("ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS")
if err != nil {
return nil, err
}
if receiverTimeoutSeconds != 0 {
apmOpts = append(apmOpts, apmproxy.WithReceiverTimeout(time.Duration(receiverTimeoutSeconds)*time.Second))
if receiverTimeout, ok, err := parseDurationTimeout(app.logger, "ELASTIC_APM_DATA_RECEIVER_TIMEOUT", "ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS"); err != nil || ok {
if err != nil {
return nil, err
}
apmOpts = append(apmOpts, apmproxy.WithReceiverTimeout(receiverTimeout))
}

dataForwarderTimeoutSeconds, err := getIntFromEnvIfAvailable("ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS")
if err != nil {
return nil, err
}
if dataForwarderTimeoutSeconds != 0 {
apmOpts = append(apmOpts, apmproxy.WithDataForwarderTimeout(time.Duration(dataForwarderTimeoutSeconds)*time.Second))
if dataForwarderTimeout, ok, err := parseDurationTimeout(app.logger, "ELASTIC_APM_DATA_FORWARDER_TIMEOUT", "ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS"); err != nil || ok {
if err != nil {
return nil, err
}
apmOpts = append(apmOpts, apmproxy.WithDataForwarderTimeout(dataForwarderTimeout))
}

if port := os.Getenv("ELASTIC_APM_DATA_RECEIVER_SERVER_PORT"); port != "" {
Expand Down Expand Up @@ -129,17 +127,28 @@ func New(opts ...configOption) (*App, error) {
return app, nil
}

func getIntFromEnvIfAvailable(name string) (int, error) {
strValue := os.Getenv(name)
if strValue == "" {
return 0, nil
func parseDurationTimeout(l *zap.SugaredLogger, flag string, deprecatedFlag string) (time.Duration, bool, error) {
if strValue, ok := os.LookupEnv(flag); ok {
d, err := time.ParseDuration(strValue)
if err != nil {
return 0, false, fmt.Errorf("failed to parse %s: %w", flag, err)
}

return d, true, nil
}

value, err := strconv.Atoi(strValue)
if err != nil {
return -1, err
if strValueSeconds, ok := os.LookupEnv(deprecatedFlag); ok {
l.Warnf("%s is deprecated, please consider moving to %s", deprecatedFlag, flag)

seconds, err := strconv.Atoi(strValueSeconds)
if err != nil {
return 0, false, fmt.Errorf("failed to parse %s: %w", deprecatedFlag, err)
}

return time.Duration(seconds) * time.Second, true, nil
}
return value, nil

return 0, false, nil
}

func parseStrategy(value string) (apmproxy.SendStrategy, bool) {
Expand Down
22 changes: 21 additions & 1 deletion docs/monitoring-aws-lambda.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,36 @@ Instead of specifying the <<aws-lambda-config-authentication-keys>> as plain tex
=== `ELASTIC_APM_SERVICE_NAME`
The configured name of your application or service. The APM agent will use this value when reporting data to the APM Server. If unset, the APM agent will automatically set the value based on the Lambda function name. Use this config option if you want to group multiple Lambda functions under a single service entity in APM.

[[aws-lambda-config-data-receiver-timeout-seconds]]
=== `ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS`
kruskall marked this conversation as resolved.
Show resolved Hide resolved

deprecated::[1.2.0,Replaced by `ELASTIC_APM_DATA_RECEIVER_TIMEOUT`. See <<aws-lambda-config-data-receiver-timeout>>]

The {apm-lambda-ext}'s timeout value, in seconds, for receiving data from the APM agent. The _default_ is `15`.

=== `ELASTIC_APM_DATA_RECEIVER_TIMEOUT`
kruskall marked this conversation as resolved.
Show resolved Hide resolved

coming::[1.2.0,Replaces `ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS`. See <<aws-lambda-config-data-receiver-timeout-seconds>>]

The {apm-lambda-ext}'s timeout value, for receiving data from the APM agent. The _default_ is `15s`.

=== `ELASTIC_APM_DATA_RECEIVER_SERVER_PORT`
The port on which the {apm-lambda-ext} listens to receive data from the APM agent. The _default_ is `8200`.

[[aws-lambda-config-data-forwarder-timeout]]
[[aws-lambda-config-data-forwarder-timeout-seconds]]
=== `ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS`

deprecated::[1.2.0,Replaced by `ELASTIC_APM_DATA_FORWARDER_TIMEOUT`. See <<aws-lambda-config-data-forwarder-timeout>>]

The timeout value, in seconds, for the {apm-lambda-ext}'s HTTP client sending data to the APM Server. The _default_ is `3`. If the extension's attempt to send APM data during this time interval is not successful, the extension queues back the data. Further attempts at sending the data are governed by an exponential backoff algorithm: data will be sent after a increasingly large grace period of 0, then circa 1, 4, 9, 16, 25 and 36 seconds, provided that the Lambda function execution is ongoing.

[[aws-lambda-config-data-forwarder-timeout]]
=== `ELASTIC_APM_DATA_FORWARDER_TIMEOUT`

coming::[1.2.0,Replaces `ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS`. See <<aws-lambda-config-data-forwarder-timeout-seconds>>]

The timeout value, for the {apm-lambda-ext}'s HTTP client sending data to the APM Server. The _default_ is `3s`. If the extension's attempt to send APM data during this time interval is not successful, the extension queues back the data. Further attempts at sending the data are governed by an exponential backoff algorithm: data will be sent after a increasingly large grace period of 0, then circa 1, 4, 9, 16, 25 and 36 seconds, provided that the Lambda function execution is ongoing.

=== `ELASTIC_APM_SEND_STRATEGY`
Whether to synchronously flush APM agent data from the {apm-lambda-ext} to the APM Server at the end of the function invocation.
The two accepted values are `background` and `syncflush`. The _default_ is `syncflush`.
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func TestAPMServerRecovery(t *testing.T) {
logsapiAddr := randomAddr()
newMockLambdaServer(t, logsapiAddr, eventsChannel, l)

t.Setenv("ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS", "1")
t.Setenv("ELASTIC_APM_DATA_FORWARDER_TIMEOUT", "1s")

eventsChain := []MockEvent{
{Type: InvokeStandard, APMServerBehavior: Hangs, ExecutionDuration: 1, Timeout: 5},
Expand Down