Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Backport crossdock fixes #7

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Build directory
# Build files
/build
/crossdock/crossdock
/crossdock/jaeger-docker-compose.yml

Choose a reason for hiding this comment

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

this a temporary thing? don't think we should be ignoring this completely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

crossdock/crossdock is the executable binary itself. Actually changed this in my recent crossdock development. The jaeger-docker-compose.yml is a downloaded file to launch the other jaeger clients.


# vim swap files
*.swo
Expand Down Expand Up @@ -37,3 +39,6 @@
*.exe
*.out
*.app

# Log files
*.log
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchain.cmake")

set(HUNTER_CACHE_SERVERS "https://github.com/isaachier/cpp-client-hunter-cache")

include(CMakeDependentOption)
include(HunterGate)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.141.tar.gz"
Expand Down Expand Up @@ -39,7 +40,7 @@ if(HUNTER_ENABLED)
endif()
endif()

project(jaegertracing VERSION 0.0.5)
project(jaegertracing VERSION 0.0.8)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down Expand Up @@ -88,9 +89,12 @@ find_package(OpenTracing CONFIG REQUIRED)
list(APPEND LIBS OpenTracing::opentracing-static)
list(APPEND package_deps opentracing-cpp)

option(JAEGERTRACING_WITH_YAML_CPP "Use yaml-cpp to parse config files" ON)
option(JAEGERTRACING_COVERAGE "Build with coverage" $ENV{COVERAGE})
option(JAEGERTRACING_BUILD_EXAMPLES "Build examples" ON)
option(JAEGERTRACING_BUILD_CROSSDOCK "Build crossdock" OFF)
cmake_dependent_option(
JAEGERTRACING_WITH_YAML_CPP "Use yaml-cpp to parse config files" ON
"NOT JAEGERTRACING_BUILD_CROSSDOCK" ON)

if(JAEGERTRACING_WITH_YAML_CPP)
hunter_add_package(yaml-cpp)
Expand Down Expand Up @@ -134,6 +138,14 @@ if(JAEGERTRACING_BUILD_EXAMPLES)
endforeach()
endif()

if(JAEGERTRACING_BUILD_CROSSDOCK)
set(CROSSDOCK_SRC crossdock/Server.cpp)
add_executable(crossdock ${CROSSDOCK_SRC})
target_include_directories(crossdock PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/crossdock>)
target_link_libraries(crossdock PUBLIC jaegertracing-static)
endif()

set(SRC
src/jaegertracing/Config.cpp
src/jaegertracing/LogRecord.cpp
Expand Down
65 changes: 5 additions & 60 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ include(CMakeParseArguments)
find_program( GCOV_PATH gcov )
find_program( LCOV_PATH lcov )
find_program( GENHTML_PATH genhtml )
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
find_program( SIMPLE_PYTHON_EXECUTABLE python )

if(NOT GCOV_PATH)
Expand Down Expand Up @@ -128,13 +127,12 @@ endif()
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# SETUP_TARGET_FOR_COVERAGE(
# setup_target_for_coverage(
# NAME testrunner_coverage # New target name
# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
# DEPENDENCIES testrunner # Dependencies to build first
# )
function(SETUP_TARGET_FOR_COVERAGE)

function(setup_target_for_coverage)
set(options NONE)
set(oneValueArgs NAME)
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
Expand Down Expand Up @@ -174,63 +172,10 @@ function(SETUP_TARGET_FOR_COVERAGE)
COMMAND ;
COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
)
endfunction() # setup_target_for_coverage

endfunction() # SETUP_TARGET_FOR_COVERAGE

# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# SETUP_TARGET_FOR_COVERAGE_COBERTURA(
# NAME ctest_coverage # New target name
# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
# DEPENDENCIES executable_target # Dependencies to build first
# )
function(SETUP_TARGET_FOR_COVERAGE_COBERTURA)

set(options NONE)
set(oneValueArgs NAME)
set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT SIMPLE_PYTHON_EXECUTABLE)
message(FATAL_ERROR "python not found! Aborting...")
endif() # NOT SIMPLE_PYTHON_EXECUTABLE

if(NOT GCOVR_PATH)
message(FATAL_ERROR "gcovr not found! Aborting...")
endif() # NOT GCOVR_PATH

