Skip to content

Conversation

jlvoiseux
Copy link
Contributor

@jlvoiseux jlvoiseux commented Mar 10, 2022

Motivation

This PR resolves #140. If an error occurs during registration, the InitError signal is sent to the Lambda runtime. If an error occurs when requesting the next event, the ExitError signal is sent to the Lambda runtime. The observed behavior upon reception of these signals is that the runtime exits cleanly and displays the received error.

Files changes

All the changes are in main.go. Aside from the implementation of those signals, two snippets have been added for testing purposes (and will be removed before merge).

Behavior

InitError sent after the extension attempts to register
Response

{
  "errorMessage": "RequestId: 5cea4d67-8113-4e47-b319-2c806ef09699 Error: exit code 0",
  "errorType": "Extension.InitError"
}

Behavior

START RequestId: 5cea4d67-8113-4e47-b319-2c806ef09699 Version: $LATEST
2022/03/10 10:48:45 7306098f-8b46-43e9-b61a-9e2eaa502013
2022/03/10 10:48:45 Register response: {
	"functionName": "lambda-sample-dev-jlvoiseux",
	"functionVersion": "$LATEST",
	"handler": "lambda_function.lambda_handler"
}
2022/03/10 10:48:45 Error: extension init crash simulation
2022/03/10 10:48:45 Init error signal sent to runtime : &{OK}
2022/03/10 10:48:45 Exiting
EXTENSION	Name: extension-dev-linux-amd64	State: InitError	Events: [INVOKE,SHUTDOWN]	Error Type: Extension.InitError
END RequestId: 5cea4d67-8113-4e47-b319-2c806ef09699
REPORT RequestId: 5cea4d67-8113-4e47-b319-2c806ef09699	Duration: 698.99 ms	Billed Duration: 699 ms	Memory Size: 128 MB	Max Memory Used: 11 MB	
RequestId: 5cea4d67-8113-4e47-b319-2c806ef09699 Error: exit code 0
Extension.InitError

Comparison : crash (main.go returns) after the extension attempts to register
Response

{
  "errorMessage": "RequestId: fc4848ae-862b-4dcd-900c-48f0e7997136 Error: exit code 0",
  "errorType": "Extension.Crash"
}

Behavior

START RequestId: fc4848ae-862b-4dcd-900c-48f0e7997136 Version: $LATEST
2022/03/10 11:03:38 67944856-7a88-4625-80cc-f7da2399d4b5
2022/03/10 11:03:38 Register response: {
	"functionName": "lambda-sample-dev-jlvoiseux",
	"functionVersion": "$LATEST",
	"handler": "lambda_function.lambda_handler"
}
EXTENSION	Name: extension-dev-linux-amd64	State: Registered	Events: [INVOKE,SHUTDOWN]
END RequestId: fc4848ae-862b-4dcd-900c-48f0e7997136
REPORT RequestId: fc4848ae-862b-4dcd-900c-48f0e7997136	Duration: 665.32 ms	Billed Duration: 666 ms	Memory Size: 128 MB	Max Memory Used: 11 MB	
RequestId: fc4848ae-862b-4dcd-900c-48f0e7997136 Error: exit code 0
Extension.Crash

ExitError sent after the extension receives a new event
Response

{
  "errorMessage": "RequestId: 134c182e-5465-4d09-99bb-0268c1f04111 Error: exit code 0",
  "errorType": "Extension.ExitError"
}

Behavior

