From 4d48ae5974cd0f5fcdd8a5c98183ab847fce5894 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 11:46:21 -0400 Subject: [PATCH 01/43] Add headers to support new relic --- src/ConfigParams.cpp | 8 +++++++- src/ConfigParams.h | 6 ++++++ src/ConfigTags.cpp | 3 +++ src/ConfigTags.h | 3 +++ src/HttpTransport.cpp | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ConfigParams.cpp b/src/ConfigParams.cpp index 04a63e1..12079c4 100644 --- a/src/ConfigParams.cpp +++ b/src/ConfigParams.cpp @@ -13,7 +13,7 @@ namespace cppkin } ConfigParams::ConfigParams(): - m_transportType(TransportType::Stub), m_debug(false), m_sampleCount(1000), m_encodingType(EncodingType::Json), m_batchSize(50) + m_transportType(TransportType::Stub), m_debug(false), m_sampleCount(1000), m_encodingType(EncodingType::Json), m_batchSize(50), m_apiKey(""), m_dataFormat(""), m_dataFormatVersion(0) {} void ConfigParams::Load(const GeneralParams& configParams) @@ -32,5 +32,11 @@ namespace cppkin m_batchSize = configParams.Get(ConfigTags::BATCH_SIZE); if(configParams.Exists(ConfigTags::SAMPLE_COUNT)) m_sampleCount = configParams.Get(ConfigTags::SAMPLE_COUNT); + if(configParams.Exists(ConfigTags::API_KEY)) + m_apiKey = configParams.Get(ConfigTags::API_KEY); + if(configParams.Exists(ConfigTags::DATA_FORMAT)) + m_dataFormat = configParams.Get(ConfigTags::DATA_FORMAT); + if(configParams.Exists(ConfigTags::DATA_FORMAT_VERSION)) + m_dataFormatVersion = configParams.Get(ConfigTags::DATA_FORMAT_VERSION); } } diff --git a/src/ConfigParams.h b/src/ConfigParams.h index 6a5bd19..0e16817 100644 --- a/src/ConfigParams.h +++ b/src/ConfigParams.h @@ -31,6 +31,9 @@ namespace cppkin int GetSampleCount() const { return m_sampleCount; } EncodingType GetEncodingType() const { return m_encodingType; } int GetBatchSize() const { return m_batchSize; } + const std::string& GetApiKey() const { return m_apiKey; } + const std::string& GetDataFormat() const { return m_dataFormat; } + int GetDataFormatVersion() const { return m_dataFormatVersion; } private: ConfigParams(); @@ -38,6 +41,9 @@ namespace cppkin private: std::string m_hostAddress; std::string m_serviceName; + std::string m_apiKey; + std::string m_dataFormat; + int m_dataFormatVersion; int m_port; TransportType m_transportType; bool m_debug; diff --git a/src/ConfigTags.cpp b/src/ConfigTags.cpp index 02f0dc1..90ed693 100644 --- a/src/ConfigTags.cpp +++ b/src/ConfigTags.cpp @@ -10,6 +10,9 @@ namespace cppkin const char* ConfigTags::SAMPLE_COUNT = "Sample Count"; const char* ConfigTags::ENCODING_TYPE = "Encoding Type"; const char* ConfigTags::BATCH_SIZE = "Batch Size"; + const char* ConfigTags::API_KEY = "API Key"; + const char* ConfigTags::DATA_FORMAT = "Data Format"; + const char* ConfigTags::DATA_FORMAT_VERSION = "Data Format Version"; ConfigTags::ConfigTags() {} } diff --git a/src/ConfigTags.h b/src/ConfigTags.h index 3eb9954..303ec56 100644 --- a/src/ConfigTags.h +++ b/src/ConfigTags.h @@ -14,6 +14,9 @@ namespace cppkin { static const char *SAMPLE_COUNT; static const char *ENCODING_TYPE; static const char *BATCH_SIZE; + static const char *API_KEY; + static const char *DATA_FORMAT; + static const char *DATA_FORMAT_VERSION; private: ConfigTags(); }; diff --git a/src/HttpTransport.cpp b/src/HttpTransport.cpp index b5883aa..e217283 100644 --- a/src/HttpTransport.cpp +++ b/src/HttpTransport.cpp @@ -25,6 +25,24 @@ namespace cppkin else headers = curl_slist_append(headers, "Content-Type: application/json"); + if (ConfigParams::Instance().GetApiKey() != "") { + std::stringstream apikey; + apikey << "Api-Key: " << ConfigParams::Instance().GetApiKey(); + headers = curl_slist_append(headers, apikey.str().c_str()); + } + + if (ConfigParams::Instance().GetDataFormat() != "") { + std::stringstream dataformat; + dataformat << "Data-Format: " << ConfigParams::Instance().GetDataFormat(); + headers = curl_slist_append(headers, dataformat.str().c_str()); + } + + if (ConfigParams::Instance().GetDataFormatVersion() != 0) { + std::stringstream dataformatversion; + dataformatversion << "Data-Format-Version: " << ConfigParams::Instance().GetDataFormatVersion(); + headers = curl_slist_append(headers, dataformatversion.str().c_str()); + } + headers = curl_slist_append(headers, "Expect:"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); From 21cba8eb2728355cdcc8a89507008402a04a7081 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 11:57:18 -0400 Subject: [PATCH 02/43] Fix initialization order --- src/ConfigParams.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ConfigParams.h b/src/ConfigParams.h index 0e16817..0fb66b2 100644 --- a/src/ConfigParams.h +++ b/src/ConfigParams.h @@ -40,16 +40,17 @@ namespace cppkin private: std::string m_hostAddress; - std::string m_serviceName; - std::string m_apiKey; - std::string m_dataFormat; - int m_dataFormatVersion; int m_port; + std::string m_serviceName; + TransportType m_transportType; bool m_debug; int m_sampleCount; EncodingType m_encodingType; int m_batchSize; + std::string m_apiKey; + std::string m_dataFormat; + int m_dataFormatVersion; }; } #if defined(WIN32) From d44a53b4de0ae868bf55bff28a1fdb534b58348e Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 12:08:36 -0400 Subject: [PATCH 03/43] Dont treat warnings as errors --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9741a9f..d62b225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,5 +189,5 @@ if(COMPILATION_STEP) endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wno-sign-compare -Wno-unused-variable") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-sign-compare -Wno-unused-variable") endif() From bac62595e627c3711ae72d7c45ca8c40a7223a92 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 13:13:20 -0400 Subject: [PATCH 04/43] Update example with new parameters --- examples/cpp/example.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/cpp/example.cpp b/examples/cpp/example.cpp index 6d29398..ae0e9e6 100644 --- a/examples/cpp/example.cpp +++ b/examples/cpp/example.cpp @@ -51,7 +51,10 @@ int main( int argc, const char *argv[] ) ("encoding", value()->default_value("json"), "Encoding" ) ("host", value()->default_value("127.0.0.1"), "Host" ) ("port", value()->default_value(-1), "Port") - ("service", value()->default_value("example_service"), "Service"); + ("service", value()->default_value("example_service"), "Service") + ("api-key", value()->default_value(""), "API Key") + ("data-format", value()->default_value("zipkin"), "Data Format") + ("data-format-version", value()->default_value(2), "Data Format Version"); variables_map vm; store(parse_command_line(argc, argv, desc), vm); notify(vm); @@ -85,6 +88,9 @@ int main( int argc, const char *argv[] ) cppkinParams.AddParam(cppkin::ConfigTags::SAMPLE_COUNT, 1); cppkinParams.AddParam(cppkin::ConfigTags::TRANSPORT_TYPE, cppkin::TransportType(transportType).ToString()); cppkinParams.AddParam(cppkin::ConfigTags::ENCODING_TYPE, cppkin::EncodingType(encodingType).ToString()); + cppkinParams.AddParam(cppkin::ConfigTags::API_KEY, vm["api-key"].as()); + cppkinParams.AddParam(cppkin::ConfigTags::DATA_FORMAT, vm["data-format"].as()); + cppkinParams.AddParam(cppkin::ConfigTags::DATA_FORMAT_VERSION, vm["data-format-version"].as()); cppkin::Init(cppkinParams); From 5311b831eb7725b9a8bc7cc8a6404d900a2c3e87 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 14:34:41 -0400 Subject: [PATCH 05/43] Fix formatting of zipkin data and cleanup example --- examples/cpp/example.cpp | 22 +++------------------- src/ConfigParams.cpp | 4 ++-- src/ConfigParams.h | 6 +++--- src/ConfigTags.cpp | 4 ++-- src/ConfigTags.h | 4 ++-- src/HttpTransport.cpp | 2 +- src/JsonEncoder.h | 28 ++++++---------------------- 7 files changed, 19 insertions(+), 51 deletions(-) diff --git a/examples/cpp/example.cpp b/examples/cpp/example.cpp index ae0e9e6..b298d0a 100644 --- a/examples/cpp/example.cpp +++ b/examples/cpp/example.cpp @@ -47,10 +47,7 @@ int main( int argc, const char *argv[] ) options_description desc{"Options"}; desc.add_options() ("help,h", "Help screen") - ("transport", value()->default_value("http"), "Transport" ) - ("encoding", value()->default_value("json"), "Encoding" ) - ("host", value()->default_value("127.0.0.1"), "Host" ) - ("port", value()->default_value(-1), "Port") + ("endpoint", value()->default_value("127.0.0.1"), "Endpoint" ) ("service", value()->default_value("example_service"), "Service") ("api-key", value()->default_value(""), "API Key") ("data-format", value()->default_value("zipkin"), "Data Format") @@ -64,27 +61,14 @@ int main( int argc, const char *argv[] ) return 0; } - - int port = 9411; + int port = -1; auto transportType = cppkin::TransportType::Http; - if (vm["transport"].as() == "scribe") { - transportType = cppkin::TransportType::Scribe; - if (vm["port"].as() == -1 ) { - port = 9410; - } - } auto encodingType = cppkin::EncodingType::Json; - if (vm["encoding"].as() == "thrift") { - encodingType = cppkin::EncodingType::Thrift; - if (vm["port"].as() == -1 ) { - port = 9410; - } - } cppkin::CppkinParams cppkinParams; cppkinParams.AddParam(cppkin::ConfigTags::HOST_ADDRESS, vm["host"].as()); - cppkinParams.AddParam(cppkin::ConfigTags::PORT, port); cppkinParams.AddParam(cppkin::ConfigTags::SERVICE_NAME, vm["service"].as()); + cppkinParams.AddParam(cppkin::ConfigTags::PORT, port) cppkinParams.AddParam(cppkin::ConfigTags::SAMPLE_COUNT, 1); cppkinParams.AddParam(cppkin::ConfigTags::TRANSPORT_TYPE, cppkin::TransportType(transportType).ToString()); cppkinParams.AddParam(cppkin::ConfigTags::ENCODING_TYPE, cppkin::EncodingType(encodingType).ToString()); diff --git a/src/ConfigParams.cpp b/src/ConfigParams.cpp index 12079c4..9fbc14e 100644 --- a/src/ConfigParams.cpp +++ b/src/ConfigParams.cpp @@ -18,9 +18,9 @@ namespace cppkin void ConfigParams::Load(const GeneralParams& configParams) { - m_hostAddress = configParams.Get(ConfigTags::HOST_ADDRESS); - m_port = configParams.Get(ConfigTags::PORT); + m_endpoint = configParams.Get(ConfigTags::ENDPOINT); m_serviceName = configParams.Get(ConfigTags::SERVICE_NAME); + m_port = configParams.Get(ConfigTags::PORT); if(configParams.Exists(ConfigTags::DEBUG)) m_debug = configParams.Get(ConfigTags::DEBUG); diff --git a/src/ConfigParams.h b/src/ConfigParams.h index 0fb66b2..6552ba0 100644 --- a/src/ConfigParams.h +++ b/src/ConfigParams.h @@ -23,7 +23,7 @@ namespace cppkin ~ConfigParams() {} void Load(const core::GeneralParams& configParams); //Accessors - const std::string& GetHostAddress() const { return m_hostAddress; } + const std::string& GetEndpoint() const { return m_endpoint; } int GetPort() const { return m_port; } TransportType GetTransportType() const { return m_transportType; } const std::string& GetServiceName() const { return m_serviceName;} @@ -39,9 +39,9 @@ namespace cppkin ConfigParams(); private: - std::string m_hostAddress; - int m_port; + std::string m_endpoint; std::string m_serviceName; + int m_port; TransportType m_transportType; bool m_debug; diff --git a/src/ConfigTags.cpp b/src/ConfigTags.cpp index 90ed693..c8e36ff 100644 --- a/src/ConfigTags.cpp +++ b/src/ConfigTags.cpp @@ -2,11 +2,11 @@ namespace cppkin { - const char* ConfigTags::HOST_ADDRESS = "Host Address"; + const char* ConfigTags::ENDPOINT = "Endpoint"; const char* ConfigTags::PORT = "Port"; + const char* ConfigTags::DEBUG = "Debug"; const char* ConfigTags::TRANSPORT_TYPE = "Transport Type"; const char* ConfigTags::SERVICE_NAME = "Service Name"; - const char* ConfigTags::DEBUG = "Debug"; const char* ConfigTags::SAMPLE_COUNT = "Sample Count"; const char* ConfigTags::ENCODING_TYPE = "Encoding Type"; const char* ConfigTags::BATCH_SIZE = "Batch Size"; diff --git a/src/ConfigTags.h b/src/ConfigTags.h index 303ec56..1275d6c 100644 --- a/src/ConfigTags.h +++ b/src/ConfigTags.h @@ -6,11 +6,11 @@ namespace cppkin { class CPPKIN_EXPORT ConfigTags { public: - static const char *HOST_ADDRESS; + static const char *ENDPOINT; static const char *PORT; + static const char *DEBUG; static const char *TRANSPORT_TYPE; static const char *SERVICE_NAME; - static const char *DEBUG; static const char *SAMPLE_COUNT; static const char *ENCODING_TYPE; static const char *BATCH_SIZE; diff --git a/src/HttpTransport.cpp b/src/HttpTransport.cpp index e217283..4475812 100644 --- a/src/HttpTransport.cpp +++ b/src/HttpTransport.cpp @@ -47,7 +47,7 @@ namespace cppkin curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); std::stringstream url; - url << "http://" << ConfigParams::Instance().GetHostAddress() << ":" << ConfigParams::Instance().GetPort() << "/api/v1/spans"; + url << ConfigParams::Instance().GetEndpoint(); curl_easy_setopt(curl, CURLOPT_URL, url.str().c_str() ); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, buffer.length()); diff --git a/src/JsonEncoder.h b/src/JsonEncoder.h index 35f0bfb..adc4f0a 100644 --- a/src/JsonEncoder.h +++ b/src/JsonEncoder.h @@ -40,37 +40,21 @@ namespace cppkin { writer.String(span.GetHeader().Name.c_str()); writer.Key("id"); writer.String(to_hex(span.GetHeader().ID).c_str()); - writer.Key("debug"); - writer.Bool(ConfigParams::Instance().GetDebug()); - writer.Key("timestamp"); - writer.Int64(span.GetTimeStamp()); writer.Key("duration"); writer.Int64(span.GetDuration()); + writer.Key("kind"); + writer.String("CLIENT"); if(span.GetHeader().ParentIdSet) { writer.Key("parentId"); writer.String(to_hex(span.GetHeader().ParentID).c_str()); } - - { - writer.Key("annotations"); - writer.StartArray(); - for (auto &annotation : span.GetAnnotations()) - if (annotation->GetType() == AnnotationType::Simple) - Serialize(writer, static_cast(*annotation)); - - writer.EndArray(); - } - + { - writer.Key("binaryAnnotations"); - writer.StartArray(); - for (auto &annotation : span.GetAnnotations()) - if (annotation->GetType() == AnnotationType::Binary) - Serialize(writer, static_cast(*annotation)); - - writer.EndArray(); + writer.Key("tags"); + writer.StartObject(); + writer.EndObject(); } writer.EndObject(); From 850bb2cbbd74f5fc4776ad3e261423862662b585 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 14:51:20 -0400 Subject: [PATCH 06/43] Cleanup references to host address --- bench/BenchMark.cpp | 2 +- cppkin/cppkin.py | 2 +- docs/cpp_client.md | 4 ++-- examples/cpp/example.cpp | 4 ++-- src/cppkinWrapper.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bench/BenchMark.cpp b/bench/BenchMark.cpp index 6097a05..efed333 100644 --- a/bench/BenchMark.cpp +++ b/bench/BenchMark.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) { cppkin::CppkinParams cppkinParams; cppkinParams.AddParam(cppkin::ConfigTags::TRANSPORT_TYPE, (cppkin::TransportType(cppkin::TransportType::Stub)).ToString()); - cppkinParams.AddParam(cppkin::ConfigTags::HOST_ADDRESS, string("127.0.0.1")); + cppkinParams.AddParam(cppkin::ConfigTags::ENDPOINT, string("127.0.0.1")); cppkinParams.AddParam(cppkin::ConfigTags::PORT, 9410); cppkinParams.AddParam(cppkin::ConfigTags::SERVICE_NAME, string("Cluster_Manager")); cppkinParams.AddParam(cppkin::ConfigTags::DEBUG, false); diff --git a/cppkin/cppkin.py b/cppkin/cppkin.py index 3bf27d2..3f813e6 100644 --- a/cppkin/cppkin.py +++ b/cppkin/cppkin.py @@ -22,7 +22,7 @@ def top_span(): def start(host_address, port, service_name, sample_count): params = _cppkin.CppkinParams() - params.add_str(_cppkin.HOST_ADDRESS, host_address) + params.add_str(_cppkin.ENDPOINT, host_address) params.add_int(_cppkin.PORT, port) params.add_str(_cppkin.SERVICE_NAME, service_name) params.add_bool(_cppkin.DEBUG, False) diff --git a/docs/cpp_client.md b/docs/cpp_client.md index 7cc4114..a13d851 100644 --- a/docs/cpp_client.md +++ b/docs/cpp_client.md @@ -11,7 +11,7 @@ Before we can start we need to initialize our client, should be done once per se lets set our client different policies: ```c++ cppkin::CppkinParams cppkinParams; -cppkinParams.AddParam(cppkin::ConfigTags::HOST_ADDRESS,"127.0.0.1"); +cppkinParams.AddParam(cppkin::ConfigTags::ENDPOINT,"127.0.0.1"); cppkinParams.AddParam(cppkin::ConfigTags::PORT, 9410); cppkinParams.AddParam(cppkin::ConfigTags::SERVICE_NAME,"serivce_name"); cppkinParams.AddParam(cppkin::ConfigTags::SAMPLE_COUNT, 10000); @@ -20,7 +20,7 @@ cppkinParams.AddParam(cppkin::ConfigTags::SAMPLE_COUNT, 10000); | Config Tag | Info | | ------------- | ------------- | -| HOST_ADDRESS | Zipkin server address in IPV4 format XXX.XXX.XXX.XXX. | +| ENDPOINT | Zipkin server address including port and endpoint | | PORT | Zipkin server port value, usually 9411 for the Http collector | | TRANSPORT_TYPE | Which transportaion to use Scribe/Http, Http is default. | | SERVICE_NAME | our service name to be displayed at Zipkin UI. | diff --git a/examples/cpp/example.cpp b/examples/cpp/example.cpp index b298d0a..036c6f9 100644 --- a/examples/cpp/example.cpp +++ b/examples/cpp/example.cpp @@ -66,9 +66,9 @@ int main( int argc, const char *argv[] ) auto encodingType = cppkin::EncodingType::Json; cppkin::CppkinParams cppkinParams; - cppkinParams.AddParam(cppkin::ConfigTags::HOST_ADDRESS, vm["host"].as()); + cppkinParams.AddParam(cppkin::ConfigTags::ENDPOINT, vm["endpoint"].as()); cppkinParams.AddParam(cppkin::ConfigTags::SERVICE_NAME, vm["service"].as()); - cppkinParams.AddParam(cppkin::ConfigTags::PORT, port) + cppkinParams.AddParam(cppkin::ConfigTags::PORT, port); cppkinParams.AddParam(cppkin::ConfigTags::SAMPLE_COUNT, 1); cppkinParams.AddParam(cppkin::ConfigTags::TRANSPORT_TYPE, cppkin::TransportType(transportType).ToString()); cppkinParams.AddParam(cppkin::ConfigTags::ENCODING_TYPE, cppkin::EncodingType(encodingType).ToString()); diff --git a/src/cppkinWrapper.cpp b/src/cppkinWrapper.cpp index 0f00953..fdd6e78 100644 --- a/src/cppkinWrapper.cpp +++ b/src/cppkinWrapper.cpp @@ -35,7 +35,7 @@ INIT_MODULE(_cppkin, "cppkin library wrapper") params.AddMethod("add_str", "will add a str typed param", &cppkin::CppkinParams::AddParam); params.AddMethod("add_bool", "will add a bool typed param", &cppkin::CppkinParams::AddParam); - sweetPy::CPythonGlobalVariable(module, "HOST_ADDRESS", cppkin::ConfigTags::HOST_ADDRESS); + sweetPy::CPythonGlobalVariable(module, "ENDPOINT", cppkin::ConfigTags::ENDPOINT); sweetPy::CPythonGlobalVariable(module, "PORT", cppkin::ConfigTags::PORT); sweetPy::CPythonGlobalVariable(module, "SERVICE_NAME", cppkin::ConfigTags::SERVICE_NAME); sweetPy::CPythonGlobalVariable(module, "DEBUG", cppkin::ConfigTags::DEBUG); @@ -91,7 +91,7 @@ INIT_MODULE(_cppkin, "cppkin library wrapper") .def("add_str", &cppkin::CppkinParams::AddParam) .def("add_bool", &cppkin::CppkinParams::AddParam); - module.attr("HOST_ADDRESS") = cppkin::ConfigTags::HOST_ADDRESS; + module.attr("ENDPOINT") = cppkin::ConfigTags::ENDPOINT; module.attr("PORT") = cppkin::ConfigTags::PORT; module.attr("SERVICE_NAME") = cppkin::ConfigTags::SERVICE_NAME; module.attr("DEBUG") = cppkin::ConfigTags::DEBUG; From e738389b08bda2ccf8a8f1b5e3ac39ce76b0a974 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Wed, 8 Apr 2020 15:23:05 -0400 Subject: [PATCH 07/43] Add localEndpoint for service --- src/JsonEncoder.h | 13 +++++++++++++ src/Span.cpp | 8 ++++++++ src/Span.h | 3 ++- src/span_impl.cpp | 15 ++++++++++++++- src/span_impl.h | 17 +++++++++++++---- 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/JsonEncoder.h b/src/JsonEncoder.h index adc4f0a..4db2be0 100644 --- a/src/JsonEncoder.h +++ b/src/JsonEncoder.h @@ -51,6 +51,19 @@ namespace cppkin { writer.String(to_hex(span.GetHeader().ParentID).c_str()); } + { + auto endPoint = span.GetLocalEndpoint(); + writer.Key("localEndpoint"); + writer.StartObject(); + writer.Key("serviceName"); + writer.String(endPoint.ServiceName.c_str()); + writer.Key("ipv4"); + writer.String(endPoint.Host.c_str()); + writer.Key("port"); + writer.Int(endPoint.Port); + writer.EndObject(); + } + { writer.Key("tags"); writer.StartObject(); diff --git a/src/Span.cpp b/src/Span.cpp index 101b320..379c15d 100644 --- a/src/Span.cpp +++ b/src/Span.cpp @@ -22,6 +22,7 @@ namespace cppkin { const span_impl::SpanHeader& header = m_span->GetHeader(); Span span( operationName, header.TraceID, header.ID, header.Sampled); + span.AddLocalEndpoint(); span.AddAnnotation(value, m_span->GetTimeStamp()); return span; } @@ -49,6 +50,13 @@ namespace cppkin return; m_span->CreateSimpleAnnotation(value, timeStamp); } + + void Span::AddLocalEndpoint() + { + if(m_span->GetHeader().Sampled == false) + return; + m_span->AddLocalEndpoint(); + } void Span::AddTag(const char* key, bool value) { diff --git a/src/Span.h b/src/Span.h index 2b09558..760509e 100644 --- a/src/Span.h +++ b/src/Span.h @@ -23,6 +23,7 @@ namespace cppkin void Join(const char* b3format); void AddAnnotation(const char* value); void AddAnnotation(const char* value, int_fast64_t timeStamp); + void AddLocalEndpoint(); void AddTag(const char* key, bool value); void AddTag(const char* key, const char* value); void Submit(const char* value = Annotation::Value::SERVER_SEND); @@ -39,4 +40,4 @@ namespace cppkin } #if defined(WIN32) #pragma warning( pop ) -#endif \ No newline at end of file +#endif diff --git a/src/span_impl.cpp b/src/span_impl.cpp index abd886a..8082b8a 100644 --- a/src/span_impl.cpp +++ b/src/span_impl.cpp @@ -17,7 +17,10 @@ namespace cppkin m_header(name, traceID, parentID, id, sampled), m_timeStamp(GetCurrentTime()) {} span_impl::span_impl(const std::string &name, uint_fast64_t traceID, bool sampled) : - m_header(name, traceID, traceID, sampled), m_timeStamp(GetCurrentTime()) {} + m_header(name, traceID, traceID, sampled), m_timeStamp(GetCurrentTime()) + { + AddLocalEndpoint(); + } span_impl::span_impl(const char* b3format) : m_timeStamp(GetCurrentTime()) @@ -56,6 +59,7 @@ namespace cppkin m_timeStamp = obj.m_timeStamp; m_duration = obj.m_duration; m_header = obj.m_header; + m_localEndpoint = obj.m_localEndpoint; } const span_impl::SpanHeader& span_impl::GetHeader() const{ @@ -66,6 +70,15 @@ namespace cppkin return m_events; } + const span_impl::LocalEndpoint& span_impl::GetLocalEndpoint() const{ + return m_localEndpoint; + } + + void span_impl::AddLocalEndpoint() { + VERIFY(!core::Environment::Instance().GetIPV4Addresses().empty(), "Missing IPV4 address"); + m_localEndpoint = { ConfigParams::Instance().GetServiceName(), core::Environment::Instance().GetIPV4Addresses().back(), ConfigParams::Instance().GetPort() }; + } + void span_impl::CreateSimpleAnnotation(const std::string &event) { VERIFY(!core::Environment::Instance().GetIPV4Addresses().empty(), "Missing IPV4 address"); static Annotation::EndPoint endPoint(ConfigParams::Instance().GetServiceName(), diff --git a/src/span_impl.h b/src/span_impl.h index a15fec5..73f201c 100644 --- a/src/span_impl.h +++ b/src/span_impl.h @@ -38,6 +38,12 @@ namespace cppkin bool Sampled; bool ParentIdSet; }; + struct CPPKIN_EXPORT LocalEndpoint + { + std::string ServiceName; + std::string Host; + int_fast16_t Port; + }; public: ~span_impl() = default; @@ -45,13 +51,15 @@ namespace cppkin span_impl& operator=(const span_impl&) = delete; const SpanHeader& GetHeader() const; const Annotations& GetAnnotations() const; + const LocalEndpoint& GetLocalEndpoint() const; void CreateSimpleAnnotation(const std::string& event); void CreateSimpleAnnotation(const std::string& event, int_fast64_t timeStamp); void CreateBinaryAnnotation(const char* key, bool value); void CreateBinaryAnnotation(const char* key, const char* value); - int_fast64_t GetTimeStamp() const; - int_fast64_t GetDuration() const; - void SetEndTime(); + void AddLocalEndpoint(); + int_fast64_t GetTimeStamp() const; + int_fast64_t GetDuration() const; + void SetEndTime(); private: friend class Trace; @@ -67,10 +75,11 @@ namespace cppkin private: SpanHeader m_header; Annotations m_events; + LocalEndpoint m_localEndpoint; int_fast64_t m_timeStamp; int_fast64_t m_duration; }; } #if defined(WIN32) #pragma warning( pop ) -#endif \ No newline at end of file +#endif From bcb09db01e5a18b8ad0a924723c6210176ef2829 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 11:28:24 -0400 Subject: [PATCH 08/43] Add Dockerfile and script to build deb --- Dockerfile | 34 ++++++++++++++++++++++++ scripts/generate_deb.sh | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 Dockerfile create mode 100755 scripts/generate_deb.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f483e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:18.04 + +RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ + apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ + apt-get install -y libboost-all-dev libaudit-dev software-properties-common + +RUN add-apt-repository universe + +RUN wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb && \ + apt-get install ./packages-microsoft-prod.deb + +RUN apt-get update && apt-get install -y dotnet-sdk-2.1.105 + +RUN mkdir /cppKin +COPY CMakeLists.txt /cppKin +COPY IDL/ /cppKin/IDL/ +COPY LICENSE /cppKin +COPY MANIFEST.in /cppKin +COPY README.md /cppKin +COPY Third_Party/ /cppKin/Third_Party +COPY appveyor.yml /cppKin +COPY bench/ /cppKin/bench +COPY cmake/ /cppKin/cmake +COPY cppkin/ /cppKin/cppkin +COPY cppkin.bat /cppKin +COPY cppkin.sh /cppKin +COPY docs/ /cppKin/docs +COPY examples/ /cppKin/examples +COPY scripts/ /scripts +COPY setup.py /cppKin +COPY src/ /cppKin/src +COPY tests/ /cppKin/tests + +RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local && make && make install diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh new file mode 100755 index 0000000..0072e00 --- /dev/null +++ b/scripts/generate_deb.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# This assumes that you installed cppkin via: +# cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local + +cd / + +PACKAGE="eosio-cppkin" +VERSION="1.0.0" + +mkdir -p /${PACKAGE}/DEBIAN +mkdir -p /${PACKAGE}/usr/local/lib +mkdir -p /${PACKAGE}/usr/local/include + +cp /usr/local/lib/libCore.so /${PACKAGE}/usr/local/lib +cp /usr/local/lib/libcppkin.so /${PACKAGE}/usr/local/lib + +cp /usr/local/include/Annotation.h /${PACKAGE}/usr/local/include +cp /usr/local/include/AnnotationType.h /${PACKAGE}/usr/local/include +cp /usr/local/include/BinaryAnnotation.h /${PACKAGE}/usr/local/include +cp /usr/local/include/ConfigParams.h /${PACKAGE}/usr/local/include +cp /usr/local/include/ConfigTags.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Encoder.h /${PACKAGE}/usr/local/include +cp /usr/local/include/EncodingContext.h /${PACKAGE}/usr/local/include +cp /usr/local/include/EncodingTypes.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Export.h /${PACKAGE}/usr/local/include +cp /usr/local/include/HttpTransport.h /${PACKAGE}/usr/local/include +cp /usr/local/include/JsonEncoder.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Sampler.h /${PACKAGE}/usr/local/include +cp /usr/local/include/ScribeTransport.h /${PACKAGE}/usr/local/include +cp /usr/local/include/SimpleAnnotation.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Span.h /${PACKAGE}/usr/local/include +cp /usr/local/include/StubTransport.h /${PACKAGE}/usr/local/include +cp /usr/local/include/ThriftEncoder.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Trace.h /${PACKAGE}/usr/local/include +cp /usr/local/include/Transport.h /${PACKAGE}/usr/local/include +cp /usr/local/include/TransportFactory.h /${PACKAGE}/usr/local/include +cp /usr/local/include/TransportManager.h /${PACKAGE}/usr/local/include +cp /usr/local/include/TransportType.h /${PACKAGE}/usr/local/include +cp /usr/local/include/cppkin.h /${PACKAGE}/usr/local/include +cp /usr/local/include/span_impl.h /${PACKAGE}/usr/local/include + +cp -r /usr/local/include/core /${PACKAGE}/usr/local/include +cp -r /usr/local/include/spdlog /${PACKAGE}/usr/local/include + +echo "Package: ${PACKAGE} +Version: ${VERSION} +Section: devel +Priority: optional +Architecture: amd64 +Homepage: https://github.com/EOSIO/cppkin +Maintainer: support@block.one +Description: C++ integration for zipkin tracing" &> /${PACKAGE}/DEBIAN/control + +dpkg-deb --build ${PACKAGE} + +mv /${PACKAGE}.deb /${PACKAGE}_${VERSION}-ubuntu-18.04_amd64.deb From bb2529be93d33772babb16b5fd093bf09e647637 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 11:32:32 -0400 Subject: [PATCH 09/43] Add pipeline --- .buildkite/pipeline.yml | 8 ++++++++ scripts/build-and-push-container.sh | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 .buildkite/pipeline.yml create mode 100755 scripts/build-and-push-container.sh diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml new file mode 100644 index 0000000..94cf1f4 --- /dev/null +++ b/.buildkite/pipeline.yml @@ -0,0 +1,8 @@ +steps: + - command: "./scripts/build-and-push-container.sh cppkin $BUILDKITE_BRANCH" + label: "Docker build eosio-cppkin" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 15 + retry: + automatic: true diff --git a/scripts/build-and-push-container.sh b/scripts/build-and-push-container.sh new file mode 100755 index 0000000..2220ce4 --- /dev/null +++ b/scripts/build-and-push-container.sh @@ -0,0 +1,6 @@ +set -e + +edited_tag=$(echo $2 | sed 's/\//\_/g') +docker build -t registry.devel.b1ops.net/b1automation/$1:$edited_tag . +docker push registry.devel.b1ops.net/b1automation/$1:$edited_tag +docker rmi registry.devel.b1ops.net/b1automation/$1:$edited_tag From 018e2f9b9db325641fda17dc8f4e92d114dcfa09 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 12:43:50 -0400 Subject: [PATCH 10/43] Create deb in pipeline --- .buildkite/pipeline.yml | 25 +++++++++++++++++++++++++ scripts/generate_deb.sh | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 94cf1f4..82565da 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -6,3 +6,28 @@ steps: timeout: 15 retry: automatic: true + + - wait + + - block: "Package version" + prompt: "Input package version" + fields: + - text: "Version" + key: "package-version" + hint: "Package version for cppkin" + + - wait + + - command: | + VERSION=$(buildkite-agent meta-data get package-version) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) + sleep 5 + docker cp $CID:/cppkin_${VERSION}-ubuntu-18.04_amd64.deb . + ls + label: "Create cppkin debian package" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 5 + artifact_paths: + - "*.deb" + diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index 0072e00..925606c 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -3,10 +3,12 @@ # This assumes that you installed cppkin via: # cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local +set -u + cd / -PACKAGE="eosio-cppkin" -VERSION="1.0.0" +PACKAGE="cppkin" +VERSION=$1 mkdir -p /${PACKAGE}/DEBIAN mkdir -p /${PACKAGE}/usr/local/lib From 39fc6b9c2459394f846925fd26d9f6adc910e7d3 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 13:45:05 -0400 Subject: [PATCH 11/43] limit deb creation to master --- .buildkite/pipeline.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 82565da..c235a22 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -10,6 +10,7 @@ steps: - wait - block: "Package version" + branches: "master" prompt: "Input package version" fields: - text: "Version" @@ -24,6 +25,7 @@ steps: sleep 5 docker cp $CID:/cppkin_${VERSION}-ubuntu-18.04_amd64.deb . ls + branches: "master" label: "Create cppkin debian package" agents: queue: "automation-eks-docker-builder-fleet" From f42a7ac42a8ff1656640cffdff37d8f860363e5c Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 13:50:09 -0400 Subject: [PATCH 12/43] Remove travis ci --- .travis.yml | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 182237c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: python -python: - - "3.6" -sudo: required - -matrix: - include: - # works on Precise and Trusty - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-5 - env: - - MATRIX_EVAL="CC=gcc-5 && CXX=g++-5" - -before_install: -- eval "${MATRIX_EVAL}" -- sudo unlink /usr/bin/g++ && sudo ln -s /usr/bin/g++-5 /usr/bin/g++ -- g++ --version - -before_script: -- ulimit -c unlimited -S # enable core dumps - -script: -- mkdir build && cd build -- ../cppkin.sh config --with_tests --with_examples && make -- BUILD_DIR=$(pwd) python ../tests/tests.py - -after_failure: -- COREFILE=$(find . -maxdepth 1 -name "core*" | head -n 1) # find core file -- if [[ -f "$COREFILE" ]]; then gdb -c "$COREFILE" ./Tests/bin/sweetPyTests -ex "thread apply all bt" -ex "set pagination 0" -batch; fi -notifications: - email: false From 668e00305c02e487f3ae145eb7a02408b3098d96 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 10 Apr 2020 14:06:33 -0400 Subject: [PATCH 13/43] not eosio-cppkin --- .buildkite/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index c235a22..6e32b47 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,6 +1,6 @@ steps: - command: "./scripts/build-and-push-container.sh cppkin $BUILDKITE_BRANCH" - label: "Docker build eosio-cppkin" + label: "Docker build cppkin" agents: queue: "automation-eks-docker-builder-fleet" timeout: 15 From 7b57ba9f4386131f80e5087d90e757ee0f30941a Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Sun, 12 Apr 2020 17:02:31 -0400 Subject: [PATCH 14/43] Add postinst script for running ldconfig --- scripts/generate_deb.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index 925606c..21ecd5a 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -54,6 +54,11 @@ Homepage: https://github.com/EOSIO/cppkin Maintainer: support@block.one Description: C++ integration for zipkin tracing" &> /${PACKAGE}/DEBIAN/control +echo "#!/bin/bash +echo 'Running ldconfig' +ldconfig" &> /${PACKAGE}/DEBIAN/postinst +chmod +x /${PACKAGE}/DEBIAN/postinst + dpkg-deb --build ${PACKAGE} mv /${PACKAGE}.deb /${PACKAGE}_${VERSION}-ubuntu-18.04_amd64.deb From 065293dce6818544408f6692fa4a20a479f04417 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 13 Apr 2020 12:59:55 -0400 Subject: [PATCH 15/43] Add simple tags --- CMakeLists.txt | 6 ++-- examples/cpp/example.cpp | 4 +++ src/BinaryAnnotation.cpp | 10 +++---- src/BinaryAnnotation.h | 11 ++------ src/JsonEncoder.h | 60 ++++++++++++++++++++++++++++++++++------ src/SimpleTag.cpp | 57 ++++++++++++++++++++++++++++++++++++++ src/SimpleTag.h | 36 ++++++++++++++++++++++++ src/Span.cpp | 28 +++++++++++++++++++ src/Span.h | 4 +++ src/ValueTypes.h | 14 ++++++++++ src/span_impl.cpp | 30 ++++++++++++++++++++ src/span_impl.h | 8 ++++++ 12 files changed, 243 insertions(+), 25 deletions(-) create mode 100644 src/SimpleTag.cpp create mode 100644 src/SimpleTag.h create mode 100644 src/ValueTypes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d62b225..081e9e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,11 +122,11 @@ if(COMPILATION_STEP) set(TO_LINK_LIBS pthread curl libCore${CMAKE_DEBUG_POSTFIX}.so) endif() - add_library(cppkin SHARED src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp) + add_library(cppkin SHARED src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) if(CPPKIN_DEPEND_LIST) add_dependencies(cppkin ${CPPKIN_DEPEND_LIST}) endif() - set_target_properties(cppkin PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") + set_target_properties(cppkin PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") if(WITH_PYTHON) set(binderLib "") @@ -189,5 +189,5 @@ if(COMPILATION_STEP) endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-sign-compare -Wno-unused-variable") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wno-sign-compare -Wno-unused-variable -DBOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT") endif() diff --git a/examples/cpp/example.cpp b/examples/cpp/example.cpp index 036c6f9..10c7e2d 100644 --- a/examples/cpp/example.cpp +++ b/examples/cpp/example.cpp @@ -86,6 +86,10 @@ int main( int argc, const char *argv[] ) portable_sleep(1); span_1.AddAnnotation("Span1Event"); span_1.AddTag("str value", "some value"); + span_1.AddSimpleTag("StringTag", "string"); + span_1.AddSimpleTag("BoolTag", true); + span_1.AddSimpleTag("IntTag", 10); + span_1.AddSimpleTag("FloatTag", float(10.99)); //Lets use the span container in order to reach a certain stack frame. cppkin::PushSpan(span_1); foo(); diff --git a/src/BinaryAnnotation.cpp b/src/BinaryAnnotation.cpp index a62bff4..49c596e 100644 --- a/src/BinaryAnnotation.cpp +++ b/src/BinaryAnnotation.cpp @@ -7,13 +7,13 @@ namespace cppkin BinaryAnnotation::BinaryAnnotation(const EndPoint& endPoint, const char* key, bool value) :Annotation(AnnotationType::Binary, endPoint), m_key(key), - m_valueType(BinaryValueTypes::Boolean), m_value(value) + m_valueType(ValueTypes::Boolean), m_value(value) { } BinaryAnnotation::BinaryAnnotation(const EndPoint& endPoint, const char* key, const char* value) :Annotation(AnnotationType::Binary, endPoint), m_key(key), - m_valueType(BinaryValueTypes::String), m_value(std::string(value)) + m_valueType(ValueTypes::String), m_value(std::string(value)) { } @@ -25,14 +25,14 @@ namespace cppkin void BinaryAnnotation::GetValue(bool& value) const { - if(m_valueType != BinaryValueTypes::Boolean) + if(m_valueType != ValueTypes::Boolean) throw core::Exception(__CORE_SOURCE, "Requested type dosen't match the stored instance type"); value = boost::get(m_value); } void BinaryAnnotation::GetValue(std::string& value) const { - if(m_valueType != BinaryValueTypes::String) + if(m_valueType != ValueTypes::String) throw core::Exception(__CORE_SOURCE, "Requested type dosen't match the stored instance type"); value = boost::get(m_value); } -} \ No newline at end of file +} diff --git a/src/BinaryAnnotation.h b/src/BinaryAnnotation.h index 4cc5168..a3ac4ae 100644 --- a/src/BinaryAnnotation.h +++ b/src/BinaryAnnotation.h @@ -5,16 +5,11 @@ #include "boost/variant.hpp" #include "Annotation.h" #include "Export.h" +#include "ValueTypes.h" namespace cppkin { - enum BinaryValueTypes - { - Boolean, - String - }; - class BinaryAnnotation : public Annotation { public: @@ -23,7 +18,7 @@ namespace cppkin BinaryAnnotation(const BinaryAnnotation& object); ~BinaryAnnotation() override = default; - BinaryValueTypes GetValueType() const { return m_valueType; } + ValueTypes GetValueType() const { return m_valueType; } const std::string& GetKey() const { return m_key; } void GetValue(bool& value) const; @@ -31,7 +26,7 @@ namespace cppkin private: std::string m_key; - BinaryValueTypes m_valueType; + ValueTypes m_valueType; boost::variant m_value; }; } diff --git a/src/JsonEncoder.h b/src/JsonEncoder.h index 4db2be0..20d7d22 100644 --- a/src/JsonEncoder.h +++ b/src/JsonEncoder.h @@ -6,6 +6,7 @@ #include "ConfigParams.h" #include "SimpleAnnotation.h" #include "BinaryAnnotation.h" +#include "ValueTypes.h" namespace cppkin { @@ -67,9 +68,43 @@ namespace cppkin { { writer.Key("tags"); writer.StartObject(); + for(auto& tag : span.GetTags()) + { + writer.Key(tag->GetKey().c_str()); + switch(tag->GetValueType()) + { + case ValueTypes::Boolean: + { + bool bool_value; + tag->GetValue(bool_value); + writer.Bool(bool_value); + } + break; + case ValueTypes::String: + { + std::string str_value; + tag->GetValue(str_value); + writer.String(str_value.c_str()); + } + break; + case ValueTypes::Int: + { + int int_value; + tag->GetValue(int_value); + writer.Int(int_value); + } + break; + case ValueTypes::Float: + { + float float_value; + tag->GetValue(float_value); + writer.Double(float_value); + } + break; + } + } writer.EndObject(); } - writer.EndObject(); } @@ -105,15 +140,22 @@ namespace cppkin { writer.Key("value"); switch(annotation.GetValueType()) { - case BinaryValueTypes::Boolean: - bool bool_value; - annotation.GetValue(bool_value); - writer.Bool(bool_value); + case ValueTypes::Boolean: + { + bool bool_value; + annotation.GetValue(bool_value); + writer.Bool(bool_value); + } + break; + case ValueTypes::String: + { + std::string str_value; + annotation.GetValue(str_value); + writer.String(str_value.c_str()); + } break; - case BinaryValueTypes::String: - std::string str_value; - annotation.GetValue(str_value); - writer.String(str_value.c_str()); + case ValueTypes::Int: + case ValueTypes::Float: break; } diff --git a/src/SimpleTag.cpp b/src/SimpleTag.cpp new file mode 100644 index 0000000..f2eb255 --- /dev/null +++ b/src/SimpleTag.cpp @@ -0,0 +1,57 @@ +#include "SimpleTag.h" +#include "core/Exception.h" +#include "boost/variant/get.hpp" + +namespace cppkin +{ + + SimpleTag::SimpleTag(const char* key, bool value) : + m_key(key), m_valueType(ValueTypes::Boolean), m_value(value) + { + } + + SimpleTag::SimpleTag(const char* key, const char* value) : + m_key(key), m_valueType(ValueTypes::String), m_value(std::string(value)) + { + } + + SimpleTag::SimpleTag(const char* key, int value) : + m_key(key), m_valueType(ValueTypes::Int), m_value(value) + { + } + + SimpleTag::SimpleTag(const char* key, float value) : + m_key(key), m_valueType(ValueTypes::Float), m_value(value) + { + } + + SimpleTag::SimpleTag(const SimpleTag& object) : + m_key(object.m_key), m_valueType(object.m_valueType), m_value(object.m_value) + { + } + + void SimpleTag::GetValue(bool& value) const + { + if(m_valueType != ValueTypes::Boolean) + throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type"); + value = boost::get(m_value); + } + void SimpleTag::GetValue(std::string& value) const + { + if(m_valueType != ValueTypes::String) + throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type"); + value = boost::get(m_value); + } + void SimpleTag::GetValue(int& value) const + { + if(m_valueType != ValueTypes::Int) + throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type"); + value = boost::get(m_value); + } + void SimpleTag::GetValue(float& value) const + { + if(m_valueType != ValueTypes::Float) + throw core::Exception(__CORE_SOURCE, "Requested type doesn't match the stored instance type"); + value = boost::get(m_value); + } +} diff --git a/src/SimpleTag.h b/src/SimpleTag.h new file mode 100644 index 0000000..11f9de1 --- /dev/null +++ b/src/SimpleTag.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include "boost/variant.hpp" +#include "Export.h" +#include "ValueTypes.h" + +namespace cppkin +{ + + class SimpleTag + { + public: + SimpleTag(const char* key, bool value); + SimpleTag(const char* key, const char* value); + SimpleTag(const char* key, int value); + SimpleTag(const char* key, float value); + SimpleTag(const SimpleTag& object); + + ~SimpleTag() {} + ValueTypes GetValueType() const { return m_valueType; } + const std::string& GetKey() const { return m_key; } + + void GetValue(bool& value) const; + void GetValue(std::string& value) const; + void GetValue(int& value) const; + void GetValue(float& value) const; + + private: + std::string m_key; + ValueTypes m_valueType; + boost::variant m_value; + }; +} + diff --git a/src/Span.cpp b/src/Span.cpp index 379c15d..1948740 100644 --- a/src/Span.cpp +++ b/src/Span.cpp @@ -72,6 +72,34 @@ namespace cppkin m_span->CreateBinaryAnnotation(key, value); } + void Span::AddSimpleTag(const char* key, bool value) + { + if(m_span->GetHeader().Sampled == false) + return; + m_span->CreateSimpleTag(key, value); + } + + void Span::AddSimpleTag(const char* key, const char* value) + { + if(m_span->GetHeader().Sampled == false) + return; + m_span->CreateSimpleTag(key, value); + } + + void Span::AddSimpleTag(const char* key, int value) + { + if(m_span->GetHeader().Sampled == false) + return; + m_span->CreateSimpleTag(key, value); + } + + void Span::AddSimpleTag(const char* key, float value) + { + if(m_span->GetHeader().Sampled == false) + return; + m_span->CreateSimpleTag(key, value); + } + void Span::Submit(const char* value) { if(m_span->GetHeader().Sampled == false) diff --git a/src/Span.h b/src/Span.h index 760509e..2bc37bd 100644 --- a/src/Span.h +++ b/src/Span.h @@ -26,6 +26,10 @@ namespace cppkin void AddLocalEndpoint(); void AddTag(const char* key, bool value); void AddTag(const char* key, const char* value); + void AddSimpleTag(const char* key, bool value); + void AddSimpleTag(const char* key, const char* value); + void AddSimpleTag(const char* key, int value); + void AddSimpleTag(const char* key, float value); void Submit(const char* value = Annotation::Value::SERVER_SEND); bool IsSampled() const; void GetHeaderB3Format(const char*& b3header) const; diff --git a/src/ValueTypes.h b/src/ValueTypes.h new file mode 100644 index 0000000..3b5cbda --- /dev/null +++ b/src/ValueTypes.h @@ -0,0 +1,14 @@ +#pragma once + + +namespace cppkin +{ + enum ValueTypes + { + Boolean, + String, + Int, + Float + }; +} + diff --git a/src/span_impl.cpp b/src/span_impl.cpp index 8082b8a..b8fdcec 100644 --- a/src/span_impl.cpp +++ b/src/span_impl.cpp @@ -56,6 +56,12 @@ namespace cppkin } } + + for(const auto& tag : obj.m_tags) + { + m_tags.emplace_back(new SimpleTag(*tag)); + } + m_timeStamp = obj.m_timeStamp; m_duration = obj.m_duration; m_header = obj.m_header; @@ -70,6 +76,10 @@ namespace cppkin return m_events; } + const span_impl::Tags& span_impl::GetTags() const{ + return m_tags; + } + const span_impl::LocalEndpoint& span_impl::GetLocalEndpoint() const{ return m_localEndpoint; } @@ -113,6 +123,26 @@ namespace cppkin m_events.emplace_back(new BinaryAnnotation(endPoint, key, value)); } + void span_impl::CreateSimpleTag(const char *key, bool value) + { + m_tags.emplace_back(new SimpleTag(key, value)); + } + + void span_impl::CreateSimpleTag(const char *key, const char* value) + { + m_tags.emplace_back(new SimpleTag(key, value)); + } + + void span_impl::CreateSimpleTag(const char *key, int value) + { + m_tags.emplace_back(new SimpleTag(key, value)); + } + + void span_impl::CreateSimpleTag(const char *key, float value) + { + m_tags.emplace_back(new SimpleTag(key, value)); + } + int_fast64_t span_impl::GetTimeStamp() const{ return m_timeStamp; } diff --git a/src/span_impl.h b/src/span_impl.h index 73f201c..3416efe 100644 --- a/src/span_impl.h +++ b/src/span_impl.h @@ -8,6 +8,7 @@ #include "core/Environment.h" #include "Annotation.h" #include "BinaryAnnotation.h" +#include "SimpleTag.h" #include "ConfigParams.h" #include "Export.h" #if defined(WIN32) @@ -24,6 +25,7 @@ namespace cppkin { public: typedef std::vector> Annotations; + typedef std::vector> Tags; struct CPPKIN_EXPORT SpanHeader { public: @@ -51,11 +53,16 @@ namespace cppkin span_impl& operator=(const span_impl&) = delete; const SpanHeader& GetHeader() const; const Annotations& GetAnnotations() const; + const Tags& GetTags() const; const LocalEndpoint& GetLocalEndpoint() const; void CreateSimpleAnnotation(const std::string& event); void CreateSimpleAnnotation(const std::string& event, int_fast64_t timeStamp); void CreateBinaryAnnotation(const char* key, bool value); void CreateBinaryAnnotation(const char* key, const char* value); + void CreateSimpleTag(const char* key, bool value); + void CreateSimpleTag(const char* key, const char* value); + void CreateSimpleTag(const char* key, int value); + void CreateSimpleTag(const char* key, float value); void AddLocalEndpoint(); int_fast64_t GetTimeStamp() const; int_fast64_t GetDuration() const; @@ -75,6 +82,7 @@ namespace cppkin private: SpanHeader m_header; Annotations m_events; + Tags m_tags; LocalEndpoint m_localEndpoint; int_fast64_t m_timeStamp; int_fast64_t m_duration; From 8edbc58b2161dcff13d0108aa81946ccc6b947b0 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 13 Apr 2020 13:12:10 -0400 Subject: [PATCH 16/43] Build for 18.04 and 19.04 --- .buildkite/pipeline.yml | 30 +++++++++++++++++++++---- scripts/build-and-push-container.sh | 8 +++---- Dockerfile => ubuntu1804.Dockerfile | 0 ubuntu1904.Dockerfile | 34 +++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 8 deletions(-) rename Dockerfile => ubuntu1804.Dockerfile (100%) create mode 100644 ubuntu1904.Dockerfile diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 6e32b47..85c95fd 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,6 +1,14 @@ steps: - - command: "./scripts/build-and-push-container.sh cppkin $BUILDKITE_BRANCH" - label: "Docker build cppkin" + - command: "./scripts/build-and-push-container.sh cppkin ubuntu1804 $BUILDKITE_BRANCH" + label: ":ubuntu: 18.04 Docker build cppkin" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 15 + retry: + automatic: true + + - command: "./scripts/build-and-push-container.sh cppkin ubuntu1904 $BUILDKITE_BRANCH" + label: ":ubuntu: 19.04 Docker build cppkin" agents: queue: "automation-eks-docker-builder-fleet" timeout: 15 @@ -21,12 +29,26 @@ steps: - command: | VERSION=$(buildkite-agent meta-data get package-version) - CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1804:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) sleep 5 docker cp $CID:/cppkin_${VERSION}-ubuntu-18.04_amd64.deb . ls branches: "master" - label: "Create cppkin debian package" + label: ":ubuntu: 18.04 Create cppkin debian package" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 5 + artifact_paths: + - "*.deb" + + - command: | + VERSION=$(buildkite-agent meta-data get package-version) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1904:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) + sleep 5 + docker cp $CID:/cppkin_${VERSION}-ubuntu-19.04_amd64.deb . + ls + branches: "master" + label: ":ubuntu: 19.04 Create cppkin debian package" agents: queue: "automation-eks-docker-builder-fleet" timeout: 5 diff --git a/scripts/build-and-push-container.sh b/scripts/build-and-push-container.sh index 2220ce4..2c80807 100755 --- a/scripts/build-and-push-container.sh +++ b/scripts/build-and-push-container.sh @@ -1,6 +1,6 @@ set -e -edited_tag=$(echo $2 | sed 's/\//\_/g') -docker build -t registry.devel.b1ops.net/b1automation/$1:$edited_tag . -docker push registry.devel.b1ops.net/b1automation/$1:$edited_tag -docker rmi registry.devel.b1ops.net/b1automation/$1:$edited_tag +edited_tag=$(echo $3 | sed 's/\//\_/g') +docker build -t registry.devel.b1ops.net/b1automation/$1_$2:$edited_tag . -f $2.Dockerfile +docker push registry.devel.b1ops.net/b1automation/$1_$2:$edited_tag +docker rmi registry.devel.b1ops.net/b1automation/$1_$2:$edited_tag diff --git a/Dockerfile b/ubuntu1804.Dockerfile similarity index 100% rename from Dockerfile rename to ubuntu1804.Dockerfile diff --git a/ubuntu1904.Dockerfile b/ubuntu1904.Dockerfile new file mode 100644 index 0000000..b0df384 --- /dev/null +++ b/ubuntu1904.Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:19.04 + +RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ + apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ + apt-get install -y libboost-all-dev libaudit-dev software-properties-common + +RUN wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb && \ + apt-get install ./packages-microsoft-prod.deb + +RUN apt update +RUN apt install -y apt-transport-https +RUN apt-get update && apt-get install -y dotnet-sdk-3.1 + +RUN mkdir /cppKin +COPY CMakeLists.txt /cppKin +COPY IDL/ /cppKin/IDL/ +COPY LICENSE /cppKin +COPY MANIFEST.in /cppKin +COPY README.md /cppKin +COPY Third_Party/ /cppKin/Third_Party +COPY appveyor.yml /cppKin +COPY bench/ /cppKin/bench +COPY cmake/ /cppKin/cmake +COPY cppkin/ /cppKin/cppkin +COPY cppkin.bat /cppKin +COPY cppkin.sh /cppKin +COPY docs/ /cppKin/docs +COPY examples/ /cppKin/examples +COPY scripts/ /scripts +COPY setup.py /cppKin +COPY src/ /cppKin/src +COPY tests/ /cppKin/tests + +RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local --with_examples && make && make install From 93a993f7b6646974b23681c1680f5f8187981fe2 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 13 Apr 2020 13:30:10 -0400 Subject: [PATCH 17/43] Fix deb script to honor ubuntu version --- .buildkite/pipeline.yml | 4 ++-- scripts/generate_deb.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 85c95fd..75e4d6d 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -29,7 +29,7 @@ steps: - command: | VERSION=$(buildkite-agent meta-data get package-version) - CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1804:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1804:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION "18.04") sleep 5 docker cp $CID:/cppkin_${VERSION}-ubuntu-18.04_amd64.deb . ls @@ -43,7 +43,7 @@ steps: - command: | VERSION=$(buildkite-agent meta-data get package-version) - CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1904:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1904:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION "19.04") sleep 5 docker cp $CID:/cppkin_${VERSION}-ubuntu-19.04_amd64.deb . ls diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index 21ecd5a..42a7e7b 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -9,6 +9,7 @@ cd / PACKAGE="cppkin" VERSION=$1 +UBUNTU_VERSION=$2 mkdir -p /${PACKAGE}/DEBIAN mkdir -p /${PACKAGE}/usr/local/lib @@ -61,4 +62,4 @@ chmod +x /${PACKAGE}/DEBIAN/postinst dpkg-deb --build ${PACKAGE} -mv /${PACKAGE}.deb /${PACKAGE}_${VERSION}-ubuntu-18.04_amd64.deb +mv /${PACKAGE}.deb /${PACKAGE}_${VERSION}-ubuntu-${UBUNTU_VERSION}_amd64.deb From c197ba293fccf2443add3d9a1f2a88b4b290e75f Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 13 Apr 2020 14:15:39 -0400 Subject: [PATCH 18/43] Copy ValueTypes.h into package --- scripts/generate_deb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index 42a7e7b..ea8bcfb 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -21,6 +21,7 @@ cp /usr/local/lib/libcppkin.so /${PACKAGE}/usr/local/lib cp /usr/local/include/Annotation.h /${PACKAGE}/usr/local/include cp /usr/local/include/AnnotationType.h /${PACKAGE}/usr/local/include cp /usr/local/include/BinaryAnnotation.h /${PACKAGE}/usr/local/include +cp /usr/local/include/ValueTypes.h /${PACKAGE}/usr/local/include cp /usr/local/include/ConfigParams.h /${PACKAGE}/usr/local/include cp /usr/local/include/ConfigTags.h /${PACKAGE}/usr/local/include cp /usr/local/include/Encoder.h /${PACKAGE}/usr/local/include From 18938e7b963fce74d81cc8c72830f8f90feb6873 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 13 Apr 2020 14:39:34 -0400 Subject: [PATCH 19/43] Copy SimpleTag.h into package --- scripts/generate_deb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index ea8bcfb..821a91e 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -33,6 +33,7 @@ cp /usr/local/include/JsonEncoder.h /${PACKAGE}/usr/local/include cp /usr/local/include/Sampler.h /${PACKAGE}/usr/local/include cp /usr/local/include/ScribeTransport.h /${PACKAGE}/usr/local/include cp /usr/local/include/SimpleAnnotation.h /${PACKAGE}/usr/local/include +cp /usr/local/include/SimpleTag.h /${PACKAGE}/usr/local/include cp /usr/local/include/Span.h /${PACKAGE}/usr/local/include cp /usr/local/include/StubTransport.h /${PACKAGE}/usr/local/include cp /usr/local/include/ThriftEncoder.h /${PACKAGE}/usr/local/include From 19cbaccd0e8e968c0682c9ecf19af58d0de6af3e Mon Sep 17 00:00:00 2001 From: Jing Xie Date: Wed, 29 Apr 2020 22:26:28 -0400 Subject: [PATCH 20/43] Create ubuntu2004.Dockerfile --- ubuntu2004.Dockerfile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ubuntu2004.Dockerfile diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile new file mode 100644 index 0000000..6d39ac6 --- /dev/null +++ b/ubuntu2004.Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ + apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ + apt-get install -y libboost-all-dev libaudit-dev software-properties-common + +RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \ + apt-get install ./packages-microsoft-prod.deb + +RUN apt update +RUN apt install -y apt-transport-https +RUN apt-get update && apt-get install -y dotnet-sdk-3.1 + +RUN mkdir /cppKin +COPY CMakeLists.txt /cppKin +COPY IDL/ /cppKin/IDL/ +COPY LICENSE /cppKin +COPY MANIFEST.in /cppKin +COPY README.md /cppKin +COPY Third_Party/ /cppKin/Third_Party +COPY appveyor.yml /cppKin +COPY bench/ /cppKin/bench +COPY cmake/ /cppKin/cmake +COPY cppkin/ /cppKin/cppkin +COPY cppkin.bat /cppKin +COPY cppkin.sh /cppKin +COPY docs/ /cppKin/docs +COPY examples/ /cppKin/examples +COPY scripts/ /scripts +COPY setup.py /cppKin +COPY src/ /cppKin/src +COPY tests/ /cppKin/tests + +RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local --with_examples && make && make install From 31fa158c9e0114e9ede92c6c8ec7a8e4e2ca15e5 Mon Sep 17 00:00:00 2001 From: Jing Xie Date: Wed, 29 Apr 2020 22:29:58 -0400 Subject: [PATCH 21/43] add ubuntu 20.04 --- .buildkite/pipeline.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 75e4d6d..e3c26bc 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -14,6 +14,14 @@ steps: timeout: 15 retry: automatic: true + + - command: "./scripts/build-and-push-container.sh cppkin ubuntu2004 $BUILDKITE_BRANCH" + label: ":ubuntu: 20.04 Docker build cppkin" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 15 + retry: + automatic: true - wait @@ -54,4 +62,18 @@ steps: timeout: 5 artifact_paths: - "*.deb" + + - command: | + VERSION=$(buildkite-agent meta-data get package-version) + CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu2004:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION "20.04") + sleep 5 + docker cp $CID:/cppkin_${VERSION}-ubuntu-20.04_amd64.deb . + ls + branches: "master" + label: ":ubuntu: 20.04 Create cppkin debian package" + agents: + queue: "automation-eks-docker-builder-fleet" + timeout: 5 + artifact_paths: + - "*.deb" From 694ba30de68037e09d0dd9553ee8fac64f489b4c Mon Sep 17 00:00:00 2001 From: Jing Xie Date: Wed, 29 Apr 2020 22:37:11 -0400 Subject: [PATCH 22/43] add noninteractive env variable --- ubuntu2004.Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index 6d39ac6..a8cecf1 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -1,5 +1,7 @@ FROM ubuntu:20.04 +ENV DEBIAN_FRONTEND=noninteractive + RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ apt-get install -y libboost-all-dev libaudit-dev software-properties-common From 6d01a5675745331828927038ad4d5d8aea06b4a4 Mon Sep 17 00:00:00 2001 From: Jing Xie Date: Wed, 29 Apr 2020 22:44:58 -0400 Subject: [PATCH 23/43] change dotnet version --- ubuntu2004.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index a8cecf1..31b2004 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -11,7 +11,7 @@ RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsof RUN apt update RUN apt install -y apt-transport-https -RUN apt-get update && apt-get install -y dotnet-sdk-3.1 +RUN apt-get update && apt-get install -y dotnet-sdk-2.1.105 RUN mkdir /cppKin COPY CMakeLists.txt /cppKin From f2d5bfe8f4eb083aacec7279e912c698c5c57936 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 4 May 2020 14:53:04 -0400 Subject: [PATCH 24/43] install dotnet from source --- ubuntu2004.Dockerfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index 31b2004..d8e54e2 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -2,16 +2,17 @@ FROM ubuntu:20.04 ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ - apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ - apt-get install -y libboost-all-dev libaudit-dev software-properties-common +RUN apt update && apt install -y wget git cmake pybind11-dev rapidjson-dev && \ + apt install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ + apt install -y libboost-all-dev libaudit-dev software-properties-common && \ + apt install -y build-essential -RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \ - apt-get install ./packages-microsoft-prod.deb +RUN wget https://download.visualstudio.microsoft.com/download/pr/f65a8eb0-4537-4e69-8ff3-1a80a80d9341/cc0ca9ff8b9634f3d9780ec5915c1c66/dotnet-sdk-3.1.201-linux-x64.tar.gz && \ + mkdir -p dotnet && \ + tar xvzf dotnet-sdk-3.1.201-linux-x64.tar.gz -C dotnet -RUN apt update -RUN apt install -y apt-transport-https -RUN apt-get update && apt-get install -y dotnet-sdk-2.1.105 +RUN export DOTNET_ROOT=/dotnet && \ + export PATH=$PATH:/dotnet RUN mkdir /cppKin COPY CMakeLists.txt /cppKin From 2a4746462f0381dd0e4805e98a9d5fa2aa2c96a9 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Mon, 4 May 2020 14:55:21 -0400 Subject: [PATCH 25/43] remove 19.04 (EOL) --- .buildkite/pipeline.yml | 22 ---------------------- ubuntu1904.Dockerfile | 34 ---------------------------------- 2 files changed, 56 deletions(-) delete mode 100644 ubuntu1904.Dockerfile diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index e3c26bc..e7bb8d3 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -7,14 +7,6 @@ steps: retry: automatic: true - - command: "./scripts/build-and-push-container.sh cppkin ubuntu1904 $BUILDKITE_BRANCH" - label: ":ubuntu: 19.04 Docker build cppkin" - agents: - queue: "automation-eks-docker-builder-fleet" - timeout: 15 - retry: - automatic: true - - command: "./scripts/build-and-push-container.sh cppkin ubuntu2004 $BUILDKITE_BRANCH" label: ":ubuntu: 20.04 Docker build cppkin" agents: @@ -49,20 +41,6 @@ steps: artifact_paths: - "*.deb" - - command: | - VERSION=$(buildkite-agent meta-data get package-version) - CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu1904:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION "19.04") - sleep 5 - docker cp $CID:/cppkin_${VERSION}-ubuntu-19.04_amd64.deb . - ls - branches: "master" - label: ":ubuntu: 19.04 Create cppkin debian package" - agents: - queue: "automation-eks-docker-builder-fleet" - timeout: 5 - artifact_paths: - - "*.deb" - - command: | VERSION=$(buildkite-agent meta-data get package-version) CID=$(docker run -d registry.devel.b1ops.net/b1automation/cppkin_ubuntu2004:$BUILDKITE_BRANCH ./scripts/generate_deb.sh $VERSION "20.04") diff --git a/ubuntu1904.Dockerfile b/ubuntu1904.Dockerfile deleted file mode 100644 index b0df384..0000000 --- a/ubuntu1904.Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -FROM ubuntu:19.04 - -RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ - apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ - apt-get install -y libboost-all-dev libaudit-dev software-properties-common - -RUN wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb && \ - apt-get install ./packages-microsoft-prod.deb - -RUN apt update -RUN apt install -y apt-transport-https -RUN apt-get update && apt-get install -y dotnet-sdk-3.1 - -RUN mkdir /cppKin -COPY CMakeLists.txt /cppKin -COPY IDL/ /cppKin/IDL/ -COPY LICENSE /cppKin -COPY MANIFEST.in /cppKin -COPY README.md /cppKin -COPY Third_Party/ /cppKin/Third_Party -COPY appveyor.yml /cppKin -COPY bench/ /cppKin/bench -COPY cmake/ /cppKin/cmake -COPY cppkin/ /cppKin/cppkin -COPY cppkin.bat /cppKin -COPY cppkin.sh /cppKin -COPY docs/ /cppKin/docs -COPY examples/ /cppKin/examples -COPY scripts/ /scripts -COPY setup.py /cppKin -COPY src/ /cppKin/src -COPY tests/ /cppKin/tests - -RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local --with_examples && make && make install From 2d9ab8108fc467dbebcc286042e177a5ce9c9704 Mon Sep 17 00:00:00 2001 From: Emory Barlow Date: Fri, 31 Jul 2020 18:42:40 -0400 Subject: [PATCH 26/43] Add timestamp to traces so that they show up in zipkin ui --- src/JsonEncoder.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/JsonEncoder.h b/src/JsonEncoder.h index 20d7d22..6c38a7e 100644 --- a/src/JsonEncoder.h +++ b/src/JsonEncoder.h @@ -41,6 +41,8 @@ namespace cppkin { writer.String(span.GetHeader().Name.c_str()); writer.Key("id"); writer.String(to_hex(span.GetHeader().ID).c_str()); + writer.Key("timestamp"); + writer.Int64(span.GetTimeStamp()); writer.Key("duration"); writer.Int64(span.GetDuration()); writer.Key("kind"); From 52c2947deb73a4fad148842cb0d072a5a4574bae Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 7 Aug 2020 15:41:30 -0500 Subject: [PATCH 27/43] Add static build --- CMakeLists.txt | 9 +++++++-- scripts/generate_deb.sh | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 081e9e0..73e06ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,11 @@ if(COMPILATION_STEP) set(TO_LINK_LIBS pthread curl libCore${CMAKE_DEBUG_POSTFIX}.so) endif() - add_library(cppkin SHARED src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) + set(CPPKIN_SOURCES src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) + + add_library(cppkin SHARED ${CPPKIN_SOURCES}) + add_library(cppkin STATIC ${CPPKIN_SOURCES}) + if(CPPKIN_DEPEND_LIST) add_dependencies(cppkin ${CPPKIN_DEPEND_LIST}) endif() @@ -180,10 +184,11 @@ if(COMPILATION_STEP) install(TARGETS cppkin PUBLIC_HEADER DESTINATION ${OUTPUT_DIR}/include LIBRARY DESTINATION ${OUTPUT_DIR}/lib + ARCHIVE DESTINATION ${OUTPUT_DIR}/lib ) install(DIRECTORY ${PROJECT_3RD_LOC}/lib DESTINATION ${OUTPUT_DIR} - FILES_MATCHING PATTERN "*.so" + FILES_MATCHING PATTERN "*.so" PATTERN "*.a" ) endif() endif() diff --git a/scripts/generate_deb.sh b/scripts/generate_deb.sh index 821a91e..5e7d38e 100755 --- a/scripts/generate_deb.sh +++ b/scripts/generate_deb.sh @@ -17,6 +17,7 @@ mkdir -p /${PACKAGE}/usr/local/include cp /usr/local/lib/libCore.so /${PACKAGE}/usr/local/lib cp /usr/local/lib/libcppkin.so /${PACKAGE}/usr/local/lib +cp /usr/local/lib/libcppkin.a /${PACKAGE}/usr/local/lib cp /usr/local/include/Annotation.h /${PACKAGE}/usr/local/include cp /usr/local/include/AnnotationType.h /${PACKAGE}/usr/local/include From 4b7873749cf4087e27bc0525f10de36f6930dc25 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 10 Aug 2020 09:32:31 -0500 Subject: [PATCH 28/43] Create both SHARED & STATIC libs --- CMakeLists.txt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73e06ab..b63711c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,14 +124,18 @@ if(COMPILATION_STEP) set(CPPKIN_SOURCES src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) - add_library(cppkin SHARED ${CPPKIN_SOURCES}) - add_library(cppkin STATIC ${CPPKIN_SOURCES}) + add_library(cppkin-shared SHARED ${CPPKIN_SOURCES}) + set_target_properties(cppkin-shared PROPERTIES OUTPUT_NAME cppkin) + add_library(cppkin-static STATIC ${CPPKIN_SOURCES}) + set_target_properties(cppkin-static PROPERTIES OUTPUT_NAME cppkin) if(CPPKIN_DEPEND_LIST) - add_dependencies(cppkin ${CPPKIN_DEPEND_LIST}) + add_dependencies(cppkin-shared ${CPPKIN_DEPEND_LIST}) + add_dependencies(cppkin-static ${CPPKIN_DEPEND_LIST}) endif() - set_target_properties(cppkin PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") - + set_target_properties(cppkin-shared PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") + set_target_properties(cppkin-static PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") + if(WITH_PYTHON) set(binderLib "") if(${PYTHON_BINDING} STREQUAL "sweetPy") @@ -163,7 +167,8 @@ if(COMPILATION_STEP) if(${SPDLOG_FOUND}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPDLOG_FOUND") endif() - target_link_libraries(cppkin ${TO_LINK_LIBS}) + target_link_libraries(cppkin-shared ${TO_LINK_LIBS}) + target_link_libraries(cppkin-static ${TO_LINK_LIBS}) if(WITH_EXAMPLES) add_subdirectory(${PROJECT_SOURCE_DIR}/examples) @@ -181,7 +186,7 @@ if(COMPILATION_STEP) FILES_MATCHING PATTERN "*.dll" ) else() - install(TARGETS cppkin + install(TARGETS cppkin-shared cppkin-static PUBLIC_HEADER DESTINATION ${OUTPUT_DIR}/include LIBRARY DESTINATION ${OUTPUT_DIR}/lib ARCHIVE DESTINATION ${OUTPUT_DIR}/lib From 21e5951b81aa5749a89c5fef6134eba6a52751f6 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 10 Aug 2020 12:04:30 -0500 Subject: [PATCH 29/43] Avoid use of uninitialized shared_ptr for default construction --- src/Span.cpp | 24 +++++++++++++----------- src/span_impl.h | 14 +++++++------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Span.cpp b/src/Span.cpp index 1948740..573d49f 100644 --- a/src/Span.cpp +++ b/src/Span.cpp @@ -39,70 +39,70 @@ namespace cppkin void Span::AddAnnotation(const char* value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleAnnotation(value); } void Span::AddAnnotation(const char* value, int_fast64_t timeStamp) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleAnnotation(value, timeStamp); } void Span::AddLocalEndpoint() { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->AddLocalEndpoint(); } void Span::AddTag(const char* key, bool value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateBinaryAnnotation(key, value); } void Span::AddTag(const char* key, const char* value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span && !m_span->GetHeader().Sampled) return; m_span->CreateBinaryAnnotation(key, value); } void Span::AddSimpleTag(const char* key, bool value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleTag(key, value); } void Span::AddSimpleTag(const char* key, const char* value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleTag(key, value); } void Span::AddSimpleTag(const char* key, int value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleTag(key, value); } void Span::AddSimpleTag(const char* key, float value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->CreateSimpleTag(key, value); } void Span::Submit(const char* value) { - if(m_span->GetHeader().Sampled == false) + if(!m_span || !m_span->GetHeader().Sampled) return; m_span->SetEndTime(); if(strcmp(value, Annotation::Value::NOP) != 0) @@ -112,11 +112,12 @@ namespace cppkin bool Span::IsSampled() const { - return m_span->GetHeader().Sampled; + return m_span && m_span->GetHeader().Sampled; } void Span::GetHeaderB3Format(const char*& b3header) const { + if(!m_span) throw core::Exception(__CORE_SOURCE, "Header not available"); typedef std::unique_ptr> char_ptr; std::string b3header_str = m_span->GetHeaderB3Format(); char_ptr temp_header((char*)malloc(sizeof(char)*(b3header_str.size() + 1)), [](char* ptr){free(ptr);}); @@ -127,6 +128,7 @@ namespace cppkin const span_impl::SpanHeader& Span::GetHeader() const { + if(!m_span) throw core::Exception(__CORE_SOURCE, "SpanHeader not available"); return m_span->GetHeader(); } } diff --git a/src/span_impl.h b/src/span_impl.h index 3416efe..1772711 100644 --- a/src/span_impl.h +++ b/src/span_impl.h @@ -34,11 +34,11 @@ namespace cppkin SpanHeader() = default; public: std::string Name; - uint_fast64_t ID; - uint_fast64_t ParentID; - uint_fast64_t TraceID; - bool Sampled; - bool ParentIdSet; + uint_fast64_t ID = 0; + uint_fast64_t ParentID = 0; + uint_fast64_t TraceID = 0; + bool Sampled = false; + bool ParentIdSet = false; }; struct CPPKIN_EXPORT LocalEndpoint { @@ -84,8 +84,8 @@ namespace cppkin Annotations m_events; Tags m_tags; LocalEndpoint m_localEndpoint; - int_fast64_t m_timeStamp; - int_fast64_t m_duration; + int_fast64_t m_timeStamp = 0; + int_fast64_t m_duration = 0; }; } #if defined(WIN32) From 3c1212eb6d97aadb68edf595b5f2d3dbf41a37c3 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 10 Aug 2020 12:04:47 -0500 Subject: [PATCH 30/43] Optimize use of std::string --- src/SimpleTag.cpp | 6 ++++++ src/SimpleTag.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/SimpleTag.cpp b/src/SimpleTag.cpp index f2eb255..7b6de48 100644 --- a/src/SimpleTag.cpp +++ b/src/SimpleTag.cpp @@ -15,6 +15,12 @@ namespace cppkin { } + SimpleTag::SimpleTag(const char* key, std::string value) : + m_key(key), m_valueType(ValueTypes::String), m_value(std::move(value)) + { + } + + SimpleTag::SimpleTag(const char* key, int value) : m_key(key), m_valueType(ValueTypes::Int), m_value(value) { diff --git a/src/SimpleTag.h b/src/SimpleTag.h index 11f9de1..91e5669 100644 --- a/src/SimpleTag.h +++ b/src/SimpleTag.h @@ -14,6 +14,7 @@ namespace cppkin public: SimpleTag(const char* key, bool value); SimpleTag(const char* key, const char* value); + SimpleTag(const char* key, std::string value); SimpleTag(const char* key, int value); SimpleTag(const char* key, float value); SimpleTag(const SimpleTag& object); From 9ae4de1ecd9a6dcd64f0712942a1df68d0d9316f Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 11 Sep 2020 15:32:06 -0500 Subject: [PATCH 31/43] Build with boost static libs --- cmake/FindBoost_Pack.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/FindBoost_Pack.cmake b/cmake/FindBoost_Pack.cmake index a4c095b..22404e7 100644 --- a/cmake/FindBoost_Pack.cmake +++ b/cmake/FindBoost_Pack.cmake @@ -1,6 +1,7 @@ set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_LIBS OFF) -find_package(Boost 1.58.0 COMPONENTS program_options) +# EOSIO build with boost static libs +# set(Boost_USE_STATIC_LIBS OFF) +find_package(Boost 1.58.0) if(Boost_FOUND) message(STATUS "Found Boost include dir - ${Green}${Boost_INCLUDE_DIR}${ColourReset}") From dd99ed68f462a5912da87ccb8b5c1a63fbf7e592 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 08:34:55 -0500 Subject: [PATCH 32/43] Add rapidjson as a submodule. Remove dependency on libCore. --- .gitmodules | 3 +++ CMakeLists.txt | 4 ++-- cmake/FindCore.cmake | 15 --------------- cmake/FindRapidJson.cmake | 9 --------- external/rapidjson | 1 + 5 files changed, 6 insertions(+), 26 deletions(-) create mode 100644 .gitmodules delete mode 100644 cmake/FindCore.cmake delete mode 100644 cmake/FindRapidJson.cmake create mode 160000 external/rapidjson diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7caf0dc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/rapidjson"] + path = external/rapidjson + url = https://github.com/Tencent/rapidjson.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 081e9e0..a3fbf99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,8 +70,6 @@ if(3RD_PARTY_INSTALL_STEP) find_package(SpdLog) find_package(Boost_Pack) find_package(CURL) - find_package(Core) - find_package(RapidJson) if(WITH_PYTHON) find_package(Python) if(${PYTHON_BINDING} STREQUAL "sweetPy") @@ -161,6 +159,8 @@ if(COMPILATION_STEP) endif() target_link_libraries(cppkin ${TO_LINK_LIBS}) + target_include_directories(cppkin PUBLIC include external/rapidjson/include) + if(WITH_EXAMPLES) add_subdirectory(${PROJECT_SOURCE_DIR}/examples) endif() diff --git a/cmake/FindCore.cmake b/cmake/FindCore.cmake deleted file mode 100644 index 72de129..0000000 --- a/cmake/FindCore.cmake +++ /dev/null @@ -1,15 +0,0 @@ -find_path(CORE_INCLUDE_DIR NAMES Exception.h PATHS ${PROJECT_3RD_LOC}/include/core) -if(WIN32) - find_program(CORE_LIBRARY_DIR NAMES Core${CMAKE_DEBUG_POSTFIX}.dll PATHS ${PROJECT_3RD_LOC}/lib) -else() - find_program(CORE_LIBRARY_DIR NAMES libCore${CMAKE_DEBUG_POSTFIX}.so PATHS ${PROJECT_3RD_LOC}/lib) -endif() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Core REQUIRED_VARS CORE_INCLUDE_DIR CORE_LIBRARY_DIR) - -if(Core_FOUND) - message(STATUS "Found Core include dir - ${Green}${CORE_INCLUDE_DIR}${ColourReset}") - message(STATUS "Found Core library dir - ${Green}${CORE_LIBRARY_DIR}${ColourReset}") -else() - message(WARNING ${Red}"Core not found"${ColourReset}) -endif() diff --git a/cmake/FindRapidJson.cmake b/cmake/FindRapidJson.cmake deleted file mode 100644 index 2f9492a..0000000 --- a/cmake/FindRapidJson.cmake +++ /dev/null @@ -1,9 +0,0 @@ -find_path(RAPIDJSON_INCLUDE_DIR NAMES rapidjson/rapidjson.h PATHS ${PROJECT_3RD_LOC}/include) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(RAPIDJSON REQUIRED_VARS RAPIDJSON_INCLUDE_DIR) - -if(RAPIDJSON_FOUND) - message(STATUS "Found RAPIDJSON include dir - ${Green}${RAPIDJSON_INCLUDE_DIR}${ColourReset}") -else() - message(WARNING ${Red}"RAPIDJSON not found"${ColourReset}) -endif() diff --git a/external/rapidjson b/external/rapidjson new file mode 160000 index 0000000..ce81bc9 --- /dev/null +++ b/external/rapidjson @@ -0,0 +1 @@ +Subproject commit ce81bc9edfe773667a7a4454ba81dac72ed4364c From eb67ff4b1734365ef35e0d6fa10b1da19dafded8 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 08:35:37 -0500 Subject: [PATCH 33/43] Do not build examples --- ubuntu2004.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index d8e54e2..1f7932f 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -34,4 +34,4 @@ COPY setup.py /cppKin COPY src/ /cppKin/src COPY tests/ /cppKin/tests -RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local --with_examples && make && make install +RUN cd cppKin && mkdir build && cd build && ../cppkin.sh config --output_dir=/usr/local --3rd_loc_prefix=/usr/local && make && make install From ea4ad9ac813f73dbdc28d84162f99642820973f7 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 09:07:48 -0500 Subject: [PATCH 34/43] working on removing core --- CMakeLists.txt | 15 ++-- src/AnnotationType.h | 2 +- src/Assert.h | 7 ++ src/EncodingTypes.h | 2 +- src/Enumeration.h | 67 ++++++++++++++++ src/Environment.cpp | 69 +++++++++++++++++ src/Environment.h | 33 ++++++++ src/Exception.h | 34 +++++++++ src/Export.h | 9 ++- src/Logger.cpp | 109 ++++++++++++++++++++++++++ src/Logger.h | 174 ++++++++++++++++++++++++++++++++++++++++++ src/LoggerImpl.h | 20 +++++ src/NoExcept.h | 7 ++ src/Source.h | 16 ++++ src/SpanContainer.cpp | 2 +- src/TransportType.h | 2 +- src/span_impl.h | 4 +- 17 files changed, 557 insertions(+), 15 deletions(-) create mode 100644 src/Assert.h create mode 100644 src/Enumeration.h create mode 100644 src/Environment.cpp create mode 100644 src/Environment.h create mode 100644 src/Exception.h create mode 100644 src/Logger.cpp create mode 100644 src/Logger.h create mode 100644 src/LoggerImpl.h create mode 100644 src/NoExcept.h create mode 100644 src/Source.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a7ca7fa..2072a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ project(cppKin CXX) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.8) -set (CMAKE_CXX_STANDARD 11) +set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_COLOR_MAKEFILE ON) set (CMAKE_CXX_EXTENSIONS OFF) @@ -115,12 +115,12 @@ if(COMPILATION_STEP) if(WIN32) add_definitions(-DCURL_STATICLIB) - set(TO_LINK_LIBS libcurl Core${CMAKE_DEBUG_POSTFIX}.dll Ws2_32) + set(TO_LINK_LIBS libcurl Ws2_32) else() - set(TO_LINK_LIBS pthread curl libCore${CMAKE_DEBUG_POSTFIX}.so) + set(TO_LINK_LIBS pthread curl) endif() - set(CPPKIN_SOURCES src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) + set(CPPKIN_SOURCES src/Export.h src/Assert.h src/Environment.h src/Environment.cpp src/Logger.h src/Logger.cpp src/LoggerImpl.h src/NoExcept.h src/Source.h src/Enumeration.h src/Exception.h src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) add_library(cppkin-shared SHARED ${CPPKIN_SOURCES}) set_target_properties(cppkin-shared PROPERTIES OUTPUT_NAME cppkin) @@ -147,7 +147,7 @@ if(COMPILATION_STEP) if(CPPKIN_WRAPPER_DEPEND_LIST) add_dependencies(_cppkin ${CPPKIN_WRAPPER_DEPEND_LIST}) endif() - target_link_libraries(_cppkin libCore${CMAKE_DEBUG_POSTFIX}.so ${binderLib} cppkin) + target_link_libraries(_cppkin ${binderLib} cppkin) set_target_properties(_cppkin PROPERTIES PREFIX "") set_target_properties(_cppkin PROPERTIES DEBUG_POSTFIX "") endif() @@ -168,7 +168,8 @@ if(COMPILATION_STEP) target_link_libraries(cppkin-shared ${TO_LINK_LIBS}) target_link_libraries(cppkin-static ${TO_LINK_LIBS}) - target_include_directories(cppkin PUBLIC include external/rapidjson/include) + target_include_directories(cppkin-shared PUBLIC include external/rapidjson/include) + target_include_directories(cppkin-static PUBLIC include external/rapidjson/include) if(WITH_EXAMPLES) add_subdirectory(${PROJECT_SOURCE_DIR}/examples) diff --git a/src/AnnotationType.h b/src/AnnotationType.h index d14d9bb..0775f10 100644 --- a/src/AnnotationType.h +++ b/src/AnnotationType.h @@ -1,6 +1,6 @@ #pragma once -#include "core/Enumeration.h" +#include "Enumeration.h" #include "Export.h" namespace cppkin diff --git a/src/Assert.h b/src/Assert.h new file mode 100644 index 0000000..7402adf --- /dev/null +++ b/src/Assert.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include +#include "Exception.h" +#define PLATFORM_VERIFY(expression) do{ if((expression) == false) throw core::Exception(__CORE_SOURCE, "An error occured, Reason - %s, error code - %d", strerror(errno), errno); } while(0) +#define VERIFY(expression, ...) do{ if((expression) == false) throw core::Exception(__CORE_SOURCE, __VA_ARGS__ ); } while(0) diff --git a/src/EncodingTypes.h b/src/EncodingTypes.h index c82bca4..92e01d3 100644 --- a/src/EncodingTypes.h +++ b/src/EncodingTypes.h @@ -1,6 +1,6 @@ #pragma once -#include "core/Enumeration.h" +#include "Enumeration.h" #include "Export.h" namespace cppkin diff --git a/src/Enumeration.h b/src/Enumeration.h new file mode 100644 index 0000000..7001b9c --- /dev/null +++ b/src/Enumeration.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include "Exception.h" + +#define ENUMERATION(name) \ +public: \ + name(Enumeration e):m_currentEnum(e){} \ + operator Enumeration() const {return m_currentEnum;} \ + std::string ToString() const;\ + static Enumeration FromString(const std::string& str);\ +\ +public: \ + struct Hash{ \ + Hash() = default; \ + size_t operator()(const name& e) const{ \ + return std::hash{}((int)(Enumeration)e); \ + };\ + size_t operator()(const name* e) const{ \ + return std::hash{}((int)(Enumeration)*e); \ + }; \ + }; \ +\ +private: \ + struct EnumStringPair\ + {\ + Enumeration enumValue;\ + std::string enumStrName;\ + };\ +\ +private: \ + Enumeration m_currentEnum; \ + static EnumStringPair m_enumToString[]; \ + const static int numOfEnumValues;\ + +#define ENUMERATION_NAMING_BEGIN(name)\ + name::EnumStringPair name::m_enumToString[]={ + +#define ENUMERATION_NAMING_END(name)\ + };\ + const int name::numOfEnumValues = std::extent::value;\ + \ + std::string name::ToString() const\ + {\ + for(int index = 0; index < numOfEnumValues; index++)\ + {\ + if(m_enumToString[index].enumValue == m_currentEnum)\ + return m_enumToString[index].enumStrName;\ + }\ + throw core::Exception(__CORE_SOURCE,"Not all enum values are covered");\ + }\ + \ + name::Enumeration name::FromString(const std::string& str){\ + for(int index = 0; index < numOfEnumValues; index++){\ + if(m_enumToString[index].enumStrName == str) \ + return m_enumToString[index].enumValue; \ + }\ + throw core::Exception(__CORE_SOURCE, "requested string value is not supported - %s", str.c_str());\ + } + + + + + + diff --git a/src/Environment.cpp b/src/Environment.cpp new file mode 100644 index 0000000..42dbc54 --- /dev/null +++ b/src/Environment.cpp @@ -0,0 +1,69 @@ +#include "Environment.h" +#include +#include +#if defined(__linux) +#include +#include +#include +#include +#endif +#include "Assert.h" +#include "Directory.h" + +using namespace std; + +namespace core +{ + Environment& Environment::Instance() + { + static Environment instance; + return instance; + } + + void Environment::Init() + { + if(m_initiated.exchange(true) == true) + return; +#if defined(__linux) + PLATFORM_VERIFY((m_coreCount = sysconf(_SC_NPROCESSORS_ONLN)) != -1); +#endif + ReadProcessLocation(); + ReadIPV4Addresses(); + } + + void Environment::ReadProcessLocation() + { +#if defined(__linux) + char buffer[MAX_WORKING_DIR_SIZE]; + ssize_t byteCount = readlink("/proc/self/exe", buffer, MAX_WORKING_DIR_SIZE); + string processFullPath = string(buffer, byteCount > 0 ? byteCount : 0); + m_processPath = Directory::GetDirctoryFullPath(processFullPath); + m_processName = Directory::GetFileName(processFullPath); +#endif + } + + void Environment::ReadIPV4Addresses() + { +#if defined(__linux) + struct ifaddrs *ifaddr; + PLATFORM_VERIFY(getifaddrs(&ifaddr) != -1); + std::unique_ptr> guard(ifaddr, + [](struct ifaddrs* ptr){freeifaddrs(ptr);}); + struct ifaddrs* ifaCurrent = ifaddr; + char host[INET_ADDRSTRLEN]; + while(ifaCurrent != NULL) + { + if(ifaCurrent->ifa_addr != NULL && ifaCurrent->ifa_addr->sa_family == AF_INET) + { + // void* addrPtr =&((struct sockaddr_in *)ifaCurrent->ifa_addr)->sin_addr; + PLATFORM_VERIFY(getnameinfo(ifaCurrent->ifa_addr, sizeof(struct sockaddr_in), host, INET_ADDRSTRLEN, + NULL, 0, NI_NUMERICHOST) == 0); + m_ipv4Adrresses.emplace_back(host); + } + ifaCurrent = ifaCurrent->ifa_next; + } +#else + m_ipv4Adrresses.emplace_back("127.0.0.1"); +#endif + } +} diff --git a/src/Environment.h b/src/Environment.h new file mode 100644 index 0000000..e85fbf1 --- /dev/null +++ b/src/Environment.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include +#include "Export.h" + +namespace core +{ + class Environment + { + public: + CORE_EXPORT static Environment& Instance(); + CORE_EXPORT void Init(); + //Accessors + int GetCoreCount() const { return m_coreCount; } + const std::string& GetProcessPath() const { return m_processPath; } + const std::string& GetProcessName() const { return m_processName; } + const std::vector GetIPV4Addresses() const{ return m_ipv4Adrresses;} + + private: + void ReadProcessLocation(); + void ReadIPV4Addresses(); + + private: + static const int MAX_WORKING_DIR_SIZE = 500; + int m_coreCount; + std::string m_processPath; + std::string m_processName; + std::atomic_bool m_initiated; + std::vector m_ipv4Adrresses; + }; +} diff --git a/src/Exception.h b/src/Exception.h new file mode 100644 index 0000000..74842f8 --- /dev/null +++ b/src/Exception.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include "Source.h" +#include "Logger.h" +#include "NoExcept.h" + +namespace core +{ + /**/ + class Exception : public std::exception + { + public: + /*Exception constructor will megerge the received exception message and print out the message and the entire + stack frames to the log.*/ + template + Exception(const Source& source, const char* format, Args&& ... args) + { + m_message = Logger::Instance().BuildMessage(source, format, args...); + TRACE_ERROR("%s", m_message.c_str()); + Logger::Instance().PrintStack(); + Logger::Instance().Flush(); + } + + Exception() = delete; + Exception(const Exception& object) NOEXCEPT(true) :m_message(object.m_message){}; + virtual ~Exception() NOEXCEPT(true) {} + //Accessor + std::string GetMessage() const {return m_message;} + protected: + std::string m_message; + }; +} diff --git a/src/Export.h b/src/Export.h index bc8a95e..d420081 100644 --- a/src/Export.h +++ b/src/Export.h @@ -1,12 +1,17 @@ #pragma once #if defined(WIN32) + #ifdef CORE_DLL + #define CORE_EXPORT __declspec(dllexport) + #else + #define CORE_EXPORT __declspec(dllimport) + #endif #ifdef CPPKIN_DLL #define CPPKIN_EXPORT __declspec(dllexport) #else #define CPPKIN_EXPORT __declspec(dllimport) #endif #else + #define CORE_EXPORT #define CPPKIN_EXPORT -#endif - +#endif \ No newline at end of file diff --git a/src/Logger.cpp b/src/Logger.cpp new file mode 100644 index 0000000..e1ee098 --- /dev/null +++ b/src/Logger.cpp @@ -0,0 +1,109 @@ +#if defined(WIN32) +#else +#include +#endif +#include +#include +#include +#include + +#include "Logger.h" +#include "TraceListener.h" +#include "Process.h" +#include "Environment.h" +#include "DefaultLogger.h" + +using namespace std; + +namespace core +{ + + Logger& Logger::Instance() + { + static Logger logger; + return logger; + } + + Logger::~Logger() + { + } + + Logger::Logger(): m_severity(TraceSeverity::NoneWorking) + { + Environment::Instance().Init(); + } + + tuple Logger::GetFunctionAndLine(char* mangledSymbol) + { + static std::string unknown("???????"); +#if defined(WIN32) +#else + int status; + static regex functionManglingPattern("\\((.*)\\+(0x[0-9a-f]*)\\)\\s*\\[(0x[0-9a-f]*)\\]"); + cmatch functionMangaledMatch; + if(regex_search(mangledSymbol, functionMangaledMatch, functionManglingPattern)) { + std::string functionMangaledName = functionMangaledMatch[1].str(); + unique_ptr unMangledName( + abi::__cxa_demangle(functionMangaledName.c_str(), nullptr, 0, &status), &std::free); + + //Get file and line + ChildProcess childProcess = Process::SpawnChildProcess("addr2line", "addr2line", (string("--exe=") + Environment::Instance().GetProcessPath().c_str() + + Environment::Instance().GetProcessName().c_str()).c_str(), functionMangaledMatch[3].str().c_str(), (const char*)NULL); + + char buffer[1024] = {0}; + PLATFORM_VERIFY(read(childProcess.GetStdOutPipe().GetReadDescriptor(), + buffer, 1024) != -1); + if( strlen(buffer) > 0) + { + static regex fileNameLinePattern("([a-zA-Z0-9]*.[a-zA-Z0-9]*):([0-9]*)"); + cmatch fileNameLineMatch; + assert(regex_search(buffer, fileNameLineMatch, fileNameLinePattern)); + std::string fileName = fileNameLineMatch.size() > 1 ? fileNameLineMatch[1].str() : std::string(); + std::string line = fileNameLineMatch.size() > 2 ? fileNameLineMatch[2].str() : std::string(); + return make_tuple( fileName.size() ? fileName : unknown, line.size() ? line : unknown, unMangledName && strlen(unMangledName.get()) > 0 ? std::string(unMangledName.get()) : functionMangaledName); + } + + return make_tuple(unknown, unknown, unMangledName && strlen(unMangledName.get()) > 0 ? std::string(unMangledName.get()) : functionMangaledName); + + } +#endif + return make_tuple(unknown, unknown, unknown); + } + + void Logger::SetImpl(unique_ptr loggerImpl) + { + swap(m_loggerImpl, loggerImpl); + } + + void Logger::Start(TraceSeverity severity) + { + if(m_loggerImpl.get() == nullptr) + m_loggerImpl.reset(new DefaultLogger()); + assert(!m_running.exchange(true, std::memory_order_relaxed)); + m_loggerImpl->Start(severity); + m_severity = severity; + } + void Logger::Log(TraceSeverity severity, const char* message) + { + assert(m_loggerImpl.get() != nullptr); + m_loggerImpl->Log(severity, message); + } + + void Logger::Flush() + { + assert(m_loggerImpl.get() != nullptr); + m_loggerImpl->Flush(); + } + + void Logger::AddListener(const shared_ptr& listener) + { + assert(m_loggerImpl.get() != nullptr); + m_loggerImpl->AddListener(listener); + } + + void Logger::Terminate() + { + m_loggerImpl.release(); + } + +} diff --git a/src/Logger.h b/src/Logger.h new file mode 100644 index 0000000..7a260d8 --- /dev/null +++ b/src/Logger.h @@ -0,0 +1,174 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(__linux) +#include +#endif +#include "Source.h" +#include "LoggerImpl.h" +#include "Export.h" + +namespace core +{ + const int ORIGINAL_STACK_FRAMES_GUESS = 20; //20 is arbitrary + class TraceListener; + enum TraceSeverity : short + { + Verbose = 1, + Info, + Fatal = 4, + NoneWorking = 5 + }; + + class Logger + { + private: + template + struct Comperator + { + static const bool value = sizeof...(Args) == 0; + }; + public: + CORE_EXPORT static Logger& Instance(); + CORE_EXPORT ~Logger(); //add nullptr to release the blocked wait. not by cancel of the thread. + void AddListener(const std::shared_ptr& listener); + std::string BuildMessage(const Source& source, const char* format, ...); + void SetImpl(std::unique_ptr loggerImpl); + CORE_EXPORT void Start(TraceSeverity severity); + CORE_EXPORT void Terminate(); + template + void Trace(TraceSeverity severity, const Source& source, const char* format, Args... args) + { + ValidateParams(); + std::string message = BuildMessage(source, format, args...); + Log(severity, message.c_str()); + } + template + static typename std::enable_if::value>::type ValidateParams(){} //Due to VS2013 limitation on expression SFIANE + template + static void ValidateParams(){ + static_assert(std::is_same::value == false, "Format only supports c-type string as type, don't use string"); + ValidateParams(); + } + + void PrintStack() + { +#if defined(__linux) + //Trace the entire stack frames: + //Get the stack frames data + void** stackFramesAddresses = (void**)malloc(sizeof(void*)*ORIGINAL_STACK_FRAMES_GUESS); + int stackFramesSize = ORIGINAL_STACK_FRAMES_GUESS; + int readFramesCount; + while(stackFramesSize == (readFramesCount = backtrace(stackFramesAddresses, stackFramesSize))) + { + free(stackFramesAddresses); + stackFramesSize*=2; + stackFramesAddresses = (void**)malloc(sizeof(void*)*stackFramesSize); + } + //Get the symbols + char** stackFramesSymbols = backtrace_symbols(stackFramesAddresses, readFramesCount); + for(int index = 0; index < readFramesCount; index++){ + auto frameInformation = GetFunctionAndLine(stackFramesSymbols[index]); + Trace(TraceSeverity::Fatal, __CORE_SOURCE, "%s:%s:%s", std::get<0>(frameInformation).c_str(), + std::get<1>(frameInformation).c_str(), std::get<2>(frameInformation).c_str()); + } + free(stackFramesAddresses); + free(stackFramesSymbols); +#endif + } + CORE_EXPORT void Log(TraceSeverity severity, const char* message); + CORE_EXPORT void Flush(); + CORE_EXPORT TraceSeverity GetSeverity() const { return m_severity; } + + private: + using FunctionName = std::string; + using Line = std::string; + using FileName = std::string; + + Logger(); + std::tuple GetFunctionAndLine(char* mangledSymbol); + void SetDefaultLogger(); + + private: + std::list> m_listeners; + std::unique_ptr m_loggerImpl; + std::atomic_bool m_running; + TraceSeverity m_severity; + mutable std::mutex m_mut; + static const int Local_buffer_size = 2000; + }; + + + inline std::string Logger::BuildMessage(const Source& source, const char* format, ...) + { + va_list arguments; + va_start(arguments, format); + std::string result; + + char buf[Local_buffer_size] = ""; +#if defined(WIN32) + int size = _snprintf_s(buf, Local_buffer_size, Local_buffer_size - 1, "%s:%s:%d\t", source.file, + source.function, source.line); +#else + int size = snprintf(buf, Local_buffer_size, "%s:%s:%d\t", source.file, source.function, source.line); + assert(size >= 0); +#endif + assert(size != -1 && size < Local_buffer_size); //In windows version -1 is a legit answer +#if defined(WIN32) + int tempSize = vsprintf_s(buf + size, Local_buffer_size - size, format, arguments); + tempSize != -1 ? size += tempSize : size = -1; +#else + int tempSize = vsnprintf(buf + size, Local_buffer_size - size, format, arguments); + assert(tempSize >=0); + size += tempSize; +#endif + + if(size != -1 && size < Local_buffer_size) + result = buf; + else //message was trunced or operation failed + { + int bufferSize = std::max(size, 32 * 1024); + std::vector largerBuf; + largerBuf.resize(bufferSize); +#if defined(WIN32) + int largerSize = _snprintf_s(&largerBuf[0], bufferSize, bufferSize - 1, "%s:%s:%d\t", source.file, source.function, source.line); +#else + int largerSize = snprintf(&largerBuf[0], bufferSize, "%s:%s:%d\t", source.file, source.function, source.line); + assert(largerSize >= 0); +#endif + assert(largerSize != -1 && largerSize < bufferSize); //In windows version -1 is a legit answer +#if defined(WIN32) + vsprintf_s(&largerBuf[largerSize], bufferSize - largerSize, format, arguments); //We will print what we can, no second resize. +#else + int remainSize = vsnprintf(&largerBuf[largerSize], bufferSize - largerSize, format, arguments); + assert(remainSize >= 0); //We will print what we can, no second resize. +#endif + result = std::string(largerBuf.begin(), largerBuf.end()); + } + + va_end(arguments); + return result; + } +} + + +#define TRACE_IMPL(severity, ...)\ + if(severity >= core::Logger::Instance().GetSeverity()) \ + core::Logger::Instance().Trace(severity, __CORE_SOURCE, __VA_ARGS__) + +#define TRACE_ERROR(...) \ + TRACE_IMPL(core::TraceSeverity::Fatal, __VA_ARGS__) +#define TRACE_INFO(...) \ + TRACE_IMPL(core::TraceSeverity::Info, __VA_ARGS__) +#define TRACE_VERBOSE(...) \ + TRACE_IMPL(core::TraceSeverity::Verbose, __VA_ARGS__) diff --git a/src/LoggerImpl.h b/src/LoggerImpl.h new file mode 100644 index 0000000..e768666 --- /dev/null +++ b/src/LoggerImpl.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace core +{ + enum TraceSeverity : short; + class TraceListener; + + class LoggerImpl + { + public: + virtual ~LoggerImpl(){} + virtual void Start(TraceSeverity) = 0; + virtual void Log(TraceSeverity, const std::string&) = 0; + virtual void Flush() = 0; + virtual void AddListener(const std::shared_ptr& listener) = 0; + }; +} diff --git a/src/NoExcept.h b/src/NoExcept.h new file mode 100644 index 0000000..c5fe330 --- /dev/null +++ b/src/NoExcept.h @@ -0,0 +1,7 @@ +#pragma once + +#if defined(WIN32) +#define NOEXCEPT(expression) +#else +#define NOEXCEPT(expression) noexcept(expression) +#endif \ No newline at end of file diff --git a/src/Source.h b/src/Source.h new file mode 100644 index 0000000..ef3cb0e --- /dev/null +++ b/src/Source.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace core { + + struct Source { + const char *file; + const char *function; + int line; + }; +} + +#define __CORE__FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define __CORE_SOURCE core::Source{__CORE__FILENAME__, __FUNCTION__, __LINE__} + diff --git a/src/SpanContainer.cpp b/src/SpanContainer.cpp index addb52f..19bf740 100644 --- a/src/SpanContainer.cpp +++ b/src/SpanContainer.cpp @@ -1,4 +1,4 @@ -#include "core/Exception.h" +#include "Exception.h" #include "SpanContainer.h" using namespace std; diff --git a/src/TransportType.h b/src/TransportType.h index 68f2134..88c1819 100644 --- a/src/TransportType.h +++ b/src/TransportType.h @@ -1,6 +1,6 @@ #pragma once -#include "core/Enumeration.h" +#include "Enumeration.h" #include "Export.h" namespace cppkin diff --git a/src/span_impl.h b/src/span_impl.h index 1772711..f75cf31 100644 --- a/src/span_impl.h +++ b/src/span_impl.h @@ -4,8 +4,8 @@ #include #include #include -#include "core/Assert.h" -#include "core/Environment.h" +#include "Assert.h" +#include "Environment.h" #include "Annotation.h" #include "BinaryAnnotation.h" #include "SimpleTag.h" From 4f6d32da144282419279052a1f9ccee04a39d5c3 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 14:32:11 +0000 Subject: [PATCH 35/43] Move libCore code into cppkin --- CMakeLists.txt | 2 +- src/BinaryAnnotation.cpp | 2 +- src/ChildProcess.cpp | 39 +++++ src/ChildProcess.h | 26 +++ src/ConfigParams.cpp | 2 +- src/DefaultLogger.cpp | 24 +++ src/DefaultLogger.h | 21 +++ src/DefaultTraceListeners.cpp | 21 +++ src/DefaultTraceListeners.h | 21 +++ src/Directory.cpp | 38 +++++ src/Directory.h | 32 ++++ src/GeneralParams.h | 123 ++++++++++++++ src/Param.h | 307 ++++++++++++++++++++++++++++++++++ src/Pipe.cpp | 41 +++++ src/Pipe.h | 32 ++++ src/Process.cpp | 5 + src/Process.h | 72 ++++++++ src/SimpleTag.cpp | 2 +- src/Thread.h | 77 +++++++++ src/TraceListener.h | 17 ++ src/TransportFactory.h | 2 +- src/TransportManager.h | 2 +- src/TypeTraits.h | 12 ++ src/cppkin.cpp | 4 +- src/cppkin.h | 2 +- 25 files changed, 917 insertions(+), 9 deletions(-) create mode 100644 src/ChildProcess.cpp create mode 100644 src/ChildProcess.h create mode 100644 src/DefaultLogger.cpp create mode 100644 src/DefaultLogger.h create mode 100644 src/DefaultTraceListeners.cpp create mode 100644 src/DefaultTraceListeners.h create mode 100644 src/Directory.cpp create mode 100644 src/Directory.h create mode 100644 src/GeneralParams.h create mode 100644 src/Param.h create mode 100644 src/Pipe.cpp create mode 100644 src/Pipe.h create mode 100644 src/Process.cpp create mode 100644 src/Process.h create mode 100644 src/Thread.h create mode 100644 src/TraceListener.h create mode 100644 src/TypeTraits.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2072a3f..fc97acc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ if(COMPILATION_STEP) set(TO_LINK_LIBS pthread curl) endif() - set(CPPKIN_SOURCES src/Export.h src/Assert.h src/Environment.h src/Environment.cpp src/Logger.h src/Logger.cpp src/LoggerImpl.h src/NoExcept.h src/Source.h src/Enumeration.h src/Exception.h src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) + set(CPPKIN_SOURCES src/DefaultTraceListeners.h src/DefaultTraceListeners.cpp src/Thread.h src/GeneralParams.h src/Param.h src/DefaultLogger.h src/DefaultLogger.cpp src/TypeTraits.h src/ChildProcess.h src/ChildProcess.cpp src/Pipe.h src/Pipe.cpp src/Process.h src/Process.cpp src/TraceListener.h src/Directory.h src/Directory.cpp src/Export.h src/Assert.h src/Environment.h src/Environment.cpp src/Logger.h src/Logger.cpp src/LoggerImpl.h src/NoExcept.h src/Source.h src/Enumeration.h src/Exception.h src/Trace.h src/SpanContainer.h src/SpanContainer.cpp src/span_impl.cpp src/span_impl.h src/AnnotationType.cpp src/AnnotationType.h src/Annotation.h src/SimpleAnnotation.cpp src/SimpleAnnotation.h src/cppkin.h src/Trace.cpp src/Encoder.cpp src/Encoder.h src/EncodingTypes.cpp src/EncodingTypes.h src/EncodingContext.cpp src/EncodingContext.h src/TransportManager.cpp src/TransportManager.h src/Transport.cpp src/Transport.h src/HttpTransport.cpp src/HttpTransport.h src/ConfigTags.h src/TransportType.cpp src/TransportType.h src/TransportFactory.h src/TransportFactory.cpp src/ConfigParams.cpp src/ConfigTags.cpp src/Annotation.cpp src/Sampler.cpp src/JsonEncoder.h src/cppkin.cpp src/Export.h src/Span.cpp src/Span.h src/BinaryAnnotation.cpp src/SimpleTag.cpp) add_library(cppkin-shared SHARED ${CPPKIN_SOURCES}) set_target_properties(cppkin-shared PROPERTIES OUTPUT_NAME cppkin) diff --git a/src/BinaryAnnotation.cpp b/src/BinaryAnnotation.cpp index 49c596e..6a68720 100644 --- a/src/BinaryAnnotation.cpp +++ b/src/BinaryAnnotation.cpp @@ -1,5 +1,5 @@ #include "BinaryAnnotation.h" -#include "core/Exception.h" +#include "Exception.h" #include "boost/variant/get.hpp" namespace cppkin diff --git a/src/ChildProcess.cpp b/src/ChildProcess.cpp new file mode 100644 index 0000000..e5d2573 --- /dev/null +++ b/src/ChildProcess.cpp @@ -0,0 +1,39 @@ +#include "ChildProcess.h" +#if defined(__linux) +#include +#include +#endif +#include "Pipe.h" +#include "Assert.h" + +using namespace std; + +namespace core{ + ChildProcess::ChildProcess(int processID, unique_ptr& stdOutputPipe, + unique_ptr& stdErrorPipe): m_processID(processID), + m_stdOutput(move(stdOutputPipe)), m_stdError(move(stdErrorPipe)){ + m_stdOutput->CloseWriteDescriptor(); + m_stdError->CloseWriteDescriptor(); + } + + ChildProcess::ChildProcess(core::ChildProcess &&object) NOEXCEPT(true) + : m_processID(object.m_processID), m_stdOutput(std::move(object.m_stdOutput)), m_stdError(std::move(object.m_stdError)){} + + ChildProcess& ChildProcess::operator=(core::ChildProcess &&rhs) NOEXCEPT(true) + { + m_processID = rhs.m_processID; + m_stdOutput = std::move(rhs.m_stdOutput); + m_stdError = std::move(rhs.m_stdError); + return *this; + } + + void ChildProcess::wait() + { +#if defined(__linux) + int status; + ::waitpid(m_processID, &status, 0); + VERIFY(WIFEXITED(status), "Process %d didn't exit sucesfully", m_processID); +#endif + } +} + diff --git a/src/ChildProcess.h b/src/ChildProcess.h new file mode 100644 index 0000000..eac8b52 --- /dev/null +++ b/src/ChildProcess.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "NoExcept.h" + +namespace core { + class Pipe; +} + +namespace core{ + class ChildProcess { + public: + ChildProcess(int processID, std::unique_ptr& stdOutputPipe, + std::unique_ptr& stdErrorPipe); + ChildProcess(ChildProcess&& object) NOEXCEPT(true); + ChildProcess& operator=(ChildProcess&& rhs) NOEXCEPT(true); + const Pipe& GetStdOutPipe(){return *m_stdOutput;} + const Pipe& GetStdErrorPipe(){return *m_stdError;} + void wait(); + + private: + int m_processID; + std::unique_ptr m_stdOutput; + std::unique_ptr m_stdError; + }; +} diff --git a/src/ConfigParams.cpp b/src/ConfigParams.cpp index 9fbc14e..f28511c 100644 --- a/src/ConfigParams.cpp +++ b/src/ConfigParams.cpp @@ -1,5 +1,5 @@ #include "ConfigParams.h" -#include "core/GeneralParams.h" +#include "GeneralParams.h" #include "ConfigTags.h" using namespace std; diff --git a/src/DefaultLogger.cpp b/src/DefaultLogger.cpp new file mode 100644 index 0000000..0cd79df --- /dev/null +++ b/src/DefaultLogger.cpp @@ -0,0 +1,24 @@ +#include "DefaultLogger.h" +#include "Exception.h" + +namespace core +{ + DefaultLogger::~DefaultLogger() {} + + void DefaultLogger::Start(TraceSeverity severity) { + m_listener.SetSeverity(severity); + } + + void DefaultLogger::Log(TraceSeverity severity, const std::string &msg) { + m_listener.Log(severity, msg); + } + + void DefaultLogger::Flush() { + m_listener.Flush(); + } + + void DefaultLogger::AddListener(const std::shared_ptr &listener) { + throw Exception(__CORE_SOURCE, "Adding listeners to default logger is not possible."); + } +} + diff --git a/src/DefaultLogger.h b/src/DefaultLogger.h new file mode 100644 index 0000000..68bd5a1 --- /dev/null +++ b/src/DefaultLogger.h @@ -0,0 +1,21 @@ +#pragma once + +#include "LoggerImpl.h" +#include "DefaultTraceListeners.h" + +namespace core +{ + class DefaultLogger: public LoggerImpl + { + public: + virtual ~DefaultLogger(); + void Start(TraceSeverity severity) override; + void Log(TraceSeverity severity, const std::string& msg) override; + void Flush() override; + void AddListener(const std::shared_ptr& listener) override; + + private: + StdOutListener m_listener; + }; +} + diff --git a/src/DefaultTraceListeners.cpp b/src/DefaultTraceListeners.cpp new file mode 100644 index 0000000..3048bf1 --- /dev/null +++ b/src/DefaultTraceListeners.cpp @@ -0,0 +1,21 @@ +#include "DefaultTraceListeners.h" +#include + +namespace core +{ + void StdOutListener::Log(TraceSeverity severity, const std::string &msg) + { + if( m_severity <= severity) + std::cout< +#include +#include "TraceListener.h" + +namespace core +{ + class StdOutListener : public TraceListener + { + public: + virtual ~StdOutListener(){} + void Log(TraceSeverity severity, const std::string &msg) override; + void Flush() override; + void SetSeverity(TraceSeverity severity) override; + + private: + TraceSeverity m_severity; + }; +} + diff --git a/src/Directory.cpp b/src/Directory.cpp new file mode 100644 index 0000000..941c0ce --- /dev/null +++ b/src/Directory.cpp @@ -0,0 +1,38 @@ +#include "Directory.h" +#include "Assert.h" +#if defined(__linux) +#include +#include +#endif + +namespace core{ + std::string Directory::GetDirctoryFullPath(const std::string& path) + { + size_t position = path.find_last_of('/'); + return std::string(path.data(), position != std::string::npos ? position : path.length()); + } + + std::string Directory::GetFileName(const std::string &path) + { + size_t position = path.find_last_of('/'); + return std::string(path.begin() + position, path.end()); + } + + void Directory::CreateDirectory(const std::string &path, std::tuple &permission) + { + #if defined(__linux) + mode_t mode = 0; + mode = mode | (char)std::get(permission); + mode = mode | (((char)std::get(permission)) << (PermissionGroup::GROUP * 8)); + mode = mode | (((char)std::get(permission)) << (PermissionGroup::USERS * 8)); + PLATFORM_VERIFY(0 == ::mkdir(path.c_str(), mode)); + #endif + } + + void Directory::RemoveDirectory(const std::string &path) + { + #if defined(__linux) + PLATFORM_VERIFY(0 == ::rmdir(path.c_str())); + #endif + } +} diff --git a/src/Directory.h b/src/Directory.h new file mode 100644 index 0000000..977a58b --- /dev/null +++ b/src/Directory.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +namespace core +{ + class Directory + { + public: + enum Permission + { + READ_ONLY = 4, + WRITE_ONLY = 2, + EXECUTE_ONLY = 1, + READ_WRITE_ONLY = 6, + READ_EXECUTE_ONLY = 5, + WRITE_EXECUTE_ONLY = 3, + ALL = 7 + }; + enum PermissionGroup + { + OTHERS = 0, + GROUP = 1, + USERS = 2 + }; + static std::string GetDirctoryFullPath(const std::string& path); + static std::string GetFileName(const std::string& path); + static void CreateDirectory(const std::string& path, std::tuple& permission); + static void RemoveDirectory(const std::string& path); + }; +} diff --git a/src/GeneralParams.h b/src/GeneralParams.h new file mode 100644 index 0000000..ef349fd --- /dev/null +++ b/src/GeneralParams.h @@ -0,0 +1,123 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include "Assert.h" +#include "Exception.h" +#include "Param.h" + +namespace core +{ + class GeneralParams + { + private: + typedef std::unique_ptr ParamPtr; + typedef std::pair ParamPair; + typedef std::vector Params; + + public: + GeneralParams() = default; + ~GeneralParams() = default; + GeneralParams(const GeneralParams& obj) + { + Copy(obj); + } + GeneralParams& operator=(const GeneralParams& rhs) + { + Copy(rhs); + } + GeneralParams(GeneralParams&& obj) + :m_params(std::move(obj.m_params)){} + GeneralParams& operator=(GeneralParams&& rhs) + { + m_params = std::move(rhs.m_params); + } + template + void AddParam(const char* key, X&& value) + { + auto comparator = [&key](const ParamPair& pair) -> bool {return pair.first == key;}; + if(std::find_if(m_params.begin(), m_params.end(), comparator) == m_params.end()) + { + auto param = MakeParam(std::forward(value)); + m_params.push_back(std::make_pair(key, std::move(param))); + } + else + { + throw core::Exception(__CORE_SOURCE, "Requested key already exists - %s", key); + } + } + template::value && + std::is_copy_constructible::value, int>::type = 0> + T Get(const char* key) const + { + auto comparator = [&key](const ParamPair& pair) -> bool {return pair.first == key;}; //redundancy from above, but never mind :) + std::vector::const_iterator it = std::find_if(m_params.begin(), m_params.end(), comparator); + if(it == m_params.end()) + throw Exception(__CORE_SOURCE, "Non existing parameter was requested %s", key); + else + { + TypedParam& param = static_cast&>(*it->second); + return param.template Get(); + } + } + bool Exists( const char* key ) const + { + + auto comparator = [&key](const ParamPair& pair) -> bool {return pair.first == key;}; //redundancy from above, but never mind :) + std::vector::const_iterator it = std::find_if(m_params.begin(), m_params.end(), comparator); + return it != m_params.end(); + } + + private: + void Copy(const GeneralParams& obj) { + Params params; + for (auto ¶mPair: obj.m_params) + { + static ParamPtr toParam; + Param& param = *paramPair.second; + + if (param.IsShort()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsInt()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsLong()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsBool()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsFloat()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsDouble()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsPointer()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsCtypeS()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsString()) { + TypedParam &typedElement = static_cast &>(param); + toParam.reset(new TypedParam(typedElement)); + } else if (param.IsStringArray()) { + TypedParam> &typedElement = static_cast> &>(param); + toParam.reset(new TypedParam>(typedElement)); + } + + params.emplace_back(std::make_pair(paramPair.first, std::move(toParam))); + } + std::swap(m_params, params); + } + + private: + Params m_params; + }; +} diff --git a/src/Param.h b/src/Param.h new file mode 100644 index 0000000..65dc6c9 --- /dev/null +++ b/src/Param.h @@ -0,0 +1,307 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include "Exception.h" + +namespace core +{ +#define ARGUMENTS short, int, long, float, double, bool, void*, char*, std::string, std::vector + + template + struct typeid_impl{}; + + template + struct typeid_impl + { + const static int value = -1; + }; + + + template + struct typeid_impl + { + const static int value = 0; + }; + + template + struct typeid_impl + { + const static int value = typeid_impl::value != -1 ? typeid_impl::value + 1 : -1; + }; + + template + struct IsTypeIdExists + { + const static bool value = typeid_impl::value != -1; + }; + + template + struct TypeId + { + const static int value = typeid_impl::value; + }; + +#define IS_INTEGRAL(NAME, TYPE) \ + bool Is##NAME() const\ + { \ + return m_typeId == TypeId::value; \ + } + + class Param + { + public: + typedef std::unique_ptr Param_Ptr; + + Param(int typeId, char* rawBuffer = nullptr):m_typeId(typeId), m_rawBuffer(rawBuffer) + { + if(m_typeId == -1) + throw core::Exception(__CORE_SOURCE, "Non supported type"); + } + virtual ~Param() = default; + virtual bool operator==(const Param& rhs) const{ return m_typeId == rhs.m_typeId; } + virtual bool operator!=(const Param& rhs) const{ return !(*this == rhs); } + + IS_INTEGRAL(Short, short); + IS_INTEGRAL(Int, int); + IS_INTEGRAL(Long, long); + IS_INTEGRAL(Float, float); + IS_INTEGRAL(Double, double); + IS_INTEGRAL(Bool, bool); + IS_INTEGRAL(Pointer, void*); + IS_INTEGRAL(CtypeS, char*); + IS_INTEGRAL(String, std::string); + IS_INTEGRAL(StringArray, std::vector); + + char* GetBuffer(){ return m_rawBuffer; } + virtual Param_Ptr Clone() = 0; + + protected: + int m_typeId; + char* m_rawBuffer; + }; + + template + class TypedParam : public Param + { + public: + typedef typename std::remove_reference::type Type; + typedef TypedParam _Self; + + explicit TypedParam(X&& value) : + Param(TypeId::value != -1 ? + TypeId::value : typeid(Type).hash_code()) + { + if(m_typeId == TypeId::value) + { + char** valuePtr = const_cast(reinterpret_cast(&value)); + m_rawBuffer = *valuePtr; + *valuePtr = nullptr; + } + else if(m_typeId == TypeId::value) + { + static_assert(sizeof(void*) == sizeof(char*), "A size mismatch"); + char** valuePtr = const_cast(reinterpret_cast(&value)); + m_rawBuffer = *valuePtr; + if(*valuePtr != nullptr) + *valuePtr = nullptr; + } + else + { + m_rawBuffer = new char[sizeof(Type)]; + new (m_rawBuffer) Type(std::move(value)); + } + } + + explicit TypedParam(X& value) : Param(TypeId::value != -1 ? + TypeId::value : typeid(Type).hash_code()) + { + if(m_typeId == TypeId::value) + { + char** valuePtr = reinterpret_cast(const_cast(&value)); + size_t size = strlen(*valuePtr); + m_rawBuffer = new char[size + 1]; + memcpy(m_rawBuffer, *valuePtr, size); + m_rawBuffer[size] = '\0'; + } + else if(m_typeId == TypeId::value) + { + static_assert(sizeof(void*) == sizeof(char*), "A size mismatch"); + char*const* valuePtr = reinterpret_cast(&value); + m_rawBuffer = *valuePtr; + } + else + { + m_rawBuffer = new char[sizeof(Type)]; + new (m_rawBuffer) Type(value); + } + } + + explicit TypedParam(const X& value) : Param(TypeId::value != -1 ? + TypeId::value : typeid(Type).hash_code()) //const char* and const void* will not be diverted to here due to the fact const X&, X=char*->char* const& + { + m_rawBuffer = new char[sizeof(Type)]; + new (m_rawBuffer) Type(value); + } + + explicit TypedParam(const char*& value) : Param(TypeId::value) + { + static_assert(std::is_same::value,"Type mismatch - Type!=char*"); + size_t size = strlen(value); + m_rawBuffer = new char[size + 1]; + memcpy(m_rawBuffer, value, size); + m_rawBuffer[size] = '\0'; + } + + explicit TypedParam(const void*& value) : Param(TypeId::value, (char*)const_cast(value)) + { + static_assert(std::is_same::value,"Type mismatch - Type!=void*"); + } + + ~TypedParam() override + { + int typeId = TypeId::value != -1 ? TypeId::value + : typeid(Type).hash_code(); + if(m_typeId == typeId) //When Type==void* Param holds no ownership on the data. + return; + Type* typedBuffer = reinterpret_cast(m_rawBuffer); + typedBuffer->~Type(); + delete[] m_rawBuffer; + } + + TypedParam(const TypedParam& obj) : + Param(obj.m_typeId) + { + if(m_typeId == TypeId::value) + { + size_t size = strlen(obj.m_rawBuffer); + m_rawBuffer = new char[size + 1]; + memcpy(m_rawBuffer, obj.m_rawBuffer, size); + m_rawBuffer[size] = '\0'; + } + else if(m_typeId == TypeId::value) + { + static_assert(sizeof(void*) == sizeof(char*), "A size mismatch"); + char*const* valuePtr = reinterpret_cast(&obj.m_rawBuffer); + m_rawBuffer = *valuePtr; + } + else + { + m_rawBuffer = new char[sizeof(Type)]; + new (m_rawBuffer) Type(*reinterpret_cast(obj.m_rawBuffer)); + } + } + + TypedParam& operator=(const TypedParam& obj) + { + m_typeId = obj.m_typeId; + if(m_typeId == TypeId::value) + { + size_t size = strlen(obj.m_rawBuffer); + m_rawBuffer = new char[size + 1]; + memcpy(m_rawBuffer, obj.m_rawBuffer, size); + m_rawBuffer[size] = '\0'; + } + else if(m_typeId == TypeId::value) + { + static_assert(sizeof(void*) == sizeof(char*), "A size mismatch"); + char*const* valuePtr = reinterpret_cast(&obj.m_rawBuffer); + m_rawBuffer = *valuePtr; + } + else + { + m_rawBuffer = new char[sizeof(Type)]; + new (m_rawBuffer) Type(*reinterpret_cast(obj.m_rawBuffer)); + } + return *this; + } + + TypedParam(TypedParam&& obj) + { + m_typeId = obj.m_typeId; + std::swap(m_rawBuffer, obj.m_rawBuffer); + } + + TypedParam& operator=(TypedParam&& obj) + { + m_typeId = obj.m_typeId; + m_rawBuffer = nullptr; + std::swap(m_rawBuffer, obj.m_rawBuffer); + return *this; + } + + bool operator==(const Param& rhs) const override + { + bool equal = Param::operator==(rhs); + + if(m_typeId == TypeId::value) + return equal && strcmp(m_rawBuffer, const_cast(rhs).GetBuffer()) == 0; + else + { + const Type& _instance = static_cast(rhs).Get(); + return equal && _instance == *reinterpret_cast(m_rawBuffer); + } + + } + + Param_Ptr Clone() override + { + return Param_Ptr(new _Self(*reinterpret_cast(m_rawBuffer))); + } + + template::value, bool>::type> + const Y& Get() const + { + int typeId = TypeId::value != -1 ? TypeId::value + : typeid(Y).hash_code(); + assert(typeId == m_typeId); + return *reinterpret_cast(m_rawBuffer); + } + + template::value, bool>::type> + char* Get() const + { + assert((TypeId::value) == m_typeId); + return m_rawBuffer; + } + + template::value, bool>::type> + void* Get() const + { + assert((TypeId::value) == m_typeId); + return (void*)m_rawBuffer; + } + }; + + template::type>::value && + !std::is_pointer::type>::value, bool>::type = true> //All integral types. + inline std::unique_ptr MakeParam(X&& val) + { + return std::unique_ptr(new TypedParam::type>::type>(std::forward(val))); + } + + template::type>::value && + std::is_pointer::type>::value, bool>::type = true> //For plain old data. + inline std::unique_ptr MakeParam(X&& val) + { + return std::unique_ptr(new TypedParam::type>::type>::type>::type>(std::forward(val))); + } + + template::type>::value && + std::is_lvalue_reference::value, bool>::type = true> + inline std::unique_ptr MakeParam(X&& val) //For array + { + char* _val = const_cast(val); //Force a conversion to T = const char*& + return std::unique_ptr(new TypedParam(_val)); + } +} + + + diff --git a/src/Pipe.cpp b/src/Pipe.cpp new file mode 100644 index 0000000..71c5569 --- /dev/null +++ b/src/Pipe.cpp @@ -0,0 +1,41 @@ +#include "Pipe.h" +#include "Assert.h" + +namespace core{ + Pipe::Pipe() { +#if defined (__linux) + PLATFORM_VERIFY(pipe(m_fds) != -1); +#endif + m_fdOpen[0] = true; + m_fdOpen[1] = true; + } + + Pipe::~Pipe(){ + if (m_fdOpen[0]){ +#if defined (__linux) + close(m_fds[0]); +#endif + } + if (m_fdOpen[1]){ +#if defined (__linux) + close(m_fds[1]); +#endif + } + } + + void Pipe::CloseReadDescriptor() { +#if defined (__linux) + PLATFORM_VERIFY(close(m_fds[0]) == 0); +#endif + m_fdOpen[0] = false; + } + + void Pipe::CloseWriteDescriptor() { +#if defined (__linux) + PLATFORM_VERIFY(close(m_fds[1]) == 0); +#endif + m_fdOpen[1] = false; + } +} + + diff --git a/src/Pipe.h b/src/Pipe.h new file mode 100644 index 0000000..d74a98d --- /dev/null +++ b/src/Pipe.h @@ -0,0 +1,32 @@ +#pragma once +#if defined(__linux) +#include +#endif +#include "Assert.h" + +namespace core{ + + class Pipe { + public: + enum DEFUALT_DESCRIPTORS{ + STD_OUT = 1, + STD_ERROR = 2 + }; + public: + Pipe(); + ~Pipe(); + Pipe(const Pipe&) = delete; + Pipe& operator=(const Pipe&) = delete; + + void CloseReadDescriptor(); + void CloseWriteDescriptor(); + int GetReadDescriptor() const { return m_fds[0]; } + int GetWriteDescriptor() const { return m_fds[1]; } + + private: +#define PIPE_FD_NUM 2 + int m_fds[PIPE_FD_NUM]; + bool m_fdOpen[PIPE_FD_NUM]; + }; + +} diff --git a/src/Process.cpp b/src/Process.cpp new file mode 100644 index 0000000..755b86a --- /dev/null +++ b/src/Process.cpp @@ -0,0 +1,5 @@ +#include "Process.h" +namespace core{ + +} + diff --git a/src/Process.h b/src/Process.h new file mode 100644 index 0000000..2e2915c --- /dev/null +++ b/src/Process.h @@ -0,0 +1,72 @@ +#pragma once +#include +#include +#include +#if defined(__linux) +#include +#endif +#include "Assert.h" +#include "Pipe.h" +#include "ChildProcess.h" +#include "TypeTraits.h" + +namespace core +{ + class Process { + private: + template + struct Comperator + { + static const bool value = sizeof...(Args) == 0; + }; + public: + template + static ChildProcess SpawnChildProcess(const char* processPath, Args... args){ + ValidateArgsType(); + + std::unique_ptr stdOutPipe(new Pipe()); + std::unique_ptr stdErrorPipe(new Pipe()); + pid_t processID = fork(); + PLATFORM_VERIFY(processID != -1); + if(processID == 0) { //child + stdOutPipe->CloseReadDescriptor(); + dup2(stdOutPipe->GetWriteDescriptor(), Pipe::STD_OUT); + stdErrorPipe->CloseReadDescriptor(); + dup2(stdErrorPipe->GetWriteDescriptor(), Pipe::STD_ERROR); + execlp(processPath, args...); + exit(0); + } + //Only parent will reach this part + return ChildProcess(processID, stdOutPipe, stdErrorPipe); + } + + template + static auto SpawnChildProcess(const Callable& function, Args&&... args) -> + typename std::enable_if::value, ChildProcess>::type + { + std::unique_ptr stdOutPipe(new Pipe()); + std::unique_ptr stdErrorPipe(new Pipe()); + pid_t processID = fork(); + PLATFORM_VERIFY(processID != -1); + if(processID == 0) { //child + stdOutPipe->CloseReadDescriptor(); + dup2(stdOutPipe->GetWriteDescriptor(), Pipe::STD_OUT); + stdErrorPipe->CloseReadDescriptor(); + dup2(stdErrorPipe->GetWriteDescriptor(), Pipe::STD_ERROR); + function(std::forward(args)...); + exit(0); + } + //Only parent will reach this part + return ChildProcess(processID, stdOutPipe, stdErrorPipe); + } + + private: + template + static typename std::enable_if::value>::type ValidateArgsType(){} + template + static void ValidateArgsType(){ + static_assert(std::is_same::value == true, "Format only supports c-type string as type"); + ValidateArgsType(); + } + }; +} diff --git a/src/SimpleTag.cpp b/src/SimpleTag.cpp index 7b6de48..020a4cb 100644 --- a/src/SimpleTag.cpp +++ b/src/SimpleTag.cpp @@ -1,5 +1,5 @@ #include "SimpleTag.h" -#include "core/Exception.h" +#include "Exception.h" #include "boost/variant/get.hpp" namespace cppkin diff --git a/src/Thread.h b/src/Thread.h new file mode 100644 index 0000000..c5c6161 --- /dev/null +++ b/src/Thread.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include "Assert.h" +#include "NoExcept.h" + +const int MAX_THREAD_NAME = 30; + +namespace core +{ + class Impl_Base + { + public: + virtual ~Impl_Base() NOEXCEPT(true)=default; + virtual void join() const = 0; + virtual std::thread::id get_id() const = 0; + }; + + template + class Thread_Impl : public Impl_Base + { + public: + typedef std::unique_ptr thread_ptr; + + Thread_Impl(const std::string& name, Callable func) + :m_name(name), m_func(func){ + m_thread.reset(new std::thread(std::bind(&Thread_Impl::entry_point, this))); + } + Thread_Impl()=delete; + Thread_Impl(const Thread_Impl&)=delete; + Thread_Impl& operator=(const Thread_Impl&)=delete; + ~Thread_Impl() NOEXCEPT(true) override = default; + + void join() const override { m_thread->join(); } + std::thread::id get_id() const override { return m_thread->get_id(); } + + void entry_point() + { + try{ + m_func(); + } + catch(const Exception&){} + catch(std::exception& e){ + TRACE_ERROR("%s", e.what()); + } + } + + private: + thread_ptr m_thread; + std::string m_name; + Callable m_func; + }; + class Thread + { + public: + template + Thread(const std::string& name, Callable func) + { + m_impl.reset(new Thread_Impl(name, func)); + } + ~Thread()=default; + Thread() = delete; + Thread(const Thread&) = delete; + void operator = (const Thread&) = delete; + std::thread::id get_id() const {return m_impl->get_id();} + void join() const {m_impl->join();}; + + private: + std::unique_ptr m_impl; + }; +} diff --git a/src/TraceListener.h b/src/TraceListener.h new file mode 100644 index 0000000..fc9d6d5 --- /dev/null +++ b/src/TraceListener.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace core +{ + enum TraceSeverity : short; + + class TraceListener + { + public: + virtual void Log(TraceSeverity severity, const std::string &msg) = 0; + virtual void Flush() = 0; + virtual void SetSeverity(TraceSeverity severity) = 0; + virtual ~TraceListener() {} + }; +} diff --git a/src/TransportFactory.h b/src/TransportFactory.h index aa178f5..d998349 100644 --- a/src/TransportFactory.h +++ b/src/TransportFactory.h @@ -2,7 +2,7 @@ #include #include -#include "core/Exception.h" +#include "Exception.h" #include "TransportType.h" #include "Transport.h" diff --git a/src/TransportManager.h b/src/TransportManager.h index 771b4fa..4f6063b 100644 --- a/src/TransportManager.h +++ b/src/TransportManager.h @@ -6,7 +6,7 @@ #include #include "Transport.h" #include "boost/lockfree/queue.hpp" -#include "core/Thread.h" +#include "Thread.h" #include "span_impl.h" namespace cppkin diff --git a/src/TypeTraits.h b/src/TypeTraits.h new file mode 100644 index 0000000..ec5aa41 --- /dev/null +++ b/src/TypeTraits.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace core{ + template + struct is_callable : std::is_constructible, Callable>{}; + + template + struct is_callable_ret : std::is_constructible, Callable>{}; +} \ No newline at end of file diff --git a/src/cppkin.cpp b/src/cppkin.cpp index a70d319..267b27f 100644 --- a/src/cppkin.cpp +++ b/src/cppkin.cpp @@ -1,6 +1,6 @@ #include "cppkin.h" -#include "core/Environment.h" -#include "core/Logger.h" +#include "Environment.h" +#include "Logger.h" #include "ConfigParams.h" #include "TransportManager.h" #include "SpanContainer.h" diff --git a/src/cppkin.h b/src/cppkin.h index d300bed..dd938b9 100644 --- a/src/cppkin.h +++ b/src/cppkin.h @@ -2,7 +2,7 @@ #include #include "Export.h" -#include "core/GeneralParams.h" +#include "GeneralParams.h" #include "ConfigTags.h" #include "Trace.h" #include "Span.h" From f2105853ed57384cc431929649c2ff4878f03ee0 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 14:49:41 +0000 Subject: [PATCH 36/43] Fix operator= --- src/GeneralParams.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GeneralParams.h b/src/GeneralParams.h index ef349fd..2cc23f5 100644 --- a/src/GeneralParams.h +++ b/src/GeneralParams.h @@ -29,12 +29,14 @@ namespace core GeneralParams& operator=(const GeneralParams& rhs) { Copy(rhs); + return *this; } GeneralParams(GeneralParams&& obj) :m_params(std::move(obj.m_params)){} GeneralParams& operator=(GeneralParams&& rhs) { m_params = std::move(rhs.m_params); + return *this; } template void AddParam(const char* key, X&& value) From e09dbbad73e173e9597c3d707521371872c48c69 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 14:53:20 +0000 Subject: [PATCH 37/43] Update dependencies. No longer need libCore as it has needed components have been merged into code base. rapidjson is now a submodule. --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 901f876..24db537 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,15 @@ cppkin is dependent upon - | ----------------------- | -----------| --------- | | boost | mandatory | >= 1.65.1 | | curl | mandatory | >= 7.54.1 | -| rapidjson | mandatory | >= 1.1.0 | -| core | mandatory | >= 1.1 | | pybind11 | python or tests | >= 2.2.4 | | bottle | tests | >= 0.12.13 | | google benchmark | tests | >= 1.3 | | thrift | only for scribe transport | >= 0.10 | ### Linux Install: -All mandatory packages besdies **core** can be fetched directly: +All mandatory packages can be fetched directly: ``` -apt-get install cmake pybind11-dev rapidjson-dev libcurl4-openssl-dev libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev +apt-get install cmake pybind11-dev libcurl4-openssl-dev libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev ``` Use the help command to review the different configuration arguments: From 9b26f2e1e188a7fda61aa1fb1f5d2e1270562bf6 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 14:58:17 +0000 Subject: [PATCH 38/43] Remove unneeded dependencies --- ubuntu1804.Dockerfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ubuntu1804.Dockerfile b/ubuntu1804.Dockerfile index 1f483e9..c5a16ea 100644 --- a/ubuntu1804.Dockerfile +++ b/ubuntu1804.Dockerfile @@ -1,16 +1,9 @@ FROM ubuntu:18.04 -RUN apt-get update && apt-get install -y wget git cmake pybind11-dev rapidjson-dev && \ +RUN apt-get update && apt-get install -y wget git cmake pybind11-dev && \ apt-get install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ apt-get install -y libboost-all-dev libaudit-dev software-properties-common -RUN add-apt-repository universe - -RUN wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb && \ - apt-get install ./packages-microsoft-prod.deb - -RUN apt-get update && apt-get install -y dotnet-sdk-2.1.105 - RUN mkdir /cppKin COPY CMakeLists.txt /cppKin COPY IDL/ /cppKin/IDL/ From f72477b86b1f2cdf102462e6198b900aeffb91d0 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 15:04:06 +0000 Subject: [PATCH 39/43] Remove unneeded dependencies --- ubuntu2004.Dockerfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index 1f7932f..efc2f2f 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -2,18 +2,11 @@ FROM ubuntu:20.04 ENV DEBIAN_FRONTEND=noninteractive -RUN apt update && apt install -y wget git cmake pybind11-dev rapidjson-dev && \ +RUN apt update && apt install -y wget git cmake pybind11-dev && \ apt install -y libcurl4-openssl-dev libblkid-dev e2fslibs-dev && \ apt install -y libboost-all-dev libaudit-dev software-properties-common && \ apt install -y build-essential -RUN wget https://download.visualstudio.microsoft.com/download/pr/f65a8eb0-4537-4e69-8ff3-1a80a80d9341/cc0ca9ff8b9634f3d9780ec5915c1c66/dotnet-sdk-3.1.201-linux-x64.tar.gz && \ - mkdir -p dotnet && \ - tar xvzf dotnet-sdk-3.1.201-linux-x64.tar.gz -C dotnet - -RUN export DOTNET_ROOT=/dotnet && \ - export PATH=$PATH:/dotnet - RUN mkdir /cppKin COPY CMakeLists.txt /cppKin COPY IDL/ /cppKin/IDL/ From d98726699813579ceba6a3482f04a14f190e54ba Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 16:12:15 +0000 Subject: [PATCH 40/43] Install needed headers --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc97acc..96dfa29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,8 +131,8 @@ if(COMPILATION_STEP) add_dependencies(cppkin-shared ${CPPKIN_DEPEND_LIST}) add_dependencies(cppkin-static ${CPPKIN_DEPEND_LIST}) endif() - set_target_properties(cppkin-shared PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") - set_target_properties(cppkin-static PROPERTIES PUBLIC_HEADER "src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") + set_target_properties(cppkin-shared PROPERTIES PUBLIC_HEADER "src/DefaultTraceListeners.h;src/Thread.h;src/GeneralParams.h;src/Param.h;src/DefaultLogger.h;src/TypeTraits.h;src/ChildProcess.h;src/Pipe.h;src/Process.h;src/TraceListener.h;src/Directory.h;src/Export.h;src/Assert.h;src/Environment.h;src/Logger.h;src/LoggerImpl.h;src/NoExcept.h;src/Source.h;src/Enumeration.h;src/Exception.h;src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") + set_target_properties(cppkin-static PROPERTIES PUBLIC_HEADER "src/DefaultTraceListeners.h;src/Thread.h;src/GeneralParams.h;src/Param.h;src/DefaultLogger.h;src/TypeTraits.h;src/ChildProcess.h;src/Pipe.h;src/Process.h;src/TraceListener.h;src/Directory.h;src/Export.h;src/Assert.h;src/Environment.h;src/Logger.h;src/LoggerImpl.h;src/NoExcept.h;src/Source.h;src/Enumeration.h;src/Exception.h;src/Trace.h;src/Annotation.h;src/cppkin.h;src/Span.h;src/AnnotationType.h;src/BinaryAnnotation.h;src/ValueTypes.h;src/SimpleTag.h;src/ConfigParams.h;src/ConfigTags.h;src/Encoder.h;src/EncodingContext.h;src/EncodingTypes.h;src/Export.h;src/HttpTransport.h;src/JsonEncoder.h;src/Sampler.h;src/ScribeTransport.h;src/SimpleAnnotation.h;src/span_impl.h;src/StubTransport.h;src/ThriftEncoder.h;src/Transport.h;src/TransportFactory.h;src/TransportManager.h;src/TransportType.h") if(WITH_PYTHON) set(binderLib "") @@ -192,10 +192,10 @@ if(COMPILATION_STEP) LIBRARY DESTINATION ${OUTPUT_DIR}/lib ARCHIVE DESTINATION ${OUTPUT_DIR}/lib ) - install(DIRECTORY ${PROJECT_3RD_LOC}/lib - DESTINATION ${OUTPUT_DIR} - FILES_MATCHING PATTERN "*.so" PATTERN "*.a" - ) + install(DIRECTORY ${PROJECT_3RD_LOC}/lib + DESTINATION ${OUTPUT_DIR} + FILES_MATCHING PATTERN "*.so" PATTERN "*.a" + ) endif() endif() From 410bde8eda6f8e4d41cadf41df07926c016da55c Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 18:13:29 +0000 Subject: [PATCH 41/43] Remove unneeded dependencies --- cmake/InstallCore.cmake | 64 ----------------------------------- cmake/installThirdParty.cmake | 3 -- 2 files changed, 67 deletions(-) delete mode 100644 cmake/InstallCore.cmake diff --git a/cmake/InstallCore.cmake b/cmake/InstallCore.cmake deleted file mode 100644 index a239143..0000000 --- a/cmake/InstallCore.cmake +++ /dev/null @@ -1,64 +0,0 @@ -if (NOT Core_FOUND) - if (WIN32) - include(cppkinMacro) - LinuxPath_ToWinPath(${PROJECT_3RD_LOC} INSTALL_DIR_WIN) - LinuxPath_ToWinPath(${PROJECT_3RD_LOC}/src/Core SOURCE_DIR_WIN) - - ExternalProject_Add(Core - URL https://github.com/Dudi119/Core/archive/v1.0.2.tar.gz - URL_MD5 07e01fac32428617adefc79f473425c5 - CONFIGURE_COMMAND cd ${SOURCE_DIR_WIN} && cmake -G "Visual Studio ${VC_VERSION}" -DCORE_3RD_PARTY_DIR:STRING=${INSTALL_DIR_WIN} -DCORE_SPDLOG_SUPPORT=OFF -DCORE_COMPILE_STEP=ON -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} . - BUILD_COMMAND cd ${SOURCE_DIR_WIN} && CMD /C msbuild Core.vcxproj /p:Configuration=${CMAKE_BUILD_TYPE} - INSTALL_COMMAND "" - TEST_COMMAND "" - DEPENDS SpdLog - ) - - ExternalProject_Add_Step(Core Core_Create_HeadersDir - COMMAND if not exist ${INSTALL_DIR_WIN}\\include\\core mkdir ${INSTALL_DIR_WIN}\\include\\core - DEPENDEES install - ) - ExternalProject_Add_Step(Core Core_Install_Headers - COMMAND xcopy ${SOURCE_DIR_WIN}\\src\\*.h ${INSTALL_DIR_WIN}\\include\\core /E - DEPENDEES install - ) - - ExternalProject_Add_Step(Core Core_Create_Libs_Dir - COMMAND if not exist ${INSTALL_DIR_WIN}\\lib mkdir ${INSTALL_DIR_WIN}\\lib - DEPENDEES install - ) - ExternalProject_Add_Step(Core Core_Install_Libs - COMMAND copy ${SOURCE_DIR_WIN}\\${CMAKE_BUILD_TYPE}\\Core${CMAKE_DEBUG_POSTFIX}.dll ${INSTALL_DIR_WIN}\\lib && copy ${SOURCE_DIR_WIN}\\${CMAKE_BUILD_TYPE}\\Core${CMAKE_DEBUG_POSTFIX}.lib ${INSTALL_DIR_WIN}\\lib - DEPENDEES install - ) - else() - ExternalProject_Add(Core - URL https://github.com/Dudi119/Core/archive/v1.0.2.tar.gz - URL_MD5 07e01fac32428617adefc79f473425c5 - CONFIGURE_COMMAND cd && cmake -DCORE_3RD_PARTY_DIR:STRING= -DCORE_SPDLOG_SUPPORT=OFF -DCORE_COMPILE_STEP=ON -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} . - BUILD_COMMAND cd && make - INSTALL_COMMAND mkdir -p /lib && cp /bin/libCore${CMAKE_DEBUG_POSTFIX}.so /lib - TEST_COMMAND "" - DEPENDS SpdLog - ) - - ExternalProject_Add_Step(Core Core_Install_Headers - COMMAND mkdir -p /include/core && sh -c "cp /src/*.h /include/core/" - DEPENDEES install - ) - - set(CPPKIN_DEPEND_LIST ${CPPKIN_DEPEND_LIST} Core) - set(CPPKIN_WRAPPER_DEPEND_LIST ${CPPKIN_WRAPPER_DEPEND_LIST} Core) - ExternalProject_Get_Property(Core INSTALL_DIR) - add_custom_target(Core_stub) - - - endif () - - ExternalProject_Get_Property(Core INSTALL_DIR) - - set (Core_ROOT_DIR ${INSTALL_DIR}) - set (Core_INCLUDE_DIR ${Core_ROOT_DIR}/include) - set (Core_LIBRARY_DIR ${Core_ROOT_DIR}/lib) - set (Core_FOUND YES) -endif () diff --git a/cmake/installThirdParty.cmake b/cmake/installThirdParty.cmake index 3909dae..df61348 100644 --- a/cmake/installThirdParty.cmake +++ b/cmake/installThirdParty.cmake @@ -2,9 +2,6 @@ include(ExternalProject) #In order to load the ExternalProject module and to add set_directory_properties(PROPERTIES EP_PREFIX ${PROJECT_3RD_LOC}) #Sets the prefix(dir) for all installations commands include(InstallSpdLog) include(InstallCURL) -include(InstallCore) -include(InstallRapidJson) -include(InstallBoost_Pack) if(WITH_PYTHON) if(${PYTHON_BINDING} STREQUAL "sweetPy") include(InstallSweetPy) From 6ac51397ba471d7e8fc1f711ad251d46e8fb27f9 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 18:29:13 +0000 Subject: [PATCH 42/43] Add submodule update --- .buildkite/pipeline.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index e7bb8d3..cd88ede 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,5 +1,7 @@ steps: - - command: "./scripts/build-and-push-container.sh cppkin ubuntu1804 $BUILDKITE_BRANCH" + - command: + - "git submodule update --init --recursive" + - "./scripts/build-and-push-container.sh cppkin ubuntu1804 $BUILDKITE_BRANCH" label: ":ubuntu: 18.04 Docker build cppkin" agents: queue: "automation-eks-docker-builder-fleet" @@ -7,7 +9,9 @@ steps: retry: automatic: true - - command: "./scripts/build-and-push-container.sh cppkin ubuntu2004 $BUILDKITE_BRANCH" + - command: + - "git submodule update --init --recursive" + - "./scripts/build-and-push-container.sh cppkin ubuntu2004 $BUILDKITE_BRANCH" label: ":ubuntu: 20.04 Docker build cppkin" agents: queue: "automation-eks-docker-builder-fleet" From 7f6ea4cb5e26587800e4523d8aa38bfc8d2c72b0 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 12 Sep 2020 18:36:09 +0000 Subject: [PATCH 43/43] Add rapidjson to image --- ubuntu1804.Dockerfile | 1 + ubuntu2004.Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/ubuntu1804.Dockerfile b/ubuntu1804.Dockerfile index c5a16ea..e124e6b 100644 --- a/ubuntu1804.Dockerfile +++ b/ubuntu1804.Dockerfile @@ -11,6 +11,7 @@ COPY LICENSE /cppKin COPY MANIFEST.in /cppKin COPY README.md /cppKin COPY Third_Party/ /cppKin/Third_Party +COPY external/ /cppKin/external COPY appveyor.yml /cppKin COPY bench/ /cppKin/bench COPY cmake/ /cppKin/cmake diff --git a/ubuntu2004.Dockerfile b/ubuntu2004.Dockerfile index efc2f2f..b5525c3 100644 --- a/ubuntu2004.Dockerfile +++ b/ubuntu2004.Dockerfile @@ -14,6 +14,7 @@ COPY LICENSE /cppKin COPY MANIFEST.in /cppKin COPY README.md /cppKin COPY Third_Party/ /cppKin/Third_Party +COPY external/ /cppKin/external COPY appveyor.yml /cppKin COPY bench/ /cppKin/bench COPY cmake/ /cppKin/cmake