-
Notifications
You must be signed in to change notification settings - Fork 138
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 TCP support #79
Add TCP support #79
Conversation
Thanks for this, great to see! A few things:
|
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 have just a few nitpicks, but I didn't find anything obvious to cause problems in the test. I'll spend some time playing with it locally and let's see.
- As mentioned, there is a conflict needed to be resolved.
- I agree with @bdeitte we should think about the duplication of tests, but I suggest we first get them passing this way, isolated and separated. I believe debugging problems in the initial TCP implementation while having the tests tangled together with the UPC implementation could be quite hard. Maybe we could make the tests more DRY as a next step when everything is passing?
lib/statsd.js
Outdated
}; | ||
} | ||
|
||
function createSocket(args) { |
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 use options
instead of args
, but both are saying nothing about the contents, so it's just a convention nitpick.
lib/statsd.js
Outdated
@@ -91,6 +102,10 @@ var Client = function (host, port, prefix, suffix, globalize, cacheDns, mock, | |||
global.statsd = this; | |||
} | |||
|
|||
if (options.protocol === 'tcp') { | |||
this.socket.setKeepAlive(true); | |||
} |
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.
Shouldn't this be a part of the createSocket
"method"?
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.
Addressed in 69de8cb.
Also, would you mind removing the |
When running locally on Node 8, I'm getting following failures randomly (flakily) even when I keep the
Also
They occur especially when running the whole test suite repeatedly. Looks like there is a flawed tear down somewhere. |
The conflict was probably caused by Regarding tests:
@bdeitte In |
I suspect that as well. We should hunt those down. Do you experience similar flakiness locally or is it just me? |
@honzajavorek I do. I am not sure it will be possible without the rewrite 😞 |
My hunch is the |
@honzajavorek Changes made in b571d8c ensure that the tests pass/fail consistently now. The solution is not ideal, but at least we can now focus on making them pass. |
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.
Running npm test
on top of the branch fails due to some linter errors. I marked them with comments.
test/test_statsd_tcp.js
Outdated
metrics.forEach(function (metric) { | ||
test(metric, server); | ||
}); | ||
var metrics = parts.filter(part => part !== ''); |
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.
test/test_statsd_tcp.js: line 37, col 41, 'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').
test/test_statsd_tcp.js
Outdated
protocol: 'tcp' | ||
}); | ||
assert.ok(statsd.socket instanceof net.Socket); | ||
done(); |
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.
test/test_statsd_tcp.js: line 72, col 9, 'done' is not defined.
BTW I can still see
I'll try to help with debugging this. Maybe I can figure something out. @bdeitte if you don't have any immediate ideas on what could be wrong with either the TCP implementation or the tests, then feel free to ignore it here until we get the thing passing. And sorry for the noise. |
@bdeitte The build is green now, could you please take another look? Thank you. |
@michalholasek Thanks for getting the tests working and doing all this work. Unfortunately I still have the same feeling I have before- the duplication of tests in the way they are isn't something I am comfortable with. The tests are already drifting apart from what I see, and this is only going to increase without careful diligence over time. There needs to be something done to get them closer in line, even if it's not exactly right. I know that you mention this could be done in a followup PR, but that is not a great place for this codebase to be in. If you need to have this right away and can't make those changes, I would suggest using your branch for now until that can be done. (Although I hope you will make them now, would be great to have this in!) I thought about this some more, to try to think of something that isn't too painful to do but which gets more at what I'm worried about here. Here's my suggestion: https://gist.github.com/bdeitte/4ae7fd92edb490e2adcd22e38d62a5a6 What I did in the above is take your new tests, rip out everything other than globalTags tests, and then try to add in the UDP tests. I ran this in your branch and it passes there. If you want to try to add this way of doing things, here's you would need to do:
In the future, it would be good to split these tests into multiple files (while still keeping UDP/TCP tests for related functionality together) as this file is really big. It'd also probably be good to think more about ways to shorten some of the boilerplate in the tests. But I started to think about that and realized it's not what I'm asking here and definitely don't want to make this something more than it is, which is just a request to have similar tests live by each other for easier maintenance. Thanks! |
lib/statsd.js
Outdated
|
||
if (this.protocol === 'tcp') { | ||
message += '\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.
I think this should be in the sendMessage
method as that one deals with the quirks of the individual transmission protocols. This is an implementation details of sending the message over TCP and IMHO should be encapsulated by sendMessage
.
lib/statsd.js
Outdated
// hidden global_tags option for backwards compatibility | ||
options.globalTags = options.globalTags || options.global_tags; | ||
|
||
this.protocol = options.protocol; |
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.
Nitpick: Although it's against various code styles, I'd stick to the code style already in place and add the alignment whitespaces:
- this.protocol = options.protocol;
+ this.protocol = options.protocol;
Just for the record, once this is done, it closes #76 (I miss the connection when browsing the issues/PRs here 😄 ) |
@bdeitte Test refactor is finished now, PR is ready for re-review:
|
lib/statsd.js
Outdated
} | ||
|
||
return socket; | ||
}.bind(this); |
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.
Doing it this way means we have two ways to have functions in here. Could you make this like the existing "_send" method? Alternatively, if you feel strongly about it, it's not that I'm a big fan of "_send"- you could also make that method like this 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.
I added the bind
to appease jshint
, which is not good enough reason, I agree. I changed the createSocket
function signature to accept instance argument instead (dee23b3).
@@ -42,26 +43,55 @@ var Client = function (host, port, prefix, suffix, globalize, cacheDns, mock, | |||
maxBufferSize : maxBufferSize, | |||
bufferFlushInterval: bufferFlushInterval, | |||
telegraf : telegraf, | |||
sampleRate : sampleRate | |||
sampleRate : sampleRate, | |||
protocol : protocol | |||
}; | |||
} |
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.
Someone is going to do "TCP" at some point and get confused. How about adding:
if (options.protocol) {
options.protocol = options.toLowerCase();
}
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.
Addressed in fe2d446.
package.json
Outdated
"test": "mocha -R spec", | ||
"lint": "jshint lib/**.js test/**.js", | ||
"test": "mocha -R spec --timeout 5000 test/index.js", | ||
"lint": "jshint lib/**.js", |
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.
Why not lint the tests anymore? If you had an issue, can we just exclude that with a jshint ignore comment?
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.
Addressed in 34215ff.
|
||
var createStatsdClient = require('./helpers').createStatsdClient; | ||
var createTCPServer = require('./helpers').createTCPServer; | ||
var createUDPServer = require('./helpers').createUDPServer; |
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.
These tests and the abstractions in them look great- thanks!
Wow this is a lot of work, thank you! I reviewed everything and just had a few small comments. (I took awhile with the tests a bit earlier and think I reviewed it all but lots to cover.) . Once you can answer/fix the few comments, I can review/answer that and merge in with a minor release. I will still make it minor in this case for anyone curious- I have made a major before with major code changes, but the changes just look at statsd.js itself look small enough (and not backwards breaking of course) with whitespace ignored to be a minor release. |
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.
Looks good- merging and releasing.
Thanks @michalholasek for all the hard work you put into this! |
This PR builds upon @remie's great work at sivy/node-statsd#67, with couple shortcomings:
should properly send a and b with the same value
test cases (skipped withxit
). @bdeitte, could you please point me to correct direction to what is missing / wrong?/cc @honzajavorek