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
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Note for the softlayer status checks: I do not have permission to grant access to the private repository into which |
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/server-app.js
Outdated
@@ -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 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+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 {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks mostly good, thank you for the contribution ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@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 |
55c97e8
to
c29bad3
Compare
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:
Could you please fix it? Suggested first line: Support middleware injected by AppDynamics |
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.
ec10b2d
to
edb8dbc
Compare
Commit ammended. I'm attempting to reach out to @mikewli |
Approved, thanks for the update! |
Published in |
Description
Much like the workaround for
NewRelic
,appd
replaces the express handle with its own, and stores it inhandle.__appdynamicsProxyInfo__.orig
. This causesproto._findLayerByHandler
to fail.This pull request was originally created by @mikewli and @gconaty - I have updated it to include unit tests.
Checklist