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

Support middleware injected by AppDynamics #4119

Merged
merged 1 commit into from Feb 5, 2019

Conversation

@mschnee
Copy link

commented Jan 21, 2019

Description

Much like the workaround for NewRelic, appd replaces the express handle with its own, and stores it in handle.__appdynamicsProxyInfo__.orig. This causes proto._findLayerByHandler to fail.

This pull request was originally created by @mikewli and @gconaty - I have updated it to include unit tests.

Checklist

  • New tests added or existing tests modified to cover all changes
    • Unit tests have been added
  • Code conforms with the style guide
    • All lint tests passes
@slnode

This comment has been minimized.

Copy link

commented Jan 21, 2019

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@mschnee

This comment has been minimized.

Copy link
Author

commented Jan 21, 2019

Note for the softlayer status checks: I do not have permission to grant access to the private repository into which loopback has been forked for this fix.

@jannyHou

This comment has been minimized.

Copy link
Contributor

commented Jan 21, 2019

@slnode test please

Copy link
Contributor

left a comment

@mschnee Thank you and @mikewli , @gconaty for providing the fix+test. I left a nitpick, the change looks reasonable to me, while I am interested to know the background of the issue, could you post a link or related story here?

@@ -225,7 +225,11 @@ proto._findLayerByHandler = function(handler) {
for (var k = this._router.stack.length - 1; k >= 0; k--) {
if (this._router.stack[k].handle === handler ||
// NewRelic replaces the handle and keeps it as __NR_original
this._router.stack[k].handle['__NR_original'] === handler
this._router.stack[k].handle['__NR_original'] === handler ||

This comment has been minimized.

Copy link
@jannyHou

jannyHou Jan 21, 2019

Contributor

@mschnee could you refactor the assertion to be a variable, like

var OrigHasHandler = this._router.stack[k].handle['__appdynamicsProxyInfo__'] &&
        this._router.stack[k].handle['__appdynamicsProxyInfo__']['orig'] === handler
      
var handlerExists = this._router.stack[k].handle === handler || this._router.stack[k].handle['__NR_original'] === handler || OrigHasHandler
if (handlerExists) {
// ...code
}

This comment has been minimized.

Copy link
@bajtos

bajtos Jan 22, 2019

Member

+1, let's clean up this complicated condition please and split it into multiple smaller conditions with their results stored in well-named variables.

E.g.

const current = this._router.stack[k].handle;

const isOriginal = current === handler;
// NewRelic replaces the handle and keeps it as __NR_original
const isNewRelic = current['__NR_original'] === handler;
 // AppDynamics replaces the handle and keeps it as __appdynamicsProxyInfo__.orig
const isAppDynamics = // ...

if (isOriginal || isNewRelic || isAppDynamics) {
  return this._router.stack[k];
} else {
 // ...
}

This comment has been minimized.

Copy link
@mschnee

mschnee Jan 22, 2019

Author

I've cleaned up the complicated conditions to be a bit more human readable.

Unfortunately, @jannyHou , I don't have very much context into the background of this issue :(

Copy link
Member

left a comment

The patch looks mostly good, thank you for the contribution ❤️

@bajtos
bajtos approved these changes Jan 24, 2019
Copy link
Member

left a comment

LGTM 👏

Could you please squash all commits into a single one and provide a descriptive commit message following our Commit Message Guidelines?

In case you are not familiar with git history rewriting:

git rebase -i master
# edit the instructions to squash commits
git push --force-with-lease

I'll leave it up to @jannyHou to do the final approval and landing.

@bajtos bajtos self-assigned this Jan 24, 2019
@bajtos

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

@mschnee one more thing: before we can accept your contribution, we need you to sign our CLA - see https://cla.strongloop.com/agreements/strongloop/loopback

@mschnee mschnee force-pushed the studykik:fix/appdynamics-proxy branch from 55c97e8 to c29bad3 Jan 24, 2019
@mschnee

This comment has been minimized.

Copy link
Author

commented Jan 24, 2019

Thanks for the review! I have squashed the commits and provided a more descriptive commit message.

I have also myself accepted the CLA
image

@bajtos

This comment has been minimized.

Copy link
Member

commented Jan 25, 2019

Thank you, @mschnee. I see that the commit was authored by two people, you and @mikewli. We need all authors to sign our CLA. Could you please talk to @mikewli and get him to sign our CLA too?

Also the commit is message is unfortunately not exactly matching our guidelines, this is the report reported by our Commit Linter check:

**************************************************
**
**  Linting commit logs
**
**  1 problems found:
**    c29bad3 - Add a workaround to avoid conflicts with AppDynamic: First line should be 50 characters or less (saw 53)
**
**************************************************

Could you please fix it? Suggested first line: Support middleware injected by AppDynamics

@bajtos bajtos added the feature label Jan 25, 2019
AppDynamics injects a proxy object into the router stack, which it
uses for its network analysis.  This is similar to how NewRelic
adds a sentinel handler to the router stack. This commit adds a
similar workaround so that loopback can find the original layer.
@mschnee mschnee force-pushed the studykik:fix/appdynamics-proxy branch from ec10b2d to edb8dbc Jan 25, 2019
@mschnee

This comment has been minimized.

Copy link
Author

commented Jan 25, 2019

Commit ammended. I'm attempting to reach out to @mikewli

@bajtos bajtos changed the title Add a workaround to avoid conflicts with AppDynamics Support middleware injected by AppDynamics Jan 28, 2019
@mikewli
mikewli approved these changes Feb 2, 2019
@mikewli

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2019

Approved, thanks for the update!

@bajtos bajtos merged commit c38900b into strongloop:master Feb 5, 2019
7 checks passed
7 checks passed
Commit Linter commits are all properly formatted
Details
PR Linter PR is up to date
Details
clahub All contributors have signed the Contributor License Agreement.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.008%) to 90.258%
Details
security/snyk - package.json (StrongLoop) No new issues
Details
security/snyk - package.json (dhmlau) No new issues
Details
@bajtos

This comment has been minimized.

Copy link
Member

commented Feb 5, 2019

Landed, thank you @mschnee & @mikewli for the contribution ❤️

@bajtos

This comment has been minimized.

Copy link
Member

commented Feb 5, 2019

Published in loopback@3.25.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.