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

Add HTTPS probes and tests #455

Merged
merged 6 commits into from
Jul 19, 2017
Merged

Add HTTPS probes and tests #455

merged 6 commits into from
Jul 19, 2017

Conversation

sjanuary
Copy link
Contributor

Fixes #409

@sjanuary
Copy link
Contributor Author

Just investigating test failures on Node 8...

@gibfahn
Copy link
Contributor

gibfahn commented Jun 15, 2017

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-io
Copy link

codecov-io commented Jun 15, 2017

Codecov Report

Merging #455 into master will increase coverage by 2.02%.
The diff coverage is 86.2%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
tests/probes/https-outbound-probe-test.js 100% <100%> (ø)
tests/probes/https-probe-test.js 100% <100%> (ø)
tests/probes/http-outbound-probe-test.js 100% <100%> (ø) ⬆️
tests/test_https_server.js 100% <100%> (ø)
tests/probes/http-probe-test.js 67.39% <100%> (ø) ⬆️
probes/http-probe.js 79.03% <100%> (-0.34%) ⬇️
probes/http-outbound-probe.js 82.41% <68.18%> (-4.54%) ⬇️
probes/https-probe.js 79.03% <79.03%> (ø)
probes/https-outbound-probe.js 81.81% <81.81%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68ff88b...a1b521d. Read the comment docs.

@sjanuary
Copy link
Contributor Author

Test failure was just a timing issue, the test was closing the server after sending requests but before they had reached it. Now fixed.

@sjanuary
Copy link
Contributor Author

Updated to comply with eslint #274


HttpsOutboundProbe.prototype.attach = function(name, target) {
var that = this;
if (name == 'https') {
Copy link
Contributor

Choose a reason for hiding this comment

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

===?

var requestMethod = 'GET';
var urlRequested = '';
var headers = '';
if (typeof options === 'object') {
Copy link
Contributor

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') {?

Copy link
Contributor Author

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'...

var requestMethod = 'GET';
var urlRequested = '';
var headers = '';
if (typeof options === 'object') {
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
}
Copy link
Contributor

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()?

Copy link
Contributor Author

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Seemingly unused functions.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lines 66, 70, 82

var fs = require('fs');
var path = require('path');

console.log('dirname = ' + __dirname);
Copy link
Contributor

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?

Copy link
Contributor Author

@sjanuary sjanuary Jun 22, 2017

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


var methods;
if (semver.lt(process.version, '8.0.0')) {
methods = ['request'];
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

@sjanuary
Copy link
Contributor Author

@bnoordhuis thanks for the comments, I've fixed or replied to all of them, just one that I need to look into further.

var util = require('util');
var url = require('url');
var am = require('../');
var semver = require('semver');
Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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('../../'));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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) {});
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

'use strict';

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var appmetrics = (appmetrics = require('../../'));
Copy link
Contributor

@sam-github sam-github Jun 22, 2017

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.

Copy link
Contributor

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.

@tobespc
Copy link
Member

tobespc commented Jul 19, 2017

@sjanuary Looks like a lot of codebeat issues have been introduced with this request. Could you take a look please, thanks

@sjanuary
Copy link
Contributor Author

@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?

@tobespc tobespc merged commit 5e72dc8 into RuntimeTools:master Jul 19, 2017
@tobespc
Copy link
Member

tobespc commented Jul 19, 2017

accepting pull request whilst we look at the wider issue of codebeat and its findings

@anthonywebb
Copy link

Tremendous work! Any idea when the next version will be released that includes this https stuff?

@sjanuary sjanuary added this to the 3.1 milestone Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants