Skip to content

Conversation

tonyman19
Copy link
Contributor

This PR lets instrument elb serverless requests.

When lambda is being connected directly to ALB (this is useful when you want to rewrite some ECS existing endpoints with their lambda counterparts)

It fixes the bugs for full url creation for api gw ver 1 (when url is formed from queryStringParameters collection):

  1. full url was not properly formed with parameters (& were missing between key=value elements)
  2. url encoding was not applied to key / value pairs inside url

Related issues

closes #1587

@cla-checker-service
Copy link

cla-checker-service bot commented Aug 5, 2022

💚 CLA has been signed

@github-actions github-actions bot added agent-python community Issues opened by the community triage Issues awaiting triage labels Aug 5, 2022
@ghost
Copy link

ghost commented Aug 5, 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-08-09T14:11:26.293+0000

  • Duration: 30 min 43 sec

Test stats 🧪

Test Results
Failed 0
Passed 4937
Skipped 3455
Total 8392

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

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

  • /test : Re-trigger the build.

  • /test linters : Run the Python linters only.

  • /test full : Run the full matrix of tests.

  • /test benchmark : Run the APM Agent Python benchmarks tests.

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

@tonyman19
Copy link
Contributor Author

/test

Copy link
Contributor

@basepi basepi left a comment

Choose a reason for hiding this comment

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

This is really excellent, thank you! Just one minor change, and I'll also be opening a PR against the spec so we can make sure this is consistent across the serverless agents.

@basepi
Copy link
Contributor

basepi commented Aug 8, 2022

/test

@ghost
Copy link

ghost commented Aug 8, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (68/68) 💚
Files 100.0% (227/227) 💚
Classes 100.0% (227/227) 💚
Lines 89.738% (17324/19305) 👍 0.096
Conditionals 77.109% (3163/4102) 👍 0.24
Copy link
Contributor

@basepi basepi left a comment

Choose a reason for hiding this comment

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

I added the fix I recommended + a CHANGELOG entry

@basepi
Copy link
Contributor

basepi commented Aug 8, 2022

@tonyman19 Did you sign the CLA for the email anton@mycarly.com? That's the email attached to your commits.

@tonyman19
Copy link
Contributor Author

tonyman19 commented Aug 9, 2022 via email

@tonyman19
Copy link
Contributor Author

Hi Colton,

Thank you for review and quick reply. Finalized signing for anton.matviyenko@gmail.com
What about recorded commits - is it possible to change from anton@mycarly.com to the abovementioned email?
Or is it ok the way they are ATM?
Will sign the CLA for anton@mycarly.com as well.

@tonyman19
Copy link
Contributor Author

Short question about following inconsistency that I have found. Is it by purpose or just a mistake?

if self.source == "api": .... cloud_context["origin"]["account"] = {"id": self.event["requestContext"]["accountId"]} elif self.source == "sns": ..... cloud_context["origin"]["account_id"] = record["Sns"]["TopicArn"].split(":")[4] 

So first time (and everywhere else) we are creating subobject with id field ["origin"]["account"]["id"] - next time we create subelement account_id which is located under ["origin"]["account_id"].

Should we also fix that here?

@tonyman19
Copy link
Contributor Author

Regarding your removal of:

service_context["origin"]["version"] = self.event.get("version", "1.0") 

version field is also absent for rest (or http integrations) v1 (check aws_api_test_data.json)

I assumed that there might be a second version of elb integration where it will be present so I did it the same way. I did it conforming the spec for api gw: https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-aws-lambda.md#api-gateway-v1--v2

context.service.origin.version e.g. 1.0 1.0 for API Gateway V1, 2.0 for API Gateway V2. event.version (or 1.0 if that field is not present)
@basepi
Copy link
Contributor

basepi commented Aug 9, 2022

I suppose there could be a v2 for ELB some day. We did it that way for API Gateway because there were two prominent (and quite different) versions in use when we launched the integration. I think since there's only one version of ELB right now, we'll leave off the version (like we do for the other non-http triggers), and we can add it in the future if it becomes relevant.

Thanks for signing the CLA with the correct email. I can't change the email on the commits, you would have to re-configure your git client and then rebase the commits. But everything is good now that you signed the CLA for the correct email.

Good catch on the SNS account_id -- that was definitely a bug! I have fixed it.

@basepi basepi merged commit 007d12a into elastic:main Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-python community Issues opened by the community triage Issues awaiting triage
2 participants