-
Notifications
You must be signed in to change notification settings - Fork 402
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
[WIP] Implementation of test socket server for tcp, udp, unix #722
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maxgolov
changed the title
Initial implementation of test server for sockets (tcp, udp, unix)
Implementation of test socket server for tcp, udp, unix
May 4, 2021
…olently redefining sockaddr_un
maxgolov
changed the title
Implementation of test socket server for tcp, udp, unix
[WIP] Implementation of test socket server for tcp, udp, unix
May 4, 2021
…y-cpp into maxgolov/socket_tests
…etry/opentelemetry-cpp into maxgolov/socket_tests
…urce dir OPENTELEMETRY_SOURCE_DIR
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is incremental addition on top of zPages HTTP / HTTP Test Server code that I originally contributed last year.
Since HTTP server already had an abstract Reactor class for handling
TCP
connections usingaccept
/listen
(WSA, kqueue, epoll), - I would like to incrementally addUDP
andUnix Domain
sockets support to it.Unix Domain
stream is nearly identical toTCP
, whereasUDP
pretty much uses a tight-loop to receive - with receiver potentially implementing a thread-pool to swap and handle the data. There are no changes anticipated to any of OpenTelemetry API or SDK code. Only additional test components for future use and reuse.What is the main motivation for this
test framework
addition?We do not presently have any existing reliable way to inspect, packet level-inspect, E2E test payload for validity. This is quite limiting. Now I'm working on
fluentd
exporter in contrib repo - and it would be great to get the new exporter tested properly. As infunctional-tested
, against a local in-proc TCP, UDP and Unix Domain server running as part of our testsuit, in the same test process - to avoid spinning and configuring other processes or external containers of any kind. Basically letting plain CTest do its test job in one single run, with all E2E test code confined to C++.I think this test framework contribution is generic enough , as it may be reused for any other 3rd party exporter that relies on TCP, UDP or Unix Domain sockets. Since most code applies nicely on top of existing test classes, it would be impractical to move it or refactor it entirely to contrib. I would've gladly renamed the classes though, to move some from
http
tosockets
ornet
directory.Scenario 1
Debugging fluentd telemetry for validity:
MsgPack
format (can be decoded usingjson.hpp
)MsgPack
binary payloads).Scenario 2
Stress-test and compare TCP, UDP and Unix Domain encoder performance for fluent, e.g.
Now it can be done without actually installing fluent. Without needing a privileged agent running.. All from the same testsuit we already have. And we also already have HTTP server in, to validate the HTTP flow. What I'm now adding is the ability to inspect TCP, UDP and Unix Domain using about the same approach we used before for HTTP server validation.
Outcome
All code is (c) OpenTelemetry Authors - Apache License v2.0, header-only, cross-platform (Windows, Linux, Mac). It is not hard to find alternatives to what I did here.. But most of these alternatives would be not header only. And not Apache License v2.
List of Changes
macros.h
- handy macros for token pasting, lockguard, debug console logging to be used in test only.socket_server.h
- implementation of TCP, UDP and Unix Domain test server. Unix Domain actually works even on Windows 10 - latest.socket_tools.h
- basic header-only C++11 cross-plat abstraction layer for Windows and POSIX sockets.sockets_test.cc
- unit + functional test of the test framework itself.Other projects, e.g. opentelemetry-cpp-contrib, then may use the framework for their own E2E tests entirely written in C++, with no external test server needed.
Usage Example
Shown in
sockets_test.cc
- simple echo server :Subsequently, the server handler
server.onRequest
may be instrumented with a mock that validates all records emitted, measures timing, checks records contents for validity, etc.. I tried implementing the new class using OpenTelemetry coding style. However, I (mostly) preserved the coding style ofSocket client
to minimize the changes. I also added thread-safety to this new server, plus to the old reactor class.I can clean-up / refactor the old HTTP server code and the
Socket
class to better coding style separately, in a separate PR.