-
Notifications
You must be signed in to change notification settings - Fork 67
Conversation
Added TCP protocol parameter switch. Name refactoring.
Thanks for the PR Petar! A few concerns:
The management of a TCP connection is why I was hesitant to add this functionality in the first place. I can't see a full handshake being done before each send request since it's all blocking and would kill the calling app. It's all fully possible of course, just more than I wanted to add for something I still don't see a huge amount of benefit from :) |
Hi Darrell, I would like to address all your concerns.
|
I have successfully run all the tests after poking around and finding out that NUnit 2.6 is being used. KR |
Changed to implementation towards the Interface. Added StatsdTCP concrete class. Reverted StatsdUDP to original state.
After finding out that there is App.confing in Tests I have created Hyper-V and configured InfluxDB with Chronograph and Telegraph to have valid Smoke tests. (See picture below) TCP Smoke test is passing. I have changed to the implementation towards the interface over concrete type. Also, I'm not done yet. Thinking about doing it with async methods. @DarrellMozingo that should address your concern on blocking the calling app. Right? |
Thanks for fixing the .NET version and splitting out the TCP/UDP classes - nice touch. I see you're doing the connect/disconnect now. I think that should be in a try/finally so ensure the connection is closed if something goes wrong in the send (I'll add an in-line comment). Also a base class (or a separate class) to handle the IP address resolution as it's a bit convoluted? I've personally always been against doing the TCP for socket management and the speed hit of doing a sync call. If it's an absolute requirement, I feel it's better to split that responsibility out to another app (ie have a statsd relay running on each server that you'd send UDP stats to, and it would relay them in TCP). Do you still think the feature is needed if someone does this? Thanks again for taking the time to contribute, I do appreciate it! :) |
{ | ||
_clientSocket.Connect(IPEndpoint.Address, _port); | ||
_clientSocket.SendTo(encodedCommand, encodedCommand.Length, SocketFlags.None, IPEndpoint); | ||
_clientSocket.Disconnect(false); |
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.
Put this in a try {} finally {}
so we're not leaving hanging TCP connections?
@DarrellMozingo no problem I really want to contribute. My position is that you should have a choice between UDP and TCP. Today I will work on this part from documentation.
Using BeginSend and EndSend would be much better. On the topic of IP address resolution, that should definitely be pulled out (separation of concern). I really appreciate you taking time to look at my messy code :) |
Pulled out shared interface into separate file. Pulled out address resolution.
{ | ||
_clientSocket.Connect(IPEndpoint); | ||
_clientSocket.SendTo(encodedCommand, encodedCommand.Length, SocketFlags.None, IPEndpoint); | ||
_clientSocket.Disconnect(false); |
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 Disconnect()
should be in the finally
block, no?
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,
still working on this part to make it Async. :)
I'm still hesitant to add it, but I suppose the TCP code will be insulated in a separate class and not defaulted or anything, so we can allow it with perhaps appropriate warnings (ie to use UDP or a TCP relay app first). Thanks for the fixes so far! I'll be away for a few days, so if you get anything else done I'll take a look next week. |
I haven't had time over the weekend. |
It's being used only inside Address class
} | ||
finally | ||
{ | ||
_clientSocket.Disconnect(false); |
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 Disconnect() in favor of Shutdown() and Close()
@DarrellMozingo I think I'm done. \o/ |
Nice work! I know Also can you rename the TCP smoke test to match the class/other UDP one? |
I have implemented IDisposable interface, and renamed filenames to reflect classnames. Is there some convention I'm not being aware of? also, I'm logging to console? |
Yea, saw you implmented Ignore my smoke test naming comment. I misread something and thought the UDP test was named differently. It's fine as is. Swallowing seems wrong. I think something like TraceSource (built into .NET) or LibLog would be best, but we're not doing either now and there hasn't been a need yet. The console log seems good enough for now anyway :) |
The build for this branch is broken. Not sure why the PR didn't update (I just enabled it, maybe I did it wrong!). Looks like the project file still has |
well, thinking is that if you close the outside connection (finally block), you shouldn't worry about dispose. Or if you are doing something like this:
Dispose will be properly called. Yes, I changed the names; Didn't know what you were referencing on SmokeTest I can change it back? |
Yes, you are right... I will fix it now :) |
Regarding disposable, you're absolutely correct. No body is doing a |
I changed the filenames, but forgot to push changed .csproj
Here is what happened. Please check if it's passing now (It should). https://ci.appveyor.com/project/DarrellMozingo/statsd-csharp-client EDIT: |
Yes, TCP smoke test will fail. I should change the smoke test to use TcpListener |
https://ci.appveyor.com/project/DarrellMozingo/statsd-csharp-client/build/tests What should we do with TCP SmokeTest? |
I like the idea of the smoke test spinning up a simple TcpListener to receive the connection. As a bonus it can read the data and make sure it's correct :) |
I was under Impression that Smoke test should be done on 'real' thing :) That's why I did all this EDIT: |
You're correct, it should be hitting the real system. From the point of view of the client though I can see just making sure it's sending a properly formed TCP packet, rather than a full end-to-end test that makes sure it shows up in the back-end correctly. So just spinning up a TCP socket to send to should work well enough for our purposes. |
It should now pass the CI build on AppVeyor
@DarrellMozingo 1.2.40 built successfully https://ci.appveyor.com/project/DarrellMozingo/statsd-csharp-client/build/1.2.40 We should probably update the readme.md 👍 |
System.Net.IPAddress localAddr = System.Net.IPAddress.Parse(_serverName); | ||
|
||
// TcpListener server = new TcpListener(port); | ||
server = new TcpListener(localAddr, port); |
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.
Can you wrap this in a using{}
to make sure it's always stopped?
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.
TcpListener class doesn't inherit/implement IDisposable Interface.
For that reason It's can't be wrapped in using()
If you try you get Type used in a using statement must be implicitly convertible to 'System.IDisposable'
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.
Quite right :) I was thinking of TcpClient
, sorry. Maybe just put the Stop()
in a finally block, or probably a test teardown fixture would be better. Just want to make sure if the test fails that listening socket gets closed.
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 went with setup/teardown fixture :)
Looks good, thanks! Want to take a stab at updating the README? |
Sure, I would love to :) |
@DarrellMozingo readme is updated :) The changelog is left up to you 👍 |
Great, thanks a lot for the contribution Petar! I'll get it pushed out today or tomorrow. |
No hurry :) I'm here if additional tweaks are needed. |
Added TCP protocol parameter switch.
Name refactoring.