From fd36b14342c311c59a7d472f52a1c12644bcc27d Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Sun, 15 Mar 2020 15:09:07 +0530 Subject: [PATCH] Basic Jaeger Tracing Added Signed-off-by: Abhinav Singh --- src/common/jaegerTracer.h | 26 ++++++++++++++++++++++++++ src/common/jaegerTracing.cc | 34 ++++++++++++++++++++++++++++++++++ src/rgw/rgw_aio.cc | 5 +++++ src/rgw/rgw_aio.h | 1 + src/rgw/rgw_main.cc | 6 ++++++ 5 files changed, 72 insertions(+) create mode 100644 src/common/jaegerTracer.h create mode 100644 src/common/jaegerTracing.cc diff --git a/src/common/jaegerTracer.h b/src/common/jaegerTracer.h new file mode 100644 index 0000000000000..44ddf3d2f7b79 --- /dev/null +++ b/src/common/jaegerTracer.h @@ -0,0 +1,26 @@ + + +#ifndef JAEGER_TRACER_ +#define JAEGER_TRACER_ + +#include +#include +#include + +class jTracer +{ +private: + static jaegertracing::Config configuration; +public: + jTracer() {} + static void loadYamlConfigFile(const char *); + void initTracer(const char *); + std::unique_ptr newSpan(const char *); + std::unique_ptr childSpan(const char *, const std::unique_ptr &); + std::unique_ptr followUpSpan(const char *, const std::unique_ptr &); + ~jTracer(){ + opentracing::Tracer::Global()->Close(); + } +}; + +#endif \ No newline at end of file diff --git a/src/common/jaegerTracing.cc b/src/common/jaegerTracing.cc new file mode 100644 index 0000000000000..eaab6cbdee8d3 --- /dev/null +++ b/src/common/jaegerTracing.cc @@ -0,0 +1,34 @@ + +#include +#include +#include "jaegerTracer.h" + +void jTracer::loadYamlConfigFile(const char *filePath) +{ + auto yaml = YAML::LoadFile(filePath); + jTracer::configuration = jaegertracing::Config::parse(yaml); +} + +void jTracer::initTracer(const char *tracerName) +{ + auto tracer = jaegertracing::Tracer::make( + tracerName, + jTracer::configuration, + jaegertracing::logging::consoleLogger()); + opentracing::Tracer::InitGlobal( + std::static_pointer_cast(tracer)); +} +std::unique_ptr newSpan(const char * spanName){ + auto Span=opentracing::Tracer::Global()->StartSpan(spanName); + return std::move(Span); +} +std::unique_ptr jTracer::childSpan(const char *spanName, const std::unique_ptr &parentSpan) +{ + auto Span = opentracing::Tracer::Global()->StartSpan(spanName, {opentracing::ChildOf(&parentSpan->context())}); + return std::move(Span); +} +std::unique_ptr jTracer::followUpSpan(const char *spanName, const std::unique_ptr &parentSpan) +{ + auto Span = opentracing::Tracer::Global()->StartSpan(spanName, {opentracing::FollowsFrom(&parentSpan->context())}); + return std::move(Span); +} diff --git a/src/rgw/rgw_aio.cc b/src/rgw/rgw_aio.cc index 48c83be98ac8a..46df8d110a08f 100644 --- a/src/rgw/rgw_aio.cc +++ b/src/rgw/rgw_aio.cc @@ -49,9 +49,14 @@ Aio::OpFunc aio_abstract(Op&& op) { return [op = std::move(op)] (Aio* aio, AioResult& r) mutable { constexpr bool read = std::is_same_v, librados::ObjectReadOperation>; auto s = new (&r.user_data) state(aio, r); + jTracer tracer; if constexpr (read) { + tracer.initTracer("Reading Started"); + auto span=tracer.newSpan("Aio Read Operation started"); r.result = r.obj.aio_operate(s->c, &op, &r.data); } else { + tracer.initTracer("Writing Started"); + auto span=tracer.newSpan("Aio Write Operation started"); r.result = r.obj.aio_operate(s->c, &op); } if (r.result < 0) { diff --git a/src/rgw/rgw_aio.h b/src/rgw/rgw_aio.h index c30de75ee2856..fad9de7af13b2 100644 --- a/src/rgw/rgw_aio.h +++ b/src/rgw/rgw_aio.h @@ -26,6 +26,7 @@ #include "services/svc_rados.h" // cant forward declare RGWSI_RADOS::Obj #include "rgw_common.h" +#include "common/jaegerTracer.h" #include "include/function2.hpp" diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index a3ca40e2cdf39..eb5cff0232df6 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -38,6 +38,9 @@ #include "rgw_frontend.h" #include "rgw_http_client_curl.h" #include "rgw_perf_counters.h" + +#include "common/jaegerTracer.h" + #ifdef WITH_RADOSGW_AMQP_ENDPOINT #include "rgw_amqp.h" #endif @@ -679,6 +682,9 @@ extern "C" { int radosgw_main(int argc, const char** argv) { + //loading the yaml configuration file for rgw + jTracer tracer; + tracer.loadYamlConfigFile("tracerConfiguration.yaml"); return radosgw_Main(argc, argv); }