Skip to content

Support Lambda Platform Metrics #202

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

Merged
merged 24 commits into from
Jun 8, 2022

Conversation

jlvoiseux
Copy link
Contributor

@jlvoiseux jlvoiseux commented May 31, 2022

Motivation / Summary

This PR is the continuation of #127, which had become obsolete and non-digestible due to the many changes brought to the extension since the initialization of the PR. The current PR implements the same features, but was rebased to enable a commit-by-commit review approach. It resolves #108.

The general flow is as follows:

  • The extension gets started (cold start)
  • A metadata container is initialized. This container is populated with the metadata extracted from the first APM payload sent by the agent
  • The log processing goroutine now handles a new type of SubEventType alongside RuntimeDone: Report. This report contains the metrics that we want to send to the APM Server. These metrics are packaged inside an APM payload (alongside the extracted metadata) in a dedicated function.

Files / Added Elements

  • 944e71f : Add a new package model which is a partial reproduction of the data model used by the Go APM Agent
  • 1ec30ab : Add a version utility file that is used to populate metadata
  • 10e2c77 and 3ec3bf9 : Functions that extract metadata from a given APM payload and populate a dedicated container. Since metadata extraction is tied to APM data, it is part of the extension package. Metadata is only extracted from the first APM payload received during the current lifetime of the extension.
  • a515a6d and c2b056a : Functions that turn the platform report provided by the Lambda runtime into a payload to be sent to the APM Server. Since metrics extraction is tied to logs data, it is part of the logsapi package.
  • 2b651c8 and 614be84 : main updates to modify the goroutines in order to extract metadata and process metrics.

Limitations / Elements to discuss

  • After several tests with two sample extensions with two different logs processing philosophies, we can conclude that the metrics report corresponding to the invocation i will be received during the execution of the invocation i+1.
  • The current implementation changes the Agent name to apm-lambda-extension when the metadata is attached to the generated metrics. While this makes sense in the framework of observability, the current APM UI is not equipped accordingly, and the service is associated to an unknown runtime:
    image
    My suggestion would be to stop altering the metadata for now to provide a consistent experience to end users.
  • The current package architecture can also be discussed. I wished I was able to keep logsapi and extension completely separate, but in the current implementation, logsapi.ProcessLogs() takes an apmServerTransport in argument in order to enqueue APM metrics payloads.
  • Several faas fields will be added to the metricset object in the APM data model (PR to be created). The subsequent modifications are beyond the scope of this initial PR, which aims to provide an initial implementation of Lambda metrics generation.

How to test

  • Clone the extension repo
  • Follow the instructions presented in the following sample repo
  • After executing your sample Lambda function a few times, you should see documents corresponding to your Lambda Platform report in your Elastic Cloud instance:
// Lambda Report
REPORT RequestId: 6862dc9b-3266-470a-9979-f39c21164f8c	Duration: 94.65 ms	Billed Duration: 95 ms	Memory Size: 128 MB	Max Memory Used: 77 MB	Init Duration: 479.30 ms	

image
image

jlvoiseux added 9 commits May 31, 2022 18:02
This commit is heavily inspired by the Go agent codebase. The data model needed to (un)marshal metrics as well as the associated metadata is defined.
This file contains information about the extension version. This used to enrich Metrics metadata with the version of the extension used to generate these metrics.
This commit allows for the extraction of the metadata from the first received transaction, with the assumption that this metadata will persist across invocations between cold starts.

Metadata is obtained from the uncompressed payload, and a dedicated container is populated.
These changes allow for populating dedicated structs by using the Lambda platform report provided after each invocation. Some fields also need to be added to the Event structs.

A notable addition is the modification of the metadata to incorporate extension-specific fields. I think that this information should be included, but the current implementation causes the extension to be displayed as a separate service in the APM UI.
@github-actions github-actions bot added the aws-λ-extension AWS Lambda Extension label May 31, 2022
@jlvoiseux jlvoiseux mentioned this pull request May 31, 2022
6 tasks
@apmmachine
Copy link

apmmachine commented May 31, 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-06-08T08:07:42.956+0000

  • Duration: 8 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 216
Skipped 4
Total 220

🤖 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 May 31, 2022 18:43
@jlvoiseux jlvoiseux requested a review from a team May 31, 2022 18:43
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, mostly minor comments.

@@ -15,9 +15,15 @@ require (
gotest.tools v2.2.0+incompatible
)

require (
go.elastic.co/apm v1.15.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use go.elastic.co/apm/v2, the current major version.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one thing (we should use Go agent v2).

I assume we'll want the labels to be recorded as faas.*, rather than labels.faas_*, right? Is your plan that once the server is updated, we'll come back and update the Go agent's model and the extension to send them as metricset fields? Similar to what we do for transaction and span properties: https://github.com/elastic/apm-agent-go/blob/94d06659448a555142c087721a79fff3ee732b49/model/model.go#L798-L804

@jlvoiseux
Copy link
Contributor Author

@axw Thank you for the review. I have updated the model to v2.
You are absolutely right regarding the faas labels. There was nothing preventing us from modifying the APM model in parallel to this PR, but given the number of changes introduced, I thought that the added complexity of having to test the PR alongside a modified APM Model was going to be too much at once. However, that is definitely the next step once we merge this.

@jlvoiseux jlvoiseux merged commit 3f78892 into elastic:main Jun 8, 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.

Support for Metrics
4 participants