START RequestId: 134c182e-5465-4d09-99bb-0268c1f04111 Version: $LATEST
2022/03/10 11:00:21 6d39b1d6-e20b-4de8-9249-2ecec1ae32c4
2022/03/10 11:00:21 Register response: {
	"functionName": "lambda-sample-dev-jlvoiseux",
	"functionVersion": "$LATEST",
	"handler": "lambda_function.lambda_handler"
}
2022/03/10 11:00:21 Could not read ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS, defaulting to 15: strconv.Atoi: parsing "": invalid syntax
2022/03/10 11:00:21 Extension listening for apm data on :8200
2022/03/10 11:00:21 Extension listening for logsAPI events on 169.254.79.130:36657
LOGS	Name: extension-dev-linux-amd64	State: Subscribed	Types: [platform]
2022/03/10 11:00:21 Waiting for next event...
[INFO]	2022-03-10T11:00:22.160Z		Fetched APM Server version 7.16.0
EXTENSION	Name: extension-dev-linux-amd64	State: Ready	Events: [INVOKE,SHUTDOWN]
2022/03/10 11:00:22 Received event: {
	"eventType": "INVOKE",
	"deadlineMs": 1646910042219,
	"requestId": "134c182e-5465-4d09-99bb-0268c1f04111",
	"invokedFunctionArn": "arn:aws:lambda:eu-central-1:627286350134:function:lambda-sample-dev-jlvoiseux",
	"tracing": {
		"type": "X-Amzn-Trace-Id",
		"value": "Root=1-6229da45-4fbaaf817a8b4f2a60990094;Parent=2d2f894c215a852a;Sampled=0"

Comparison : crash (main.go returns) after the extension receives a new event
Response

{
  "errorMessage": "RequestId: 20a2a54a-5de8-4a44-a961-3313982ab0cc Error: exit code 0",
  "errorType": "Extension.Crash"
}

Behavior

START RequestId: 20a2a54a-5de8-4a44-a961-3313982ab0cc Version: $LATEST
2022/03/10 11:07:34 301fdb54-0113-4f63-8740-f63ececa1ba4
2022/03/10 11:07:34 Register response: {
	"functionName": "lambda-sample-dev-jlvoiseux",
	"functionVersion": "$LATEST",
	"handler": "lambda_function.lambda_handler"
}
2022/03/10 11:07:34 Could not read ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS, defaulting to 15: strconv.Atoi: parsing "": invalid syntax
2022/03/10 11:07:34 Extension listening for apm data on :8200
2022/03/10 11:07:34 Extension listening for logsAPI events on 169.254.79.130:40753
LOGS	Name: extension-dev-linux-amd64	State: Subscribed	Types: [platform]
2022/03/10 11:07:34 Waiting for next event...
[INFO]	2022-03-10T11:07:34.825Z		Fetched APM Server version 7.16.0
EXTENSION	Name: extension-dev-linux-amd64	State: Ready	Events: [INVOKE,SHUTDOWN]
2022/03/10 11:07:34 Received event: {
	"eventType": "INVOKE",
	"deadlineMs": 1646910474890,
	"requestId": "20a2a54a-5de8-4a44-a961-3313982ab0cc",
	"invokedFunctionArn": "arn:aws:lambda:eu-central-1:627286350134:function:lambda-sample-dev-jlvoiseux",
	"tracing": {
		"type": "X-Amzn-Trace-Id",
		"value": "Root=1-6229dbf6-1cb0196749627d1043e16a10;Parent=3965ab7127536b71;Sampled=0"
	}
}
2022/03/10 11:07:34 Checking for agent data
2022/03/10 11:07:34 No agent data on buffer
[WARNING]	2022-03-10T11:07:34.893Z	20a2a54a-5de8-4a44-a961-3313982ab0cc	Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc2e2ae81f0>: Failed to establish a new connection: [Errno 111] Connection refused')': /intake/v2/events
END RequestId: 20a2a54a-5de8-4a44-a961-3313982ab0cc
REPORT RequestId: 20a2a54a-5de8-4a44-a961-3313982ab0cc	Duration: 42.64 ms	Billed Duration: 43 ms	Memory Size: 128 MB	Max Memory Used: 76 MB	Init Duration: 447.03 ms	
RequestId: 20a2a54a-5de8-4a44-a961-3313982ab0cc Error: exit code 0
Extension.Crash

Pending points

  • Are there other places where we might want to send InitError and ExitError signals ?

@github-actions github-actions bot added the aws-λ-extension AWS Lambda Extension label Mar 10, 2022
@ghost
Copy link

ghost commented Mar 10, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-31T10:46:00.350+0000

  • Duration: 8 min 33 sec

Test stats 🧪

Test Results
Failed 0
Passed 240
Skipped 6
Total 246

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@jlvoiseux jlvoiseux marked this pull request as ready for review March 10, 2022 16:40
@jlvoiseux jlvoiseux merged commit a14c80f into elastic:main Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-λ-extension AWS Lambda Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add calls to InitError and ExitError to notify the lambda runtime that the extension had an error

3 participants