-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add HTTPS probes and tests #455
Conversation
Just investigating test failures on Node 8... |
Make sure you're not using 8.1.1 (and if you are look for nodejs/node#13667) |
Codecov Report
@@ Coverage Diff @@
## master #455 +/- ##
========================================
+ Coverage 57.97% 60% +2.02%
========================================
Files 44 49 +5
Lines 2967 3195 +228
========================================
+ Hits 1720 1917 +197
- Misses 1247 1278 +31
Continue to review full report at Codecov.
|
Test failure was just a timing issue, the test was closing the server after sending requests but before they had reached it. Now fixed. |
Updated to comply with eslint #274 |
probes/https-outbound-probe.js
Outdated
|
||
HttpsOutboundProbe.prototype.attach = function(name, target) { | ||
var that = this; | ||
if (name == 'https') { |
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.
===
?
probes/https-outbound-probe.js
Outdated
var requestMethod = 'GET'; | ||
var urlRequested = ''; | ||
var headers = ''; | ||
if (typeof options === 'object') { |
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.
if (options !== null && typeof options === 'object') {
?
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.
Just googled this - I didn't realise typeof null was 'object'...
probes/https-outbound-probe.js
Outdated
var requestMethod = 'GET'; | ||
var urlRequested = ''; | ||
var headers = ''; | ||
if (typeof options === 'object') { |
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.
Likewise.
} | ||
} else if (typeof options === 'string') { | ||
urlRequested = options; | ||
var parsedOptions = url.parse(options); |
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.
Callling url.parse()
before and after is arguably a little wasteful, it's not cheap.
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'll look into this. Metrics mode definitely doesn't need it but requests seem to need a name. We might be able to put a dummy name in though.
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 rewrote this bit in both http-outbound-probe and https-outbound-probe. They're both now only calling url.parse()
on metrics end.
url += '/'; | ||
} | ||
return url; | ||
} |
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.
How does this differ from url.format()
?
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.
It strips off trailing ? or # components, which we don't use.
|
||
function isNumeric(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} |
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.
Seemingly unused functions.
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.
used on line 47
tap.tearDown(function() { | ||
setTimeout(function() { | ||
server.close(); | ||
}, 1000); |
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.
Is there a reason for this timeout? The next test doesn't have one.
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.
Yes, the test was crashing because the server was being closed after the http outbound call was made but before it was received by the server, so this gives the server time to receive the call. The other test tests incoming https calls so by definition doesn't close the server until the calls have got there.
|
||
function isNumeric(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} |
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.
Unused functions.
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.
lines 66, 70, 82
tests/test_https_server.js
Outdated
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
console.log('dirname = ' + __dirname); |
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.
What is this used for?
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.
Debug, left in by mistake, will remove
probes/https-outbound-probe.js
Outdated
|
||
var methods; | ||
if (semver.lt(process.version, '8.0.0')) { | ||
methods = ['request']; |
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.
https.get()
exists in older versions. Is there a reason for the conditional?
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.
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'd perhaps add an explaining comment, it's not clear from context why node 8 is special.
@bnoordhuis thanks for the comments, I've fixed or replied to all of them, just one that I need to look into further. |
probes/https-outbound-probe.js
Outdated
var util = require('util'); | ||
var url = require('url'); | ||
var am = require('../'); | ||
var semver = require('semver'); |
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 prefer requires to be sorted alphabetically (by line) rather being in some random order.
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.
(but don't know if that's part of the appmetrics coding style)
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.
Personally I like to group related requires together, e.g. all local requires together and any chained requires together. Then alphabetical after that. This is not my ordering though (copied) so I will improve it a bit so that it looks less random.
We don't really have a coding style beyond what eslint does and some naming/case stuff. I wouldn't like to enforce something like alphabetical ordering with eslint or otherwise because ordering can change behaviour, e.g. appmetrics itself usually needs to be required first.
'use strict'; | ||
|
||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
var appmetrics = (appmetrics = require('../../')); |
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 don't understand this line, I thought maybe you were trying to set global.appmetrics
as well as the module-scope appmetrics
, but that isn't how it works. Typo?
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.
Yes, this confused me too but looking at the history there was an extra appmetrics =
in the original commit and I think eslint-fix or prettify must have added the brackets.
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.
now fixed
}; | ||
|
||
// Request with a callback | ||
https.get('https://localhost:8000/', function(res) {}); |
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.
maybe assert the callback is called?
}, 1000); | ||
}); | ||
|
||
var completedTests = 0; |
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.
you don't need this, if you get more (or less) than 3 https-outbound events, then there is a bug.
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.
removed
tests/probes/https-probe-test.js
Outdated
'use strict'; | ||
|
||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
var appmetrics = (appmetrics = require('../../')); |
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.
it this test is the same as http (and it seems it is), it can be factored into a utility function, and just called with httpTest(require('https'))
(or http
). Besides eliminating cut-n-paste, it makes it clear that the behaviour of the probes should be identical. EDIT: and if they ever are not identical, the test will fail.
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.
You'd also have to pass the event and monitor names ('https-outbound' vs 'http-outbound'), the rest looks the same.
@sjanuary Looks like a lot of codebeat issues have been introduced with this request. Could you take a look please, thanks |
@tobespc I don't really rate codebeat tbh, I'm not sure why we're using it. The 'issues' are things like 'function too long', 'similar code in 2 places', 'too many function arguments', 'block nesting too deep'. There are a lot introduced because there's a lot of new code here and some of it is similar to existing code, but some are not fixable because of how the probes framework work and others are not fixable for other reasons. I've looked through the codebeat report and there's nothing I really want to change - are there any specific issues that you would like to be addressed? |
accepting pull request whilst we look at the wider issue of codebeat and its findings |
Tremendous work! Any idea when the next version will be released that includes this https stuff? |
Fixes #409