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

Fix #1770 support for proxies in destination context #2126

Merged
merged 7 commits into from
Jun 29, 2021
Merged

Fix #1770 support for proxies in destination context #2126

merged 7 commits into from
Jun 29, 2021

Conversation

ebuildy
Copy link
Contributor

@ebuildy ebuildy commented Jun 24, 2021

Fix #1770 issue:

If a proxy is used, the destination context will not be set on outgoing http spans because the URL cannot be successfully extracted from the request.

Copy/paste from Qard/http-request-to-url@7406c37

Checklist

  • Implement code
  • Add tests
  • Update TypeScript typings
  • Update documentation
  • Add CHANGELOG.asciidoc entry
  • Commit message follows commit guidelines

@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Jun 24, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Jun 24, 2021

💚 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

Expand to view the summary

Build stats

  • Build Cause: astorm commented: jenkins run the tests please

  • Start Time: 2021-06-29T05:35:11.475+0000

  • Duration: 19 min 24 sec

  • Commit: 951d000

Test stats 🧪

Test Results
Failed 0
Passed 19040
Skipped 0
Total 19040

Trends 🧪

Image of Build Times

Image of Tests

@trentm
Copy link
Member

trentm commented Jun 24, 2021

@ebuildy Thanks.

The best original discussion of this is here: Qard/http-request-to-url#1
There is also a test case example there. Can we take that and add to the test suite here?

@trentm
Copy link
Member

trentm commented Jun 24, 2021

jenkins run the tests

@trentm
Copy link
Member

trentm commented Jun 24, 2021

I'm not clear on the history of commits here. Is this proxy functionality something we missed in #2039 where the 'http-request-to-url' dep was removed?

@trentm trentm linked an issue Jun 24, 2021 that may be closed by this pull request
@ebuildy
Copy link
Contributor Author

ebuildy commented Jun 24, 2021

There is an old bug in case we use HTTP proxy to send query, the URL from request.path == proxied URL (the URL we want to report in APM). The problem is this throw error all the time (see

agent.logger.error('Could not set destination context: %s', e.message)
) and fill logs (whereas the URL is valid).

@trentm trentm added the bug label Jun 24, 2021
@astorm
Copy link
Contributor

astorm commented Jun 24, 2021

jenkins run the tests please

@astorm
Copy link
Contributor

astorm commented Jun 24, 2021

There is an old bug in case we use HTTP proxy to send query, the URL from request.path == proxied URL (the URL we want to report in APM). The problem is this throw error all the time (see

agent.logger.error('Could not set destination context: %s', e.message)
) and fill logs (whereas the URL is valid).

Additional Context: We had hoped/assumed that removing the dependency on http-request-to-url would fix this behavior. However, it did not. FWIW I managed to cobble together a proxy server that reproduced the behavior we're trying to fix (#1770 (comment)) so we should be able to validate the fix this time.

@ebuildy
Copy link
Contributor Author

ebuildy commented Jun 24, 2021

Wonderful!

It looks like a bug from nodeJS it-self actually, there is no way to guess if a https://github.com/nodejs/node/blob/master/lib/_http_client.js ClientRequest is using a proxy or not.

@astorm
Copy link
Contributor

astorm commented Jun 24, 2021

@elasticmachine, run elasticsearch-ci/docs

@astorm
Copy link
Contributor

astorm commented Jun 24, 2021

It looks like our CI is happy with things. Per @trentm's comments above

Can we take that and add to the test suite here?

I've written up a test that captures the intent of this fix, based on the http-request-to-url test
https://gist.github.com/astorm/ff0211e076d670d3c41e8fe0169f8532

@ebuildy -- would you be able to

  1. Add the test at the above gist to your PR
  2. Add an entry to the CHANGELOG.asciidoc mentioning this bug fix?

With those in place we should be able to merge.

@astorm
Copy link
Contributor

astorm commented Jun 25, 2021

jenkins run the tests please

@astorm
Copy link
Contributor

astorm commented Jun 25, 2021

@elasticmachine, run elasticsearch-ci/docs

@astorm
Copy link
Contributor

astorm commented Jun 25, 2021

@ebuildy Apologies -- it looks like there's a timing issue in the test I handed you (only pops up in Node 8.6). I made a PR to your branch to fix that. https://github.com/ebuildy/apm-agent-nodejs/pull/1/files

@ebuildy
Copy link
Contributor Author

ebuildy commented Jun 26, 2021

Ok got it! thanks you. (Sorry for the delay, I am in France ....)

@astorm
Copy link
Contributor

astorm commented Jun 26, 2021

@ebuildy No rush intended or asked for :)

Also -- PR to fix the above linting errors: https://github.com/ebuildy/apm-agent-nodejs/pull/2

@ebuildy
Copy link
Contributor Author

ebuildy commented Jun 27, 2021

sure! just saying that because I answer always a day after. Thanks you for the fix

@astorm
Copy link
Contributor

astorm commented Jun 27, 2021

jenkins run the tests please

@astorm
Copy link
Contributor

astorm commented Jun 27, 2021

@elasticmachine, run elasticsearch-ci/docs

@astorm
Copy link
Contributor

astorm commented Jun 29, 2021

jenkins run the tests please

@astorm
Copy link
Contributor

astorm commented Jun 29, 2021

@elasticmachine, run elasticsearch-ci/docs

Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

👍 does the thing, approving and merging

@astorm astorm merged commit a80aea3 into elastic:master Jun 29, 2021
dgieselaar pushed a commit to dgieselaar/apm-agent-nodejs that referenced this pull request Sep 10, 2021
…2126)

* Fix elastic#1770 support for proxies in destination context

Fix for elastic#1770, ensures only a single url is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for proxies in destination context
4 participants