From ba0fa3fa6dbb01995d996f988a897e272100bf95 Mon Sep 17 00:00:00 2001 From: isaachier Date: Mon, 6 Aug 2018 12:28:02 -0400 Subject: [PATCH] Upgrade dynamic loading API (#120) * Update Hunter to latest release Signed-off-by: Isaac Hier * Fix library loading with help from mdouaihy Signed-off-by: Isaac Hier * Check ABI version in tracer factory Signed-off-by: Isaac Hier * Fix dynamic loading Signed-off-by: Isaac Hier * Fix dynamic loading Signed-off-by: Isaac Hier * Fix typo in disabled code Signed-off-by: Isaac Hier --- CMakeLists.txt | 11 +-- src/jaegertracing/DynamicLoad.cpp | 14 ++-- src/jaegertracing/DynamicLoadTest.cpp | 99 --------------------------- src/jaegertracing/TracerFactory.h | 1 + 4 files changed, 12 insertions(+), 113 deletions(-) delete mode 100644 src/jaegertracing/DynamicLoadTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5842113e..2378c29f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ set(HUNTER_CONFIGURATION_TYPES "Release;Debug" CACHE STRING include(CMakeDependentOption) include(HunterGate) HunterGate( - URL "https://github.com/ruslo/hunter/archive/v0.20.70.tar.gz" - SHA1 "95fb7d11f0828746e2983b5f06ff7981a676da3f" + URL "https://github.com/ruslo/hunter/archive/v0.23.5.tar.gz" + SHA1 "2c5c6fc1cf609d0856695d60f147594daf4e6b3e" ) project(jaegertracing VERSION 0.5.0) @@ -255,12 +255,8 @@ if(BUILD_TESTING) src/jaegertracing/testutils/TracerUtil.cpp) target_link_libraries(testutils PUBLIC ${JAEGERTRACING_LIB}) - if(BUILD_SHARED_LIBS) - set(dynamic_load_test_src src/jaegertracing/DynamicLoadTest.cpp) - endif() add_executable(UnitTest src/jaegertracing/ConfigTest.cpp - ${dynamic_load_test_src} src/jaegertracing/ReferenceTest.cpp src/jaegertracing/SpanContextTest.cpp src/jaegertracing/SpanTest.cpp @@ -286,9 +282,6 @@ if(BUILD_TESTING) src/jaegertracing/utils/ErrorUtilTest.cpp src/jaegertracing/utils/RateLimiterTest.cpp src/jaegertracing/utils/UDPClientTest.cpp) - target_compile_definitions(UnitTest PUBLIC - GTEST_HAS_TR1_TUPLE=0 - GTEST_USE_OWN_TR1_TUPLE=0) target_link_libraries( UnitTest PRIVATE testutils GTest::main) add_test(NAME UnitTest COMMAND UnitTest) diff --git a/src/jaegertracing/DynamicLoad.cpp b/src/jaegertracing/DynamicLoad.cpp index 3b77025d..ef388ffe 100644 --- a/src/jaegertracing/DynamicLoad.cpp +++ b/src/jaegertracing/DynamicLoad.cpp @@ -19,12 +19,14 @@ #include -#include "TracerFactory.h" #include "jaegertracing/Tracer.h" +#include "jaegertracing/TracerFactory.h" -int OpenTracingMakeTracerFactory(const char* opentracingVersion, - const void** errorCategory, - void** tracerFactory) +static int makeTracerFactory(const char* opentracingVersion, + const char* opentracingABIVersion, + const void** errorCategory, + void* errorMessage, + void** tracerFactory) { assert(errorCategory != nullptr); assert(tracerFactory != nullptr); @@ -33,7 +35,7 @@ int OpenTracingMakeTracerFactory(const char* opentracingVersion, static_cast(&opentracing::dynamic_load_error_category()); return opentracing::dynamic_load_not_supported_error.value(); #endif - if (std::strcmp(opentracingVersion, OPENTRACING_VERSION) != 0) { + if (std::strcmp(opentracingABIVersion, OPENTRACING_ABI_VERSION) != 0) { *errorCategory = static_cast( &opentracing::dynamic_load_error_category()); return opentracing::incompatible_library_versions_error.value(); @@ -47,3 +49,5 @@ int OpenTracingMakeTracerFactory(const char* opentracingVersion, return 0; } + +OPENTRACING_DECLARE_IMPL_FACTORY(makeTracerFactory) diff --git a/src/jaegertracing/DynamicLoadTest.cpp b/src/jaegertracing/DynamicLoadTest.cpp deleted file mode 100644 index ecac35a9..00000000 --- a/src/jaegertracing/DynamicLoadTest.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2018 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include - -#include "jaegertracing/Constants.h" -#include -#include - -namespace jaegertracing { -namespace { - -void trace(opentracing::TracerFactory& factory) -{ - std::string errorMessage; - auto result = factory.MakeTracer(R"( -service_name: test-service -disabled: false -sampler: - type: probabilistic - param: 0.001 -reporter: - queueSize: 100 - bufferFlushInterval: 10 - logSpans: false - localAgentHostPort: 127.0.0.1:6831 -headers: - jaegerDebugHeader: debug-id - jaegerBaggageHeader: baggage - TraceContextHeaderName: trace-id - traceBaggageHeaderPrefix: testctx- -baggage_restrictions: - denyBaggageOnInitializationFailure: false - hostPort: 127.0.0.1:5778 - refreshInterval: 60 -)", - errorMessage); - assert(errorMessage.empty()); - auto tracer = static_cast>(*result); - { - tracer->StartSpan("a"); - std::cout << "Started span\n"; - } - std::cout << "Finished span\n"; -} - -} // anonymous namespace - -#ifdef JAEGERTRACING_WITH_YAML_CPP -TEST(DynamicLoad, invalidVersion) -{ - const void* errorCategory = nullptr; - void* tracerFactory = nullptr; - const auto rcode = OpenTracingMakeTracerFactory( - "0.0.0" /*invalid version*/, &errorCategory, &tracerFactory); - ASSERT_EQ(rcode, opentracing::incompatible_library_versions_error.value()); - ASSERT_EQ( - errorCategory, - static_cast(&opentracing::dynamic_load_error_category())); - ASSERT_EQ(tracerFactory, nullptr); -} - -TEST(DynamicLoad, validVersion) -{ - const void* errorCategory = nullptr; - void* tracerFactory = nullptr; - const auto rcode = OpenTracingMakeTracerFactory( - OPENTRACING_VERSION, &errorCategory, &tracerFactory); - ASSERT_EQ(rcode, 0); - ASSERT_EQ(errorCategory, nullptr); - ASSERT_NE(tracerFactory, nullptr); - std::unique_ptr factory( - static_cast(tracerFactory)); - trace(*factory); -} -#else -TEST(DynamicLoad, noYAML) -{ - const void* errorCategory = nullptr; - void* tracerFactory = nullptr; - const auto rcode = OpenTracingMakeTracerFactory( - OPENTRACING_VERSION, &errorCategory, &tracerFactory); - ASSERT_NE(rcode, 0); -} -#endif // JAEGERTRACING_WITH_YAML_CPP -} // namespace jaegertracing diff --git a/src/jaegertracing/TracerFactory.h b/src/jaegertracing/TracerFactory.h index 2d4b211c..7369ac29 100644 --- a/src/jaegertracing/TracerFactory.h +++ b/src/jaegertracing/TracerFactory.h @@ -27,6 +27,7 @@ class TracerFactory : public opentracing::TracerFactory { MakeTracer(const char* configuration, std::string& errorMessage) const noexcept override; }; + } // namespace jaegertracing #endif // JAEGERTRACING_TRACER_FACTORY_H