# Combine excludes to several -e arguments
set(COBERTURA_EXCLUDES "")
foreach(EXCLUDE ${COVERAGE_EXCLUDES})
set(COBERTURA_EXCLUDES "-e ${EXCLUDE} ${COBERTURA_EXCLUDES}")
endforeach()

add_custom_target(${Coverage_NAME}

# Run tests
${Coverage_EXECUTABLE}

# Running gcovr
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} ${COBERTURA_EXCLUDES}
-o ${Coverage_NAME}.xml
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS ${Coverage_DEPENDENCIES}
COMMENT "Running gcovr to produce Cobertura code coverage report."
)

# Show info where to find the report
add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
COMMAND ;
COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
)

endfunction() # SETUP_TARGET_FOR_COVERAGE_COBERTURA

function(APPEND_COVERAGE_COMPILER_FLAGS)
function(append_coverage_compiler_flags)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
endfunction() # APPEND_COVERAGE_COMPILER_FLAGS
endfunction() # append_coverage_compiler_flags
41 changes: 20 additions & 21 deletions examples/hotrod/CustomerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class Database {
Database(opentracing::Tracer& tracer, logging::Logger& logger)
: _tracer(tracer)
, _logger(logger)
, _customers({
{"123", Customer("123", "Rachel's Floral Designs", "115,227")},
{"567", Customer("567", "Amazing Coffee Roasters", "211,653")},
{"392", Customer("392", "Trom Chocolatier", "577,322")},
{"731", Customer("731", "Japanese Deserts", "728,326")}
})
, _customers(
{ { "123",
Customer("123", "Rachel's Floral Designs", "115,227") },
{ "567",
Customer("567", "Amazing Coffee Roasters", "211,653") },
{ "392", Customer("392", "Trom Chocolatier", "577,322") },
{ "731", Customer("731", "Japanese Deserts", "728,326") } })
{
}

Expand All @@ -58,8 +59,7 @@ class Database {
options.start_system_timestamp = std::chrono::system_clock::now();
options.start_steady_timestamp = std::chrono::steady_clock::now();
options.references.emplace_back(
opentracing::SpanReferenceType::ChildOfRef,
&parentSpan.context());
opentracing::SpanReferenceType::ChildOfRef, &parentSpan.context());

auto span = _tracer.StartSpanWithOptions("SQL SELECT", options);
const auto query =
Expand Down Expand Up @@ -87,15 +87,15 @@ class CustomerServiceImpl : public CustomerService {
public:
CustomerServiceImpl()
: _logger(logging::consoleLogger())
, _tracer(Tracer::make(
"customer",
Config(false,
samplers::Config("const", 1),
reporters::Config(
reporters::Config::kDefaultQueueSize,
reporters::Config::defaultBufferFlushInterval(),
true)),
_logger))
, _tracer(Tracer::make(
"customer",
Config(false,
samplers::Config("const", 1),
reporters::Config(
reporters::Config::kDefaultQueueSize,
reporters::Config::defaultBufferFlushInterval(),
true)),
_logger))
, _database(*_tracer, *_logger)
{
}
Expand Down Expand Up @@ -158,10 +158,9 @@ int main(int argc, const char* argv[])
}

std::ostringstream oss;
oss << "{ \"ID\": \"" << customer.id() << '"'
<< ", \"name\": \"" << customer.name() << '"'
<< ", \"location\": \"" << customer.location() << '"'
<< " }";
oss << "{ \"ID\": \"" << customer.id() << '"' << ", \"name\": \""
<< customer.name() << '"' << ", \"location\": \""
<< customer.location() << '"' << " }";
const auto jsonData = oss.str();
oss.clear();
oss.str("");
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void sleep(const Clock::duration& average,
using FractionalSecond = std::chrono::duration<double>;
std::normal_distribution<> distribution(
std::chrono::duration_cast<FractionalSecond>(average).count(),
std::chrono::duration_cast<FractionalSecond>(
standardDeviation).count());
std::chrono::duration_cast<FractionalSecond>(standardDeviation)
.count());
FractionalSecond secondsToSleep;
{
std::lock_guard<std::mutex> lock(mutex);
Expand Down
85 changes: 39 additions & 46 deletions examples/hotrod/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ namespace examples {
namespace hotrod {
namespace {

auto defaultHandler =
[](net::Socket&& socket, const net::http::Request& /* request */) {
const std::string message =
"HTTP/1.1 404 Not found\r\n";
const auto numWritten =
::write(socket.handle(), &message[0], message.size());
if (numWritten < static_cast<int>(message.size())) {
std::cerr
<< "Failed to write entire response to client"
", message=" << message << '\n';
}
};
auto defaultHandler = [](net::Socket&& socket,
const net::http::Request& /* request */) {
const std::string message = "HTTP/1.1 404 Not found\r\n";
const auto numWritten =
::write(socket.handle(), &message[0], message.size());
if (numWritten < static_cast<int>(message.size())) {
std::cerr << "Failed to write entire response to client"
", message="
<< message << '\n';
}
};

} // anonymous namespace

Expand Down Expand Up @@ -65,8 +64,7 @@ void HTTPServer::start()
constexpr auto kBufferSize = 256;
std::string buffer(kBufferSize, '\0');
std::string requestStr;
auto numRead =
::read(clientSocket.handle(), &buffer[0], buffer.size());
auto numRead = ::read(clientSocket.handle(), &buffer[0], buffer.size());
while (numRead == static_cast<int>(buffer.size())) {
requestStr.append(&buffer[0], numRead);
numRead = ::read(clientSocket.handle(), &buffer[0], buffer.size());
Expand All @@ -75,50 +73,45 @@ void HTTPServer::start()
std::istringstream iss(requestStr);
try {
const auto request = net::http::Request::parse(iss);
auto itr =
std::find_if(std::begin(_handlers),
std::end(_handlers),
[&request](const HandlerVec::value_type& pair) {
return std::regex_search(request.target(),
pair.first);
});

Handler handler = ((itr == std::end(_handlers)) ? defaultHandler
: itr->second);

std::packaged_task<void(net::Socket&&,
const net::http::Request&)> task(
handler);
auto itr = std::find_if(
std::begin(_handlers),
std::end(_handlers),
[&request](const HandlerVec::value_type& pair) {
return std::regex_search(request.target(), pair.first);
});

Handler handler =
((itr == std::end(_handlers)) ? defaultHandler : itr->second);

std::packaged_task<void(net::Socket&&, const net::http::Request&)>
task(handler);
_tasks.push_back(task.get_future());
task(std::move(clientSocket), request);
} catch (...) {
auto logger = logging::consoleLogger();
utils::ErrorUtil::logError(*logger, "Error parsing request");
}

_tasks.erase(
std::remove_if(std::begin(_tasks),
std::end(_tasks),
[](const TaskList::value_type& task) {
return task.valid();
}),
std::end(_tasks));
_tasks.erase(std::remove_if(std::begin(_tasks),
std::end(_tasks),
[](const TaskList::value_type& task) {
return task.valid();
}),
std::end(_tasks));
}
}

void HTTPServer::close() noexcept
{
std::for_each(std::begin(_tasks),
std::end(_tasks),
[](TaskList::value_type& task) {
try {
task.get();
} catch (...) {
auto logger = logging::consoleLogger();
utils::ErrorUtil::logError(
*logger, "Error finishing task");
}
});
std::for_each(
std::begin(_tasks), std::end(_tasks), [](TaskList::value_type& task) {
try {
task.get();
} catch (...) {
auto logger = logging::consoleLogger();
utils::ErrorUtil::logError(*logger, "Error finishing task");
}
});
_socket.close();
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function main() {
cd "$project_dir" || exit 1

local srcs
srcs=$(git ls-files src | grep -E -v 'thrift-gen' | grep -E '\.(cpp|h)$')
srcs=$(git ls-files src crossdock examples |
grep -E -v 'thrift-gen' |
grep -E '\.(cpp|h)$')

local cmd
for src in $srcs; do
Expand Down
2 changes: 1 addition & 1 deletion scripts/clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function main() {
cd "$project_dir" || exit 1

local srcs
srcs=$(git ls-files src |
srcs=$(git ls-files src crossdock examples |
grep -E -v 'thrift-gen|Test\.cpp' |
grep -E '\.cpp$')

Expand Down
5 changes: 4 additions & 1 deletion scripts/update-licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

set -e

python scripts/update-license.py $(git ls-files "*\.cpp" "*\.h" | grep -v thrift-gen | grep -v tracetest) src/jaegertracing/Constants.h.in
python scripts/update-license.py $(git ls-files "*\.cpp" "*\.h" |
grep -v thrift-gen |
grep -v tracetest) \
src/jaegertracing/Constants.h.in
Loading