diff --git a/REPO_LAYOUT.md b/REPO_LAYOUT.md index 2c057e88d24b5..88f9731cf8eab 100644 --- a/REPO_LAYOUT.md +++ b/REPO_LAYOUT.md @@ -71,8 +71,6 @@ currently implemented but that is the plan moving forward.) * These are the top level extension directories and associated namespaces: * [access_loggers/](/source/extensions/access_loggers): Access log implementations which use the `Envoy::Extensions::AccessLoggers` namespace. - * [http_tracers/](/source/extensions/http_tracers): HTTP tracers which use the - `Envoy::Extensions::HttpTracers` namespace. * [filters/http/](/source/extensions/filters/http): HTTP L7 filters which use the `Envoy::Extensions::HttpFilters` namespace. * [filters/listener/](/source/extensions/filters/listener): Listener filters which use the @@ -83,6 +81,8 @@ currently implemented but that is the plan moving forward.) `Envoy::Extensions::Resolvers` namespace. * [stat_sinks/](/source/extensions/stat_sinks): Stat sink implementations which use the `Envoy::Extensions::StatSinks` namespace. + * [tracers/](/source/extensions/tracers): Tracers which use the + `Envoy::Extensions::Tracers` namespace. * [transport_sockets/](/source/extensions/transport_sockets): Transport socket implementations which use the `Envoy::Extensions::TransportSockets` namespace. * Each extension is contained wholly in its own namespace. E.g., diff --git a/source/common/config/well_known_names.h b/source/common/config/well_known_names.h index 978c71cd85cb3..150b594a164bf 100644 --- a/source/common/config/well_known_names.h +++ b/source/common/config/well_known_names.h @@ -156,9 +156,11 @@ class HttpFilterNameValues { typedef ConstSingleton HttpFilterNames; /** - * Well-known HTTP tracer names. + * Well-known tracer names. + * TODO(mattklein123): Move this to extensions directory when the migration is complete. + * TODO(mattklein123): New tracers should use the well known name: envoy.tracers.name. */ -class HttpTracerNameValues { +class TracerNameValues { public: // Lightstep tracer const std::string LIGHTSTEP = "envoy.lightstep"; @@ -168,12 +170,12 @@ class HttpTracerNameValues { const std::string DYNAMIC_OT = "envoy.dynamic.ot"; }; -typedef ConstSingleton HttpTracerNames; +typedef ConstSingleton TracerNames; /** * Well-known stats sink names. * TODO(mattklein123): Move this to extensions directory when the migration is complete. - * TODO(mattklein123): New filters should use the well known name: envoy.stat_sinks.name. + * TODO(mattklein123): New sinks should use the well known name: envoy.stat_sinks.name. */ class StatsSinkNameValues { public: @@ -190,7 +192,8 @@ typedef ConstSingleton StatsSinkNames; /** * Well-known access log names. * TODO(mattklein123): Move this to extensions directory when the migration is complete. - * TODO(mattklein123): New filters should use the well known name: envoy.access_loggers.name. + * TODO(mattklein123): New access loggers should use the well known name: + * envoy.access_loggers.name. */ class AccessLogNameValues { public: diff --git a/source/common/tracing/BUILD b/source/common/tracing/BUILD index 8d7c4431322e8..3f1e4ddf8a90d 100644 --- a/source/common/tracing/BUILD +++ b/source/common/tracing/BUILD @@ -38,46 +38,3 @@ envoy_cc_library( "//source/common/runtime:uuid_util_lib", ], ) - -envoy_cc_library( - name = "opentracing_driver_lib", - srcs = [ - "opentracing_driver_impl.cc", - ], - hdrs = [ - "opentracing_driver_impl.h", - ], - external_deps = ["opentracing"], - deps = [ - ":http_tracer_lib", - ], -) - -envoy_cc_library( - name = "dynamic_opentracing_driver_lib", - srcs = [ - "dynamic_opentracing_driver_impl.cc", - ], - hdrs = [ - "dynamic_opentracing_driver_impl.h", - ], - deps = [ - ":http_tracer_lib", - ":opentracing_driver_lib", - ], -) - -envoy_cc_library( - name = "lightstep_tracer_lib", - srcs = [ - "lightstep_tracer_impl.cc", - ], - hdrs = [ - "lightstep_tracer_impl.h", - ], - external_deps = ["lightstep"], - deps = [ - ":http_tracer_lib", - ":opentracing_driver_lib", - ], -) diff --git a/source/exe/BUILD b/source/exe/BUILD index b108018e67da7..f93384d54c7ee 100644 --- a/source/exe/BUILD +++ b/source/exe/BUILD @@ -58,9 +58,6 @@ envoy_cc_library( srcs = ["main.cc"], deps = [ ":envoy_main_common_lib", - "//source/server/config/http:dynamic_opentracing_lib", - "//source/server/config/http:lightstep_lib", - "//source/server/config/http:zipkin_lib", ], ) diff --git a/source/extensions/all_extensions.bzl b/source/extensions/all_extensions.bzl index 6dbc3ecdbc038..f00f219746cac 100644 --- a/source/extensions/all_extensions.bzl +++ b/source/extensions/all_extensions.bzl @@ -22,5 +22,8 @@ def envoy_all_extensions(repository = ""): repository + "//source/extensions/stat_sinks/dog_statsd:config", repository + "//source/extensions/stat_sinks/metrics_service:config", repository + "//source/extensions/stat_sinks/statsd:config", + repository + "//source/extensions/tracers/dynamic_ot:config", + repository + "//source/extensions/tracers/lightstep:config", + repository + "//source/extensions/tracers/zipkin:config", ] diff --git a/source/extensions/tracers/common/ot/BUILD b/source/extensions/tracers/common/ot/BUILD new file mode 100644 index 0000000000000..29dd62e655f8a --- /dev/null +++ b/source/extensions/tracers/common/ot/BUILD @@ -0,0 +1,23 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_library", + "envoy_package", +) + +envoy_package() + +envoy_cc_library( + name = "opentracing_driver_lib", + srcs = [ + "opentracing_driver_impl.cc", + ], + hdrs = [ + "opentracing_driver_impl.h", + ], + external_deps = ["opentracing"], + deps = [ + "//source/common/tracing:http_tracer_lib", + ], +) diff --git a/source/common/tracing/opentracing_driver_impl.cc b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc similarity index 88% rename from source/common/tracing/opentracing_driver_impl.cc rename to source/extensions/tracers/common/ot/opentracing_driver_impl.cc index 0d70f3d7a99f4..ce6783410a96a 100644 --- a/source/common/tracing/opentracing_driver_impl.cc +++ b/source/extensions/tracers/common/ot/opentracing_driver_impl.cc @@ -1,4 +1,4 @@ -#include "common/tracing/opentracing_driver_impl.h" +#include "extensions/tracers/common/ot/opentracing_driver_impl.h" #include @@ -7,7 +7,10 @@ #include "common/common/utility.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Common { +namespace Ot { namespace { class OpenTracingHTTPHeadersWriter : public opentracing::HTTPHeadersWriter { @@ -117,19 +120,22 @@ void OpenTracingSpan::injectContext(Http::HeaderMap& request_headers) { } } -SpanPtr OpenTracingSpan::spawnChild(const Config&, const std::string& name, SystemTime start_time) { +Tracing::SpanPtr OpenTracingSpan::spawnChild(const Tracing::Config&, const std::string& name, + SystemTime start_time) { std::unique_ptr ot_span = span_->tracer().StartSpan( name, {opentracing::ChildOf(&span_->context()), opentracing::StartTimestamp(start_time)}); RELEASE_ASSERT(ot_span != nullptr); - return SpanPtr{new OpenTracingSpan{driver_, std::move(ot_span)}}; + return Tracing::SpanPtr{new OpenTracingSpan{driver_, std::move(ot_span)}}; } OpenTracingDriver::OpenTracingDriver(Stats::Store& stats) : tracer_stats_{OPENTRACING_TRACER_STATS(POOL_COUNTER_PREFIX(stats, "tracing.opentracing."))} {} -SpanPtr OpenTracingDriver::startSpan(const Config&, Http::HeaderMap& request_headers, - const std::string& operation_name, SystemTime start_time, - const Tracing::Decision tracing_decision) { +Tracing::SpanPtr OpenTracingDriver::startSpan(const Tracing::Config&, + Http::HeaderMap& request_headers, + const std::string& operation_name, + SystemTime start_time, + const Tracing::Decision tracing_decision) { // If tracing decision is no, and sampling decision is not communicated via tags, then // return a null span to indicate that tracing is not being performed. if (!tracing_decision.traced && !useTagForSamplingDecision()) { @@ -179,8 +185,11 @@ SpanPtr OpenTracingDriver::startSpan(const Config&, Http::HeaderMap& request_hea } active_span = tracer.StartSpanWithOptions(operation_name, options); RELEASE_ASSERT(active_span != nullptr); - return SpanPtr{new OpenTracingSpan{*this, std::move(active_span)}}; + return Tracing::SpanPtr{new OpenTracingSpan{*this, std::move(active_span)}}; } -} // namespace Tracing +} // namespace Ot +} // namespace Common +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/opentracing_driver_impl.h b/source/extensions/tracers/common/ot/opentracing_driver_impl.h similarity index 74% rename from source/common/tracing/opentracing_driver_impl.h rename to source/extensions/tracers/common/ot/opentracing_driver_impl.h index 9edaf8203735b..bc8a2216dbf75 100644 --- a/source/common/tracing/opentracing_driver_impl.h +++ b/source/extensions/tracers/common/ot/opentracing_driver_impl.h @@ -11,7 +11,10 @@ #include "opentracing/tracer.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Common { +namespace Ot { #define OPENTRACING_TRACER_STATS(COUNTER) \ COUNTER(span_context_extraction_error) \ @@ -23,7 +26,7 @@ struct OpenTracingTracerStats { class OpenTracingDriver; -class OpenTracingSpan : public Span, Logger::Loggable { +class OpenTracingSpan : public Tracing::Span, Logger::Loggable { public: OpenTracingSpan(OpenTracingDriver& driver, std::unique_ptr&& span); @@ -32,7 +35,8 @@ class OpenTracingSpan : public Span, Logger::Loggable { void setOperation(const std::string& operation) override; void setTag(const std::string& name, const std::string& value) override; void injectContext(Http::HeaderMap& request_headers) override; - SpanPtr spawnChild(const Config& config, const std::string& name, SystemTime start_time) override; + Tracing::SpanPtr spawnChild(const Tracing::Config& config, const std::string& name, + SystemTime start_time) override; private: OpenTracingDriver& driver_; @@ -45,14 +49,14 @@ class OpenTracingSpan : public Span, Logger::Loggable { * minimal amount of effort. Libraries need only provide an opentracing::Tracer implementation; the * rest of span creation is taken care of by this class. */ -class OpenTracingDriver : public Driver, protected Logger::Loggable { +class OpenTracingDriver : public Tracing::Driver, protected Logger::Loggable { public: explicit OpenTracingDriver(Stats::Store& stats); // Tracer::TracingDriver - SpanPtr startSpan(const Config& config, Http::HeaderMap& request_headers, - const std::string& operation_name, SystemTime start_time, - const Tracing::Decision tracing_decision) override; + Tracing::SpanPtr startSpan(const Tracing::Config& config, Http::HeaderMap& request_headers, + const std::string& operation_name, SystemTime start_time, + const Tracing::Decision tracing_decision) override; virtual opentracing::Tracer& tracer() PURE; @@ -73,6 +77,8 @@ class OpenTracingDriver : public Driver, protected Logger::Loggable +#include "extensions/tracers/dynamic_ot/config.h" #include "envoy/registry/registry.h" #include "common/common/utility.h" #include "common/config/well_known_names.h" -#include "common/tracing/dynamic_opentracing_driver_impl.h" #include "common/tracing/http_tracer_impl.h" +#include "extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h" + namespace Envoy { -namespace Server { -namespace Configuration { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { -Tracing::HttpTracerPtr DynamicOpenTracingHttpTracerFactory::createHttpTracer( - const Json::Object& json_config, Server::Instance& server, - Upstream::ClusterManager& /*cluster_manager*/) { +Tracing::HttpTracerPtr +DynamicOpenTracingHttpTracerFactory::createHttpTracer(const Json::Object& json_config, + Server::Instance& server) { const std::string library = json_config.getString("library"); const std::string config = json_config.getObject("config")->asJsonString(); Tracing::DriverPtr dynamic_driver{ - std::make_unique(server.stats(), library, config)}; + std::make_unique(server.stats(), library, config)}; return std::make_unique(std::move(dynamic_driver), server.localInfo()); } std::string DynamicOpenTracingHttpTracerFactory::name() { - return Config::HttpTracerNames::get().DYNAMIC_OT; + return Config::TracerNames::get().DYNAMIC_OT; } /** * Static registration for the dynamic opentracing http tracer. @see RegisterFactory. */ -static Registry::RegisterFactory register_; +static Registry::RegisterFactory + register_; -} // namespace Configuration -} // namespace Server +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/server/config/http/dynamic_opentracing_http_tracer.h b/source/extensions/tracers/dynamic_ot/config.h similarity index 50% rename from source/server/config/http/dynamic_opentracing_http_tracer.h rename to source/extensions/tracers/dynamic_ot/config.h index e3db4cb1bd07d..c8b74f49b03b6 100644 --- a/source/server/config/http/dynamic_opentracing_http_tracer.h +++ b/source/extensions/tracers/dynamic_ot/config.h @@ -7,23 +7,22 @@ #include "server/configuration_impl.h" namespace Envoy { -namespace Server { -namespace Configuration { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { /** * Config registration for the dynamic opentracing tracer. @see HttpTracerFactory. */ -class DynamicOpenTracingHttpTracerFactory : public HttpTracerFactory { +class DynamicOpenTracingHttpTracerFactory : public Server::Configuration::HttpTracerFactory { public: // HttpTracerFactory - Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, Server::Instance& server, - Upstream::ClusterManager& cluster_manager) override; - + Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, + Server::Instance& server) override; std::string name() override; - - bool requiresClusterName() const override { return false; } }; -} // namespace Configuration -} // namespace Server +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/dynamic_opentracing_driver_impl.cc b/source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.cc similarity index 86% rename from source/common/tracing/dynamic_opentracing_driver_impl.cc rename to source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.cc index 132f8628cc6a9..3829a6e66ab52 100644 --- a/source/common/tracing/dynamic_opentracing_driver_impl.cc +++ b/source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.cc @@ -1,9 +1,11 @@ -#include "common/tracing/dynamic_opentracing_driver_impl.h" +#include "extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h" #include "common/common/assert.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { DynamicOpenTracingDriver::DynamicOpenTracingDriver(Stats::Store& stats, const std::string& library, const std::string& tracer_config) @@ -34,5 +36,7 @@ std::string DynamicOpenTracingDriver::formatErrorMessage(std::error_code error_c } } -} // namespace Tracing +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/dynamic_opentracing_driver_impl.h b/source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h similarity index 81% rename from source/common/tracing/dynamic_opentracing_driver_impl.h rename to source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h index 2b15fadf983a0..6785dd4242d24 100644 --- a/source/common/tracing/dynamic_opentracing_driver_impl.h +++ b/source/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h @@ -5,19 +5,21 @@ #include "envoy/tracing/http_tracer.h" #include "envoy/upstream/cluster_manager.h" -#include "common/tracing/opentracing_driver_impl.h" +#include "extensions/tracers/common/ot/opentracing_driver_impl.h" #include "opentracing/dynamic_load.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { /** * This driver provides support for dynamically loading tracing libraries into Envoy that provide an * implementation of the OpenTracing API (see https://github.com/opentracing/opentracing-cpp). * TODO(rnburn): Add an example showing how to use a tracer library with this driver. */ -class DynamicOpenTracingDriver : public OpenTracingDriver { +class DynamicOpenTracingDriver : public Common::Ot::OpenTracingDriver { public: DynamicOpenTracingDriver(Stats::Store& stats, const std::string& library, const std::string& tracer_config); @@ -40,5 +42,7 @@ class DynamicOpenTracingDriver : public OpenTracingDriver { std::shared_ptr tracer_; }; -} // namespace Tracing +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/extensions/tracers/lightstep/BUILD b/source/extensions/tracers/lightstep/BUILD new file mode 100644 index 0000000000000..54bcff99c0f39 --- /dev/null +++ b/source/extensions/tracers/lightstep/BUILD @@ -0,0 +1,36 @@ +licenses(["notice"]) # Apache 2 +# Trace driver for LightStep (https://lightstep.com/) + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_library", + "envoy_package", +) + +envoy_package() + +envoy_cc_library( + name = "lightstep_tracer_lib", + srcs = [ + "lightstep_tracer_impl.cc", + ], + hdrs = [ + "lightstep_tracer_impl.h", + ], + external_deps = ["lightstep"], + deps = [ + "//source/common/tracing:http_tracer_lib", + "//source/extensions/tracers/common/ot:opentracing_driver_lib", + ], +) + +envoy_cc_library( + name = "config", + srcs = ["config.cc"], + hdrs = ["config.h"], + deps = [ + ":lightstep_tracer_lib", + "//source/common/config:well_known_names", + "//source/server:configuration_lib", + ], +) diff --git a/source/extensions/tracers/lightstep/config.cc b/source/extensions/tracers/lightstep/config.cc new file mode 100644 index 0000000000000..af7d9957717e6 --- /dev/null +++ b/source/extensions/tracers/lightstep/config.cc @@ -0,0 +1,46 @@ +#include "extensions/tracers/lightstep/config.h" + +#include "envoy/registry/registry.h" + +#include "common/common/utility.h" +#include "common/config/well_known_names.h" +#include "common/tracing/http_tracer_impl.h" + +#include "extensions/tracers/lightstep/lightstep_tracer_impl.h" + +#include "lightstep/tracer.h" + +namespace Envoy { +namespace Extensions { +namespace Tracers { +namespace Lightstep { + +Tracing::HttpTracerPtr LightstepHttpTracerFactory::createHttpTracer(const Json::Object& json_config, + Server::Instance& server) { + + std::unique_ptr opts(new lightstep::LightStepTracerOptions()); + const auto access_token_file = + server.api().fileReadToEnd(json_config.getString("access_token_file")); + const auto access_token_sv = StringUtil::rtrim(access_token_file); + opts->access_token.assign(access_token_sv.data(), access_token_sv.size()); + opts->component_name = server.localInfo().clusterName(); + + Tracing::DriverPtr lightstep_driver{new LightStepDriver{ + json_config, server.clusterManager(), server.stats(), server.threadLocal(), server.runtime(), + std::move(opts), Common::Ot::OpenTracingDriver::PropagationMode::TracerNative}}; + return std::make_unique(std::move(lightstep_driver), server.localInfo()); +} + +std::string LightstepHttpTracerFactory::name() { return Config::TracerNames::get().LIGHTSTEP; } + +/** + * Static registration for the lightstep http tracer. @see RegisterFactory. + */ +static Registry::RegisterFactory + register_; + +} // namespace Lightstep +} // namespace Tracers +} // namespace Extensions +} // namespace Envoy diff --git a/source/server/config/http/lightstep_http_tracer.h b/source/extensions/tracers/lightstep/config.h similarity index 53% rename from source/server/config/http/lightstep_http_tracer.h rename to source/extensions/tracers/lightstep/config.h index 4ff1c0f054425..09b65cac04dc1 100644 --- a/source/server/config/http/lightstep_http_tracer.h +++ b/source/extensions/tracers/lightstep/config.h @@ -7,21 +7,23 @@ #include "server/configuration_impl.h" namespace Envoy { -namespace Server { -namespace Configuration { +namespace Extensions { +namespace Tracers { +namespace Lightstep { /** * Config registration for the lightstep tracer. @see HttpTracerFactory. */ -class LightstepHttpTracerFactory : public HttpTracerFactory { +class LightstepHttpTracerFactory : public Server::Configuration::HttpTracerFactory { public: // HttpTracerFactory - Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, Server::Instance& server, - Upstream::ClusterManager& cluster_manager) override; + Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, + Server::Instance& server) override; std::string name() override; }; -} // namespace Configuration -} // namespace Server +} // namespace Lightstep +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/lightstep_tracer_impl.cc b/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc similarity index 97% rename from source/common/tracing/lightstep_tracer_impl.cc rename to source/extensions/tracers/lightstep/lightstep_tracer_impl.cc index 6d3b4069dec0b..e19b0a1635571 100644 --- a/source/common/tracing/lightstep_tracer_impl.cc +++ b/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc @@ -1,4 +1,4 @@ -#include "common/tracing/lightstep_tracer_impl.h" +#include "extensions/tracers/lightstep/lightstep_tracer_impl.h" #include #include @@ -13,7 +13,9 @@ #include "common/tracing/http_tracer_impl.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Lightstep { void LightStepLogger::operator()(lightstep::LogLevel level, opentracing::string_view message) const { @@ -164,5 +166,7 @@ opentracing::Tracer& LightStepDriver::tracer() { return tls_->getTyped().tracer(); } -} // namespace Tracing +} // namespace Lightstep +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/lightstep_tracer_impl.h b/source/extensions/tracers/lightstep/lightstep_tracer_impl.h similarity index 94% rename from source/common/tracing/lightstep_tracer_impl.h rename to source/extensions/tracers/lightstep/lightstep_tracer_impl.h index b76c7933ad40b..52ef143457900 100644 --- a/source/common/tracing/lightstep_tracer_impl.h +++ b/source/extensions/tracers/lightstep/lightstep_tracer_impl.h @@ -13,7 +13,8 @@ #include "common/http/message_impl.h" #include "common/json/json_loader.h" #include "common/protobuf/protobuf.h" -#include "common/tracing/opentracing_driver_impl.h" + +#include "extensions/tracers/common/ot/opentracing_driver_impl.h" #include "lightstep/tracer.h" #include "lightstep/transporter.h" @@ -21,7 +22,9 @@ #include "opentracing/tracer.h" namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Lightstep { #define LIGHTSTEP_TRACER_STATS(COUNTER) \ COUNTER(spans_sent) \ @@ -45,7 +48,7 @@ class LightStepLogger : Logger::Loggable { * * LightStepSink is for flushing data to LightStep collectors. */ -class LightStepDriver : public OpenTracingDriver { +class LightStepDriver : public Common::Ot::OpenTracingDriver { public: LightStepDriver(const Json::Object& config, Upstream::ClusterManager& cluster_manager, Stats::Store& stats, ThreadLocal::SlotAllocator& tls, Runtime::Loader& runtime, @@ -119,6 +122,7 @@ class LightStepDriver : public OpenTracingDriver { std::unique_ptr options_; const PropagationMode propagation_mode_; }; - -} // Tracing +} +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/BUILD b/source/extensions/tracers/zipkin/BUILD similarity index 83% rename from source/common/tracing/zipkin/BUILD rename to source/extensions/tracers/zipkin/BUILD index 022f303f1ac36..488657394460e 100644 --- a/source/common/tracing/zipkin/BUILD +++ b/source/extensions/tracers/zipkin/BUILD @@ -1,4 +1,5 @@ licenses(["notice"]) # Apache 2 +# Trace driver for Zipkin (https://zipkin.io/). load( "//bazel:envoy_build_system.bzl", @@ -53,3 +54,14 @@ envoy_cc_library( "//source/common/tracing:http_tracer_lib", ], ) + +envoy_cc_library( + name = "config", + srcs = ["config.cc"], + hdrs = ["config.h"], + deps = [ + "//source/common/config:well_known_names", + "//source/extensions/tracers/zipkin:zipkin_lib", + "//source/server:configuration_lib", + ], +) diff --git a/source/extensions/tracers/zipkin/config.cc b/source/extensions/tracers/zipkin/config.cc new file mode 100644 index 0000000000000..b77fe92a2c1a4 --- /dev/null +++ b/source/extensions/tracers/zipkin/config.cc @@ -0,0 +1,40 @@ +#include "extensions/tracers/zipkin/config.h" + +#include "envoy/registry/registry.h" + +#include "common/common/utility.h" +#include "common/config/well_known_names.h" +#include "common/tracing/http_tracer_impl.h" + +#include "extensions/tracers/zipkin/zipkin_tracer_impl.h" + +namespace Envoy { +namespace Extensions { +namespace Tracers { +namespace Zipkin { + +Tracing::HttpTracerPtr ZipkinHttpTracerFactory::createHttpTracer(const Json::Object& json_config, + Server::Instance& server) { + + Envoy::Runtime::RandomGenerator& rand = server.random(); + + Tracing::DriverPtr zipkin_driver(new Zipkin::Driver(json_config, server.clusterManager(), + server.stats(), server.threadLocal(), + server.runtime(), server.localInfo(), rand)); + + return Tracing::HttpTracerPtr( + new Tracing::HttpTracerImpl(std::move(zipkin_driver), server.localInfo())); +} + +std::string ZipkinHttpTracerFactory::name() { return Config::TracerNames::get().ZIPKIN; } + +/** + * Static registration for the lightstep http tracer. @see RegisterFactory. + */ +static Registry::RegisterFactory + register_; + +} // namespace Zipkin +} // namespace Tracers +} // namespace Extensions +} // namespace Envoy diff --git a/source/server/config/http/zipkin_http_tracer.h b/source/extensions/tracers/zipkin/config.h similarity index 52% rename from source/server/config/http/zipkin_http_tracer.h rename to source/extensions/tracers/zipkin/config.h index 7340623949ecf..c5c12cbf03ea6 100644 --- a/source/server/config/http/zipkin_http_tracer.h +++ b/source/extensions/tracers/zipkin/config.h @@ -1,26 +1,26 @@ #pragma once -#include - #include "envoy/server/instance.h" #include "server/configuration_impl.h" namespace Envoy { -namespace Server { -namespace Configuration { +namespace Extensions { +namespace Tracers { +namespace Zipkin { /** * Config registration for the zipkin http tracer. @see HttpTracerFactory. */ -class ZipkinHttpTracerFactory : public HttpTracerFactory { +class ZipkinHttpTracerFactory : public Server::Configuration::HttpTracerFactory { public: // HttpTracerFactory - Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, Server::Instance& server, - Upstream::ClusterManager& cluster_manager) override; + Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, + Server::Instance& server) override; std::string name() override; }; -} // namespace Configuration -} // namespace Server +} // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/span_buffer.cc b/source/extensions/tracers/zipkin/span_buffer.cc similarity index 84% rename from source/common/tracing/zipkin/span_buffer.cc rename to source/extensions/tracers/zipkin/span_buffer.cc index cff07425f616e..387d851a9f912 100644 --- a/source/common/tracing/zipkin/span_buffer.cc +++ b/source/extensions/tracers/zipkin/span_buffer.cc @@ -1,6 +1,8 @@ -#include "common/tracing/zipkin/span_buffer.h" +#include "extensions/tracers/zipkin/span_buffer.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { // TODO(fabolive): Need to avoid the copy to improve performance. @@ -29,5 +31,8 @@ std::string SpanBuffer::toStringifiedJsonArray() { return stringified_json_array; } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/span_buffer.h b/source/extensions/tracers/zipkin/span_buffer.h similarity index 91% rename from source/common/tracing/zipkin/span_buffer.h rename to source/extensions/tracers/zipkin/span_buffer.h index cfe09662e046b..f81ddc41e003e 100644 --- a/source/common/tracing/zipkin/span_buffer.h +++ b/source/extensions/tracers/zipkin/span_buffer.h @@ -1,8 +1,10 @@ #pragma once -#include "common/tracing/zipkin/zipkin_core_types.h" +#include "extensions/tracers/zipkin/zipkin_core_types.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { /** @@ -61,5 +63,8 @@ class SpanBuffer { // We use a pre-allocated vector to improve performance std::vector span_buffer_; }; + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/span_context.cc b/source/extensions/tracers/zipkin/span_context.cc similarity index 63% rename from source/common/tracing/zipkin/span_context.cc rename to source/extensions/tracers/zipkin/span_context.cc index 259fe9c343442..efe701a74af00 100644 --- a/source/common/tracing/zipkin/span_context.cc +++ b/source/extensions/tracers/zipkin/span_context.cc @@ -1,10 +1,13 @@ -#include "common/tracing/zipkin/span_context.h" +#include "extensions/tracers/zipkin/span_context.h" #include "common/common/macros.h" #include "common/common/utility.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" + +#include "extensions/tracers/zipkin/zipkin_core_constants.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { SpanContext::SpanContext(const Span& span) { @@ -14,5 +17,8 @@ SpanContext::SpanContext(const Span& span) { sampled_ = span.sampled(); is_initialized_ = true; } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/span_context.h b/source/extensions/tracers/zipkin/span_context.h similarity index 86% rename from source/common/tracing/zipkin/span_context.h rename to source/extensions/tracers/zipkin/span_context.h index a9b92dca9234d..eb22edaa7a34c 100644 --- a/source/common/tracing/zipkin/span_context.h +++ b/source/extensions/tracers/zipkin/span_context.h @@ -2,11 +2,13 @@ #include -#include "common/tracing/zipkin/util.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" -#include "common/tracing/zipkin/zipkin_core_types.h" +#include "extensions/tracers/zipkin/util.h" +#include "extensions/tracers/zipkin/zipkin_core_constants.h" +#include "extensions/tracers/zipkin/zipkin_core_types.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { /** @@ -67,5 +69,8 @@ class SpanContext { bool is_initialized_; bool sampled_; }; + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/tracer.cc b/source/extensions/tracers/zipkin/tracer.cc similarity index 94% rename from source/common/tracing/zipkin/tracer.cc rename to source/extensions/tracers/zipkin/tracer.cc index 879d705034e65..6639d30ebadf6 100644 --- a/source/common/tracing/zipkin/tracer.cc +++ b/source/extensions/tracers/zipkin/tracer.cc @@ -1,13 +1,16 @@ -#include "common/tracing/zipkin/tracer.h" +#include "extensions/tracers/zipkin/tracer.h" #include #include "common/common/utility.h" #include "common/tracing/http_tracer_impl.h" -#include "common/tracing/zipkin/util.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" + +#include "extensions/tracers/zipkin/util.h" +#include "extensions/tracers/zipkin/zipkin_core_constants.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { SpanPtr Tracer::startSpan(const Tracing::Config& config, const std::string& span_name, @@ -125,4 +128,6 @@ void Tracer::reportSpan(Span&& span) { void Tracer::setReporter(ReporterPtr reporter) { reporter_ = std::move(reporter); } } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/tracer.h b/source/extensions/tracers/zipkin/tracer.h similarity index 92% rename from source/common/tracing/zipkin/tracer.h rename to source/extensions/tracers/zipkin/tracer.h index 9dc623d001823..dfa60308cb7bd 100644 --- a/source/common/tracing/zipkin/tracer.h +++ b/source/extensions/tracers/zipkin/tracer.h @@ -5,12 +5,14 @@ #include "envoy/runtime/runtime.h" #include "envoy/tracing/http_tracer.h" -#include "common/tracing/zipkin/span_context.h" -#include "common/tracing/zipkin/tracer_interface.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" -#include "common/tracing/zipkin/zipkin_core_types.h" +#include "extensions/tracers/zipkin/span_context.h" +#include "extensions/tracers/zipkin/tracer_interface.h" +#include "extensions/tracers/zipkin/zipkin_core_constants.h" +#include "extensions/tracers/zipkin/zipkin_core_types.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { /** @@ -115,4 +117,6 @@ class Tracer : public TracerInterface { typedef std::unique_ptr TracerPtr; } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/tracer_interface.h b/source/extensions/tracers/zipkin/tracer_interface.h similarity index 88% rename from source/common/tracing/zipkin/tracer_interface.h rename to source/extensions/tracers/zipkin/tracer_interface.h index fe6d72bc90046..7e593c657d0ee 100644 --- a/source/common/tracing/zipkin/tracer_interface.h +++ b/source/extensions/tracers/zipkin/tracer_interface.h @@ -3,6 +3,8 @@ #include "envoy/common/pure.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { class Span; @@ -28,5 +30,8 @@ class TracerInterface { */ virtual void reportSpan(Span&& span) PURE; }; + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/util.cc b/source/extensions/tracers/zipkin/util.cc similarity index 92% rename from source/common/tracing/zipkin/util.cc rename to source/extensions/tracers/zipkin/util.cc index 95b3d2d530318..9ea8091a68e6a 100644 --- a/source/common/tracing/zipkin/util.cc +++ b/source/extensions/tracers/zipkin/util.cc @@ -1,4 +1,4 @@ -#include "common/tracing/zipkin/util.h" +#include "extensions/tracers/zipkin/util.h" #include #include @@ -12,8 +12,8 @@ #include "rapidjson/writer.h" namespace Envoy { -// TODO(fabolive): Need to add interfaces to the JSON namespace - +namespace Extensions { +namespace Tracers { namespace Zipkin { void Util::mergeJsons(std::string& target, const std::string& source, @@ -54,5 +54,8 @@ uint64_t Util::generateRandom64() { std::mt19937_64 rand_64(seed); return rand_64(); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/util.h b/source/extensions/tracers/zipkin/util.h similarity index 93% rename from source/common/tracing/zipkin/util.h rename to source/extensions/tracers/zipkin/util.h index a988b250502c1..cee928f8a9af1 100644 --- a/source/common/tracing/zipkin/util.h +++ b/source/extensions/tracers/zipkin/util.h @@ -4,6 +4,8 @@ #include namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { /** @@ -45,5 +47,8 @@ class Util { */ static uint64_t generateRandom64(); }; + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_core_constants.h b/source/extensions/tracers/zipkin/zipkin_core_constants.h similarity index 93% rename from source/common/tracing/zipkin/zipkin_core_constants.h rename to source/extensions/tracers/zipkin/zipkin_core_constants.h index 42a14aaab9704..042906a0e778f 100644 --- a/source/common/tracing/zipkin/zipkin_core_constants.h +++ b/source/extensions/tracers/zipkin/zipkin_core_constants.h @@ -5,6 +5,8 @@ #include "common/singleton/const_singleton.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { class ZipkinCoreConstantValues { @@ -43,4 +45,6 @@ class ZipkinCoreConstantValues { typedef ConstSingleton ZipkinCoreConstants; } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_core_types.cc b/source/extensions/tracers/zipkin/zipkin_core_types.cc similarity index 95% rename from source/common/tracing/zipkin/zipkin_core_types.cc rename to source/extensions/tracers/zipkin/zipkin_core_types.cc index 73fed8b42c07c..6485e39f9d8da 100644 --- a/source/common/tracing/zipkin/zipkin_core_types.cc +++ b/source/extensions/tracers/zipkin/zipkin_core_types.cc @@ -1,17 +1,18 @@ -#include "common/tracing/zipkin/zipkin_core_types.h" +#include "extensions/tracers/zipkin/zipkin_core_types.h" #include "common/common/utility.h" -#include "common/tracing/zipkin/span_context.h" -#include "common/tracing/zipkin/util.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" -#include "common/tracing/zipkin/zipkin_json_field_names.h" + +#include "extensions/tracers/zipkin/span_context.h" +#include "extensions/tracers/zipkin/util.h" +#include "extensions/tracers/zipkin/zipkin_core_constants.h" +#include "extensions/tracers/zipkin/zipkin_json_field_names.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" namespace Envoy { -// TODO(fabolive): Need to add interfaces to the JSON namespace - +namespace Extensions { +namespace Tracers { namespace Zipkin { Endpoint::Endpoint(const Endpoint& ep) { @@ -258,5 +259,8 @@ void Span::setTag(const std::string& name, const std::string& value) { addBinaryAnnotation(BinaryAnnotation(name, value)); } } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_core_types.h b/source/extensions/tracers/zipkin/zipkin_core_types.h similarity index 98% rename from source/common/tracing/zipkin/zipkin_core_types.h rename to source/extensions/tracers/zipkin/zipkin_core_types.h index af5ebbd9978c2..861f8918bdee1 100644 --- a/source/common/tracing/zipkin/zipkin_core_types.h +++ b/source/extensions/tracers/zipkin/zipkin_core_types.h @@ -6,12 +6,15 @@ #include "envoy/network/address.h" #include "common/common/hex.h" -#include "common/tracing/zipkin/tracer_interface.h" -#include "common/tracing/zipkin/util.h" + +#include "extensions/tracers/zipkin/tracer_interface.h" +#include "extensions/tracers/zipkin/util.h" #include "absl/types/optional.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { /** @@ -555,5 +558,8 @@ class Span : public ZipkinBase { int64_t monotonic_start_time_; TracerInterface* tracer_; }; + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_json_field_names.h b/source/extensions/tracers/zipkin/zipkin_json_field_names.h similarity index 92% rename from source/common/tracing/zipkin/zipkin_json_field_names.h rename to source/extensions/tracers/zipkin/zipkin_json_field_names.h index 09b841ca31924..ff3f6068511e4 100644 --- a/source/common/tracing/zipkin/zipkin_json_field_names.h +++ b/source/extensions/tracers/zipkin/zipkin_json_field_names.h @@ -5,6 +5,8 @@ #include "common/singleton/const_singleton.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { class ZipkinJsonFieldNameValues { @@ -35,4 +37,6 @@ class ZipkinJsonFieldNameValues { typedef ConstSingleton ZipkinJsonFieldNames; } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_tracer_impl.cc b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc similarity index 97% rename from source/common/tracing/zipkin/zipkin_tracer_impl.cc rename to source/extensions/tracers/zipkin/zipkin_tracer_impl.cc index 592e7d116a3f5..b80214eb37df3 100644 --- a/source/common/tracing/zipkin/zipkin_tracer_impl.cc +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc @@ -1,4 +1,4 @@ -#include "common/tracing/zipkin/zipkin_tracer_impl.h" +#include "extensions/tracers/zipkin/zipkin_tracer_impl.h" #include "common/common/enum_to_int.h" #include "common/common/fmt.h" @@ -7,9 +7,12 @@ #include "common/http/message_impl.h" #include "common/http/utility.h" #include "common/tracing/http_tracer_impl.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" + +#include "extensions/tracers/zipkin/zipkin_core_constants.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { ZipkinSpan::ZipkinSpan(Zipkin::Span& span, Zipkin::Tracer& tracer) : span_(span), tracer_(tracer) {} @@ -193,5 +196,8 @@ void ReporterImpl::onSuccess(Http::MessagePtr&& http_response) { driver_.tracerStats().reports_sent_.inc(); } } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/common/tracing/zipkin/zipkin_tracer_impl.h b/source/extensions/tracers/zipkin/zipkin_tracer_impl.h similarity index 97% rename from source/common/tracing/zipkin/zipkin_tracer_impl.h rename to source/extensions/tracers/zipkin/zipkin_tracer_impl.h index 6be50447ebe9d..bd02c5de2a899 100644 --- a/source/common/tracing/zipkin/zipkin_tracer_impl.h +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.h @@ -8,10 +8,13 @@ #include "common/http/header_map_impl.h" #include "common/json/json_loader.h" -#include "common/tracing/zipkin/span_buffer.h" -#include "common/tracing/zipkin/tracer.h" + +#include "extensions/tracers/zipkin/span_buffer.h" +#include "extensions/tracers/zipkin/tracer.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { #define ZIPKIN_TRACER_STATS(COUNTER) \ @@ -199,5 +202,7 @@ class ReporterImpl : public Reporter, Http::AsyncClient::Callbacks { SpanBuffer span_buffer_; const std::string collector_endpoint_; }; -} // Zipkin +} +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/source/server/config/http/BUILD b/source/server/config/http/BUILD index 17f501e4aaf5f..e8b15befed172 100644 --- a/source/server/config/http/BUILD +++ b/source/server/config/http/BUILD @@ -114,30 +114,6 @@ envoy_cc_library( ], ) -envoy_cc_library( - name = "lightstep_lib", - srcs = ["lightstep_http_tracer.cc"], - hdrs = ["lightstep_http_tracer.h"], - deps = [ - "//source/common/config:well_known_names", - "//source/common/tracing:http_tracer_lib", - "//source/common/tracing:lightstep_tracer_lib", - "//source/server:configuration_lib", - ], -) - -envoy_cc_library( - name = "dynamic_opentracing_lib", - srcs = ["dynamic_opentracing_http_tracer.cc"], - hdrs = ["dynamic_opentracing_http_tracer.h"], - deps = [ - "//source/common/config:well_known_names", - "//source/common/tracing:dynamic_opentracing_driver_lib", - "//source/common/tracing:http_tracer_lib", - "//source/server:configuration_lib", - ], -) - envoy_cc_library( name = "router_lib", srcs = ["router.cc"], @@ -167,14 +143,3 @@ envoy_cc_library( "//source/common/protobuf:utility_lib", ], ) - -envoy_cc_library( - name = "zipkin_lib", - srcs = ["zipkin_http_tracer.cc"], - hdrs = ["zipkin_http_tracer.h"], - deps = [ - "//source/common/config:well_known_names", - "//source/common/tracing/zipkin:zipkin_lib", - "//source/server:configuration_lib", - ], -) diff --git a/source/server/config/http/lightstep_http_tracer.cc b/source/server/config/http/lightstep_http_tracer.cc deleted file mode 100644 index 8cff862215837..0000000000000 --- a/source/server/config/http/lightstep_http_tracer.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "server/config/http/lightstep_http_tracer.h" - -#include - -#include "envoy/registry/registry.h" - -#include "common/common/utility.h" -#include "common/config/well_known_names.h" -#include "common/tracing/http_tracer_impl.h" -#include "common/tracing/lightstep_tracer_impl.h" - -#include "lightstep/tracer.h" - -namespace Envoy { -namespace Server { -namespace Configuration { - -Tracing::HttpTracerPtr -LightstepHttpTracerFactory::createHttpTracer(const Json::Object& json_config, - Server::Instance& server, - Upstream::ClusterManager& cluster_manager) { - - std::unique_ptr opts(new lightstep::LightStepTracerOptions()); - const auto access_token_file = - server.api().fileReadToEnd(json_config.getString("access_token_file")); - const auto access_token_sv = StringUtil::rtrim(access_token_file); - opts->access_token.assign(access_token_sv.data(), access_token_sv.size()); - opts->component_name = server.localInfo().clusterName(); - - Tracing::DriverPtr lightstep_driver{new Tracing::LightStepDriver{ - json_config, cluster_manager, server.stats(), server.threadLocal(), server.runtime(), - std::move(opts), Tracing::OpenTracingDriver::PropagationMode::TracerNative}}; - return Tracing::HttpTracerPtr{ - new Tracing::HttpTracerImpl{std::move(lightstep_driver), server.localInfo()}}; -} - -std::string LightstepHttpTracerFactory::name() { return Config::HttpTracerNames::get().LIGHTSTEP; } - -/** - * Static registration for the lightstep http tracer. @see RegisterFactory. - */ -static Registry::RegisterFactory register_; - -} // namespace Configuration -} // namespace Server -} // namespace Envoy diff --git a/source/server/config/http/zipkin_http_tracer.cc b/source/server/config/http/zipkin_http_tracer.cc deleted file mode 100644 index e1b405146732e..0000000000000 --- a/source/server/config/http/zipkin_http_tracer.cc +++ /dev/null @@ -1,39 +0,0 @@ -#include "server/config/http/zipkin_http_tracer.h" - -#include - -#include "envoy/registry/registry.h" - -#include "common/common/utility.h" -#include "common/config/well_known_names.h" -#include "common/tracing/http_tracer_impl.h" -#include "common/tracing/zipkin/zipkin_tracer_impl.h" - -namespace Envoy { -namespace Server { -namespace Configuration { - -Tracing::HttpTracerPtr -ZipkinHttpTracerFactory::createHttpTracer(const Json::Object& json_config, Server::Instance& server, - Upstream::ClusterManager& cluster_manager) { - - Envoy::Runtime::RandomGenerator& rand = server.random(); - - Tracing::DriverPtr zipkin_driver(new Zipkin::Driver(json_config, cluster_manager, server.stats(), - server.threadLocal(), server.runtime(), - server.localInfo(), rand)); - - return Tracing::HttpTracerPtr( - new Tracing::HttpTracerImpl(std::move(zipkin_driver), server.localInfo())); -} - -std::string ZipkinHttpTracerFactory::name() { return Config::HttpTracerNames::get().ZIPKIN; } - -/** - * Static registration for the lightstep http tracer. @see RegisterFactory. - */ -static Registry::RegisterFactory register_; - -} // namespace Configuration -} // namespace Server -} // namespace Envoy diff --git a/source/server/configuration_impl.cc b/source/server/configuration_impl.cc index 7ffa6e4dbeaa3..2884176e81bdd 100644 --- a/source/server/configuration_impl.cc +++ b/source/server/configuration_impl.cc @@ -106,12 +106,7 @@ void MainImpl::initializeTracers(const envoy::config::trace::v2::Tracing& config // Now see if there is a factory that will accept the config. auto& factory = Config::Utility::getAndCheckFactory(type); - if (factory.requiresClusterName() && server.localInfo().clusterName().empty()) { - throw EnvoyException(fmt::format("cluster name must be defined for the tracing driver {}. See " - "--service-cluster option.", - type)); - } - http_tracer_ = factory.createHttpTracer(*driver_config, server, *cluster_manager_); + http_tracer_ = factory.createHttpTracer(*driver_config, server); } void MainImpl::initializeStatsSinks(const envoy::config::bootstrap::v2::Bootstrap& bootstrap, diff --git a/source/server/configuration_impl.h b/source/server/configuration_impl.h index 8c25359093e38..20f10db605dbd 100644 --- a/source/server/configuration_impl.h +++ b/source/server/configuration_impl.h @@ -44,21 +44,15 @@ class HttpTracerFactory { * pointer should always be valid. * @param json_config supplies the general json configuration for the HttpTracer * @param server supplies the server instance - * @param cluster_manager supplies the cluster_manager instance */ - virtual Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, Instance& server, - Upstream::ClusterManager& cluster_manager) PURE; + virtual Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, + Instance& server) PURE; /** * Returns the identifying name for a particular implementation of HttpTracer produced by the * factory. */ virtual std::string name() PURE; - - /** - * Returns true if the tracing driver requires cluster name to be defined. - */ - virtual bool requiresClusterName() const { return true; } }; /** diff --git a/test/common/tracing/BUILD b/test/common/tracing/BUILD index 81661d78e6262..24ef626a3194c 100644 --- a/test/common/tracing/BUILD +++ b/test/common/tracing/BUILD @@ -31,59 +31,3 @@ envoy_cc_test( "//test/test_common:utility_lib", ], ) - -envoy_cc_test( - name = "opentracing_driver_impl_test", - srcs = [ - "opentracing_driver_impl_test.cc", - ], - deps = [ - "//source/common/tracing:dynamic_opentracing_driver_lib", - "//test/mocks/http:http_mocks", - "//test/mocks/stats:stats_mocks", - "//test/mocks/tracing:tracing_mocks", - "@io_opentracing_cpp//mocktracer", - ], -) - -envoy_cc_test( - name = "lightstep_tracer_impl_test", - srcs = [ - "lightstep_tracer_impl_test.cc", - ], - deps = [ - "//source/common/common:base64_lib", - "//source/common/http:header_map_lib", - "//source/common/http:headers_lib", - "//source/common/http:message_lib", - "//source/common/runtime:runtime_lib", - "//source/common/runtime:uuid_util_lib", - "//source/common/tracing:lightstep_tracer_lib", - "//test/mocks/http:http_mocks", - "//test/mocks/local_info:local_info_mocks", - "//test/mocks/runtime:runtime_mocks", - "//test/mocks/stats:stats_mocks", - "//test/mocks/thread_local:thread_local_mocks", - "//test/mocks/tracing:tracing_mocks", - "//test/mocks/upstream:upstream_mocks", - "//test/test_common:utility_lib", - ], -) - -envoy_cc_test( - name = "dynamic_opentracing_driver_impl_test", - srcs = [ - "dynamic_opentracing_driver_impl_test.cc", - ], - data = [ - "@io_opentracing_cpp//mocktracer:libmocktracer_plugin.so", - ], - deps = [ - "//source/common/http:header_map_lib", - "//source/common/tracing:dynamic_opentracing_driver_lib", - "//test/mocks/http:http_mocks", - "//test/mocks/stats:stats_mocks", - "//test/mocks/tracing:tracing_mocks", - "//test/test_common:environment_lib", - ], -) diff --git a/test/extensions/tracers/common/ot/BUILD b/test/extensions/tracers/common/ot/BUILD new file mode 100644 index 0000000000000..fba078c13bbce --- /dev/null +++ b/test/extensions/tracers/common/ot/BUILD @@ -0,0 +1,23 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_test", + "envoy_package", +) + +envoy_package() + +envoy_cc_test( + name = "opentracing_driver_impl_test", + srcs = [ + "opentracing_driver_impl_test.cc", + ], + deps = [ + "//source/extensions/tracers/dynamic_ot:dynamic_opentracing_driver_lib", + "//test/mocks/http:http_mocks", + "//test/mocks/stats:stats_mocks", + "//test/mocks/tracing:tracing_mocks", + "@io_opentracing_cpp//mocktracer", + ], +) diff --git a/test/common/tracing/opentracing_driver_impl_test.cc b/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc similarity index 79% rename from test/common/tracing/opentracing_driver_impl_test.cc rename to test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc index a3b9b71aa55a8..df9f9c60554d6 100644 --- a/test/common/tracing/opentracing_driver_impl_test.cc +++ b/test/extensions/tracers/common/ot/opentracing_driver_impl_test.cc @@ -1,4 +1,4 @@ -#include "common/tracing/opentracing_driver_impl.h" +#include "extensions/tracers/common/ot/opentracing_driver_impl.h" #include "test/mocks/http/mocks.h" #include "test/mocks/stats/mocks.h" @@ -12,7 +12,10 @@ using testing::Test; namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Common { +namespace Ot { class TestDriver : public OpenTracingDriver { public: @@ -71,8 +74,8 @@ class OpenTracingDriverTest : public Test { TEST_F(OpenTracingDriverTest, FlushSpanWithTag) { setupValidDriver(); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); first_span->setTag("abc", "123"); first_span->finishSpan(); @@ -87,14 +90,14 @@ TEST_F(OpenTracingDriverTest, NoSpanSamplingFalse) { setupValidDriver(OpenTracingDriver::PropagationMode::SingleHeader, {}, false); EXPECT_EQ(nullptr, driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, false})); + {Tracing::Reason::Sampling, false})); } TEST_F(OpenTracingDriverTest, TagSamplingFalse) { setupValidDriver(OpenTracingDriver::PropagationMode::TracerNative, {}, true); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, false}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, false}); first_span->finishSpan(); const std::unordered_map expected_tags = { @@ -112,8 +115,8 @@ TEST_F(OpenTracingDriverTest, InjectFailure) { propagation_options.inject_error_code = std::make_error_code(std::errc::bad_message); setupValidDriver(propagation_mode, propagation_options); - SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); const auto span_context_injection_error_count = stats_.counter("tracing.opentracing.span_context_injection_error").value(); @@ -130,17 +133,21 @@ TEST_F(OpenTracingDriverTest, ExtractWithUnindexedHeader) { propagation_options.propagation_key = "unindexed-header"; setupValidDriver(OpenTracingDriver::PropagationMode::TracerNative, propagation_options); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); first_span->injectContext(request_headers_); - SpanPtr second_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr second_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); second_span->finishSpan(); first_span->finishSpan(); auto spans = driver_->recorder().spans(); EXPECT_EQ(spans.at(1).span_context.span_id, spans.at(0).references.at(0).span_id); } -} // namespace Tracing + +} // namespace Ot +} // namespace Common +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/extensions/tracers/dynamic_ot/BUILD b/test/extensions/tracers/dynamic_ot/BUILD new file mode 100644 index 0000000000000..6c8a869bdedfd --- /dev/null +++ b/test/extensions/tracers/dynamic_ot/BUILD @@ -0,0 +1,41 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_test", + "envoy_package", +) + +envoy_package() + +envoy_cc_test( + name = "dynamic_opentracing_driver_impl_test", + srcs = [ + "dynamic_opentracing_driver_impl_test.cc", + ], + data = [ + "@io_opentracing_cpp//mocktracer:libmocktracer_plugin.so", + ], + deps = [ + "//source/common/http:header_map_lib", + "//source/extensions/tracers/dynamic_ot:dynamic_opentracing_driver_lib", + "//test/mocks/http:http_mocks", + "//test/mocks/stats:stats_mocks", + "//test/mocks/tracing:tracing_mocks", + "//test/test_common:environment_lib", + ], +) + +envoy_cc_test( + name = "config_test", + srcs = ["config_test.cc"], + data = [ + "@io_opentracing_cpp//mocktracer:libmocktracer_plugin.so", + ], + deps = [ + "//source/extensions/tracers/dynamic_ot:config", + "//test/mocks/server:server_mocks", + "//test/test_common:environment_lib", + "//test/test_common:utility_lib", + ], +) diff --git a/test/server/config/http/dynamic_opentracing_config_test.cc b/test/extensions/tracers/dynamic_ot/config_test.cc similarity index 61% rename from test/server/config/http/dynamic_opentracing_config_test.cc rename to test/extensions/tracers/dynamic_ot/config_test.cc index 062426b25073e..2febd7aff2cb5 100644 --- a/test/server/config/http/dynamic_opentracing_config_test.cc +++ b/test/extensions/tracers/dynamic_ot/config_test.cc @@ -1,6 +1,4 @@ -#include - -#include "server/config/http/dynamic_opentracing_http_tracer.h" +#include "extensions/tracers/dynamic_ot/config.h" #include "test/mocks/server/mocks.h" #include "test/test_common/environment.h" @@ -9,19 +7,20 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -namespace Envoy { - using testing::NiceMock; using testing::Return; using testing::_; -namespace Server { -namespace Configuration { - -TEST(HttpTracerConfigTest, DynamicOpentracingHttpTracer) { - NiceMock cm; - EXPECT_CALL(cm, get("fake_cluster")).WillRepeatedly(Return(&cm.thread_local_cluster_)); - ON_CALL(*cm.thread_local_cluster_.cluster_.info_, features()) +namespace Envoy { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { + +TEST(DynamicOtTracerConfigTest, DynamicOpentracingHttpTracer) { + NiceMock server; + EXPECT_CALL(server.cluster_manager_, get("fake_cluster")) + .WillRepeatedly(Return(&server.cluster_manager_.thread_local_cluster_)); + ON_CALL(*server.cluster_manager_.thread_local_cluster_.cluster_.info_, features()) .WillByDefault(Return(Upstream::ClusterInfo::Features::HTTP2)); const std::string valid_config = fmt::sprintf(R"EOF( @@ -34,13 +33,13 @@ TEST(HttpTracerConfigTest, DynamicOpentracingHttpTracer) { )EOF", TestEnvironment::runfilesDirectory()); const Json::ObjectSharedPtr valid_json = Json::Factory::loadFromString(valid_config); - NiceMock server; DynamicOpenTracingHttpTracerFactory factory; - const Tracing::HttpTracerPtr tracer = factory.createHttpTracer(*valid_json, server, cm); + const Tracing::HttpTracerPtr tracer = factory.createHttpTracer(*valid_json, server); EXPECT_NE(nullptr, tracer); } -} // namespace Configuration -} // namespace Server +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/dynamic_opentracing_driver_impl_test.cc b/test/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl_test.cc similarity index 85% rename from test/common/tracing/dynamic_opentracing_driver_impl_test.cc rename to test/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl_test.cc index 15418fbc0c13d..d53ecbcf46338 100644 --- a/test/common/tracing/dynamic_opentracing_driver_impl_test.cc +++ b/test/extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl_test.cc @@ -1,5 +1,6 @@ #include "common/http/header_map_impl.h" -#include "common/tracing/dynamic_opentracing_driver_impl.h" + +#include "extensions/tracers/dynamic_ot/dynamic_opentracing_driver_impl.h" #include "test/mocks/http/mocks.h" #include "test/mocks/stats/mocks.h" @@ -13,7 +14,9 @@ using testing::Test; namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace DynamicOt { class DynamicOpenTracingDriverTest : public Test { public: @@ -70,8 +73,8 @@ TEST_F(DynamicOpenTracingDriverTest, InitializeDriver) { TEST_F(DynamicOpenTracingDriverTest, FlushSpans) { setupValidDriver(); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); first_span->finishSpan(); driver_->tracer().Close(); @@ -81,5 +84,7 @@ TEST_F(DynamicOpenTracingDriverTest, FlushSpans) { EXPECT_EQ(spans_json->asObjectArray().size(), 1); } -} // namespace Tracing +} // namespace DynamicOt +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/extensions/tracers/lightstep/BUILD b/test/extensions/tracers/lightstep/BUILD new file mode 100644 index 0000000000000..7ed4f2821a57a --- /dev/null +++ b/test/extensions/tracers/lightstep/BUILD @@ -0,0 +1,43 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_test", + "envoy_package", +) + +envoy_package() + +envoy_cc_test( + name = "lightstep_tracer_impl_test", + srcs = [ + "lightstep_tracer_impl_test.cc", + ], + deps = [ + "//source/common/common:base64_lib", + "//source/common/http:header_map_lib", + "//source/common/http:headers_lib", + "//source/common/http:message_lib", + "//source/common/runtime:runtime_lib", + "//source/common/runtime:uuid_util_lib", + "//source/extensions/tracers/lightstep:lightstep_tracer_lib", + "//test/mocks/http:http_mocks", + "//test/mocks/local_info:local_info_mocks", + "//test/mocks/runtime:runtime_mocks", + "//test/mocks/stats:stats_mocks", + "//test/mocks/thread_local:thread_local_mocks", + "//test/mocks/tracing:tracing_mocks", + "//test/mocks/upstream:upstream_mocks", + "//test/test_common:utility_lib", + ], +) + +envoy_cc_test( + name = "config_test", + srcs = ["config_test.cc"], + deps = [ + "//source/extensions/tracers/lightstep:config", + "//test/mocks/server:server_mocks", + "//test/test_common:utility_lib", + ], +) diff --git a/test/server/config/http/lightstep_config_test.cc b/test/extensions/tracers/lightstep/config_test.cc similarity index 53% rename from test/server/config/http/lightstep_config_test.cc rename to test/extensions/tracers/lightstep/config_test.cc index cdd19f42db30e..8d60609e0209e 100644 --- a/test/server/config/http/lightstep_config_test.cc +++ b/test/extensions/tracers/lightstep/config_test.cc @@ -1,25 +1,24 @@ -#include - -#include "server/config/http/lightstep_http_tracer.h" +#include "extensions/tracers/lightstep/config.h" #include "test/mocks/server/mocks.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -namespace Envoy { - using testing::NiceMock; using testing::Return; using testing::_; -namespace Server { -namespace Configuration { - -TEST(HttpTracerConfigTest, LightstepHttpTracer) { - NiceMock cm; - EXPECT_CALL(cm, get("fake_cluster")).WillRepeatedly(Return(&cm.thread_local_cluster_)); - ON_CALL(*cm.thread_local_cluster_.cluster_.info_, features()) +namespace Envoy { +namespace Extensions { +namespace Tracers { +namespace Lightstep { + +TEST(LightstepTracerConfigTest, LightstepHttpTracer) { + NiceMock server; + EXPECT_CALL(server.cluster_manager_, get("fake_cluster")) + .WillRepeatedly(Return(&server.cluster_manager_.thread_local_cluster_)); + ON_CALL(*server.cluster_manager_.thread_local_cluster_.cluster_.info_, features()) .WillByDefault(Return(Upstream::ClusterInfo::Features::HTTP2)); std::string valid_config = R"EOF( @@ -29,12 +28,13 @@ TEST(HttpTracerConfigTest, LightstepHttpTracer) { } )EOF"; Json::ObjectSharedPtr valid_json = Json::Factory::loadFromString(valid_config); - NiceMock server; + LightstepHttpTracerFactory factory; - Tracing::HttpTracerPtr lightstep_tracer = factory.createHttpTracer(*valid_json, server, cm); + Tracing::HttpTracerPtr lightstep_tracer = factory.createHttpTracer(*valid_json, server); EXPECT_NE(nullptr, lightstep_tracer); } -} // namespace Configuration -} // namespace Server +} // namespace Lightstep +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/lightstep_tracer_impl_test.cc b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc similarity index 85% rename from test/common/tracing/lightstep_tracer_impl_test.cc rename to test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc index 83ec5603d566c..cf2dfeb9bacb4 100644 --- a/test/common/tracing/lightstep_tracer_impl_test.cc +++ b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc @@ -11,7 +11,8 @@ #include "common/runtime/runtime_impl.h" #include "common/runtime/uuid_util.h" #include "common/tracing/http_tracer_impl.h" -#include "common/tracing/lightstep_tracer_impl.h" + +#include "extensions/tracers/lightstep/lightstep_tracer_impl.h" #include "test/mocks/http/mocks.h" #include "test/mocks/local_info/mocks.h" @@ -35,13 +36,15 @@ using testing::Test; using testing::_; namespace Envoy { -namespace Tracing { +namespace Extensions { +namespace Tracers { +namespace Lightstep { class LightStepDriverTest : public Test { public: void setup(Json::Object& config, bool init_timer, - OpenTracingDriver::PropagationMode propagation_mode = - OpenTracingDriver::PropagationMode::TracerNative) { + Common::Ot::OpenTracingDriver::PropagationMode propagation_mode = + Common::Ot::OpenTracingDriver::PropagationMode::TracerNative) { std::unique_ptr opts( new lightstep::LightStepTracerOptions()); opts->access_token = "sample_token"; @@ -59,8 +62,8 @@ class LightStepDriverTest : public Test { propagation_mode}); } - void setupValidDriver(OpenTracingDriver::PropagationMode propagation_mode = - OpenTracingDriver::PropagationMode::TracerNative) { + void setupValidDriver(Common::Ot::OpenTracingDriver::PropagationMode propagation_mode = + Common::Ot::OpenTracingDriver::PropagationMode::TracerNative) { EXPECT_CALL(cm_, get("fake_cluster")).WillRepeatedly(Return(&cm_.thread_local_cluster_)); ON_CALL(*cm_.thread_local_cluster_.cluster_.info_, features()) .WillByDefault(Return(Upstream::ClusterInfo::Features::HTTP2)); @@ -184,16 +187,16 @@ TEST_F(LightStepDriverTest, FlushSeveralSpans) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U)) .WillOnce(Return(5000U)); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); // Currently not possible to access the operation from the span, but this // invocation will make sure setting the operation does not cause a crash! first_span->setOperation("myOperation"); first_span->finishSpan(); - SpanPtr second_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr second_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); second_span->finishSpan(); Http::MessagePtr msg(new Http::ResponseMessageImpl( @@ -243,8 +246,8 @@ TEST_F(LightStepDriverTest, FlushOneFailure) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U)) .WillOnce(Return(5000U)); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); first_span->finishSpan(); @@ -285,8 +288,8 @@ TEST_F(LightStepDriverTest, FlushOneInvalidResponse) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U)) .WillOnce(Return(5000U)); - SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); first_span->finishSpan(); @@ -316,8 +319,8 @@ TEST_F(LightStepDriverTest, FlushSpansTimer) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.min_flush_spans", 5)) .WillOnce(Return(5)); - SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); span->finishSpan(); // Timer should be re-enabled. @@ -358,8 +361,8 @@ TEST_F(LightStepDriverTest, FlushOneSpanGrpcFailure) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U)) .WillOnce(Return(5000U)); - SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); span->finishSpan(); Http::MessagePtr msg(new Http::ResponseMessageImpl( @@ -397,8 +400,8 @@ TEST_F(LightStepDriverTest, CancelRequestOnDestruction) { EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U)) .WillOnce(Return(5000U)); - SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); span->finishSpan(); EXPECT_CALL(request, cancel()); @@ -407,9 +410,9 @@ TEST_F(LightStepDriverTest, CancelRequestOnDestruction) { } TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { - for (OpenTracingDriver::PropagationMode propagation_mode : - {OpenTracingDriver::PropagationMode::SingleHeader, - OpenTracingDriver::PropagationMode::TracerNative}) { + for (Common::Ot::OpenTracingDriver::PropagationMode propagation_mode : + {Common::Ot::OpenTracingDriver::PropagationMode::SingleHeader, + Common::Ot::OpenTracingDriver::PropagationMode::TracerNative}) { setupValidDriver(propagation_mode); // Supply bogus context, that will be simply ignored. @@ -417,7 +420,7 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { request_headers_.insertOtSpanContext().value(invalid_context); stats_.counter("tracing.opentracing.span_context_extraction_error").reset(); driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + {Tracing::Reason::Sampling, true}); EXPECT_EQ(1U, stats_.counter("tracing.opentracing.span_context_extraction_error").value()); std::string injected_ctx = request_headers_.OtSpanContext()->value().c_str(); @@ -425,8 +428,8 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { // Supply empty context. request_headers_.removeOtSpanContext(); - SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr span = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); EXPECT_EQ(nullptr, request_headers_.OtSpanContext()); span->injectContext(request_headers_); @@ -441,8 +444,8 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { EXPECT_TRUE(tracer.Extract(iss)); // Supply parent context, request_headers has properly populated x-ot-span-context. - SpanPtr span_with_parent = driver_->startSpan(config_, request_headers_, operation_name_, - start_time_, {Reason::Sampling, true}); + Tracing::SpanPtr span_with_parent = driver_->startSpan( + config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); request_headers_.removeOtSpanContext(); span_with_parent->injectContext(request_headers_); injected_ctx = request_headers_.OtSpanContext()->value().c_str(); @@ -453,13 +456,13 @@ TEST_F(LightStepDriverTest, SerializeAndDeserializeContext) { TEST_F(LightStepDriverTest, SpawnChild) { setupValidDriver(); - SpanPtr parent = driver_->startSpan(config_, request_headers_, operation_name_, start_time_, - {Reason::Sampling, true}); + Tracing::SpanPtr parent = driver_->startSpan(config_, request_headers_, operation_name_, + start_time_, {Tracing::Reason::Sampling, true}); parent->injectContext(request_headers_); - SpanPtr childViaHeaders = driver_->startSpan(config_, request_headers_, operation_name_, - start_time_, {Reason::Sampling, true}); - SpanPtr childViaSpawn = parent->spawnChild(config_, operation_name_, start_time_); + Tracing::SpanPtr childViaHeaders = driver_->startSpan( + config_, request_headers_, operation_name_, start_time_, {Tracing::Reason::Sampling, true}); + Tracing::SpanPtr childViaSpawn = parent->spawnChild(config_, operation_name_, start_time_); Http::TestHeaderMapImpl base1{{":path", "/"}, {":method", "GET"}, {"x-request-id", "foo"}}; Http::TestHeaderMapImpl base2{{":path", "/"}, {":method", "GET"}, {"x-request-id", "foo"}}; @@ -474,5 +477,7 @@ TEST_F(LightStepDriverTest, SpawnChild) { EXPECT_FALSE(base2_context.empty()); } -} // namespace Tracing +} // namespace Lightstep +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/zipkin/BUILD b/test/extensions/tracers/zipkin/BUILD similarity index 80% rename from test/common/tracing/zipkin/BUILD rename to test/extensions/tracers/zipkin/BUILD index 66955688e36a7..e3e93f6a10928 100644 --- a/test/common/tracing/zipkin/BUILD +++ b/test/extensions/tracers/zipkin/BUILD @@ -27,7 +27,7 @@ envoy_cc_test( "//source/common/network:address_lib", "//source/common/network:utility_lib", "//source/common/runtime:runtime_lib", - "//source/common/tracing/zipkin:zipkin_lib", + "//source/extensions/tracers/zipkin:zipkin_lib", "//test/mocks:common_lib", "//test/mocks/http:http_mocks", "//test/mocks/local_info:local_info_mocks", @@ -39,3 +39,13 @@ envoy_cc_test( "//test/test_common:utility_lib", ], ) + +envoy_cc_test( + name = "config_test", + srcs = ["config_test.cc"], + deps = [ + "//source/extensions/tracers/zipkin:config", + "//test/mocks/server:server_mocks", + "//test/test_common:utility_lib", + ], +) diff --git a/test/extensions/tracers/zipkin/config_test.cc b/test/extensions/tracers/zipkin/config_test.cc new file mode 100644 index 0000000000000..407509fafa66f --- /dev/null +++ b/test/extensions/tracers/zipkin/config_test.cc @@ -0,0 +1,41 @@ +#include "envoy/registry/registry.h" + +#include "extensions/tracers/zipkin/config.h" + +#include "test/mocks/server/mocks.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace Envoy { +namespace Extensions { +namespace Tracers { +namespace Zipkin { + +TEST(ZipkinTracerConfigTest, ZipkinHttpTracer) { + NiceMock server; + EXPECT_CALL(server.cluster_manager_, get("fake_cluster")) + .WillRepeatedly(Return(&server.cluster_manager_.thread_local_cluster_)); + + std::string valid_config = R"EOF( + { + "collector_cluster": "fake_cluster", + "collector_endpoint": "/api/v1/spans" + } + )EOF"; + Json::ObjectSharedPtr valid_json = Json::Factory::loadFromString(valid_config); + ZipkinHttpTracerFactory factory; + Tracing::HttpTracerPtr zipkin_tracer = factory.createHttpTracer(*valid_json, server); + EXPECT_NE(nullptr, zipkin_tracer); +} + +TEST(ZipkinTracerConfigTest, DoubleRegistrationTest) { + EXPECT_THROW_WITH_MESSAGE((Registry::RegisterFactory()), + EnvoyException, "Double registration for name: 'envoy.zipkin'"); +} + +} // namespace Zipkin +} // namespace Tracers +} // namespace Extensions +} // namespace Envoy diff --git a/test/common/tracing/zipkin/span_buffer_test.cc b/test/extensions/tracers/zipkin/span_buffer_test.cc similarity index 96% rename from test/common/tracing/zipkin/span_buffer_test.cc rename to test/extensions/tracers/zipkin/span_buffer_test.cc index 8b903757a2392..4150bffa52147 100644 --- a/test/common/tracing/zipkin/span_buffer_test.cc +++ b/test/extensions/tracers/zipkin/span_buffer_test.cc @@ -1,8 +1,10 @@ -#include "common/tracing/zipkin/span_buffer.h" +#include "extensions/tracers/zipkin/span_buffer.h" #include "gtest/gtest.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { TEST(ZipkinSpanBufferTest, defaultConstructorEndToEnd) { @@ -101,5 +103,8 @@ TEST(ZipkinSpanBufferTest, sizeConstructorEndtoEnd) { EXPECT_EQ(0ULL, buffer.pendingSpans()); EXPECT_EQ("[]", buffer.toStringifiedJsonArray()); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/zipkin/tracer_test.cc b/test/extensions/tracers/zipkin/tracer_test.cc similarity index 98% rename from test/common/tracing/zipkin/tracer_test.cc rename to test/extensions/tracers/zipkin/tracer_test.cc index a542550592260..6ee9311e42b79 100644 --- a/test/common/tracing/zipkin/tracer_test.cc +++ b/test/extensions/tracers/zipkin/tracer_test.cc @@ -2,9 +2,10 @@ #include "common/network/address_impl.h" #include "common/network/utility.h" #include "common/runtime/runtime_impl.h" -#include "common/tracing/zipkin/tracer.h" -#include "common/tracing/zipkin/util.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" + +#include "extensions/tracers/zipkin/tracer.h" +#include "extensions/tracers/zipkin/util.h" +#include "extensions/tracers/zipkin/zipkin_core_constants.h" #include "test/mocks/common.h" #include "test/mocks/runtime/mocks.h" @@ -17,6 +18,8 @@ using testing::NiceMock; using testing::Return; namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { class TestReporterImpl : public Reporter { @@ -353,5 +356,8 @@ TEST(ZipkinTracerTest, SpanSampledPropagatedToChild) { // Test that sampled flag is false EXPECT_FALSE(child_span2->sampled()); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/zipkin/util_test.cc b/test/extensions/tracers/zipkin/util_test.cc similarity index 91% rename from test/common/tracing/zipkin/util_test.cc rename to test/extensions/tracers/zipkin/util_test.cc index c2712ba55569a..0b27f554b2dfa 100644 --- a/test/common/tracing/zipkin/util_test.cc +++ b/test/extensions/tracers/zipkin/util_test.cc @@ -1,8 +1,10 @@ -#include "common/tracing/zipkin/util.h" +#include "extensions/tracers/zipkin/util.h" #include "gtest/gtest.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { TEST(ZipkinUtilTest, utilTests) { @@ -38,5 +40,8 @@ TEST(ZipkinUtilTest, utilTests) { "\"val1\"}},\"array_field\":[],\"second_array\":[{\"a1\":10},{\"a2\":\"10\"}]}"; EXPECT_EQ(expected_json, merged_json); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/zipkin/zipkin_core_types_test.cc b/test/extensions/tracers/zipkin/zipkin_core_types_test.cc similarity index 99% rename from test/common/tracing/zipkin/zipkin_core_types_test.cc rename to test/extensions/tracers/zipkin/zipkin_core_types_test.cc index 416dc7a1b4cc8..1aa63e55e1068 100644 --- a/test/common/tracing/zipkin/zipkin_core_types_test.cc +++ b/test/extensions/tracers/zipkin/zipkin_core_types_test.cc @@ -1,12 +1,15 @@ #include "common/common/utility.h" #include "common/network/address_impl.h" #include "common/network/utility.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" -#include "common/tracing/zipkin/zipkin_core_types.h" + +#include "extensions/tracers/zipkin/zipkin_core_constants.h" +#include "extensions/tracers/zipkin/zipkin_core_types.h" #include "gtest/gtest.h" namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { TEST(ZipkinCoreTypesEndpointTest, defaultConstructor) { @@ -567,5 +570,8 @@ TEST(ZipkinCoreTypesSpanTest, setTag) { EXPECT_EQ("key2", bann.key()); EXPECT_EQ("value2", bann.value()); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/common/tracing/zipkin/zipkin_tracer_impl_test.cc b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc similarity index 98% rename from test/common/tracing/zipkin/zipkin_tracer_impl_test.cc rename to test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc index db098e37b2925..de699aee2de28 100644 --- a/test/common/tracing/zipkin/zipkin_tracer_impl_test.cc +++ b/test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc @@ -8,8 +8,9 @@ #include "common/runtime/runtime_impl.h" #include "common/runtime/uuid_util.h" #include "common/tracing/http_tracer_impl.h" -#include "common/tracing/zipkin/zipkin_core_constants.h" -#include "common/tracing/zipkin/zipkin_tracer_impl.h" + +#include "extensions/tracers/zipkin/zipkin_core_constants.h" +#include "extensions/tracers/zipkin/zipkin_tracer_impl.h" #include "test/mocks/http/mocks.h" #include "test/mocks/local_info/mocks.h" @@ -31,6 +32,8 @@ using testing::Test; using testing::_; namespace Envoy { +namespace Extensions { +namespace Tracers { namespace Zipkin { class ZipkinDriverTest : public Test { @@ -498,5 +501,8 @@ TEST_F(ZipkinDriverTest, ZipkinSpanContextFromInvalidParentIdB3HeadersTest) { start_time_, {Tracing::Reason::Sampling, true}); EXPECT_NE(nullptr, dynamic_cast(span.get())); } + } // namespace Zipkin +} // namespace Tracers +} // namespace Extensions } // namespace Envoy diff --git a/test/integration/BUILD b/test/integration/BUILD index 1df5fcc0c51c5..6863d2b86b619 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -300,9 +300,7 @@ envoy_cc_test_library( "//source/server/config/http:grpc_json_transcoder_lib", "//source/server/config/http:gzip_lib", "//source/server/config/http:ip_tagging_lib", - "//source/server/config/http:lightstep_lib", "//source/server/config/http:router_lib", - "//source/server/config/http:zipkin_lib", "//source/server/config/network:http_connection_manager_lib", "//source/server/config/network:raw_buffer_socket_lib", "//source/server/config/network:ssl_socket_lib", diff --git a/test/server/BUILD b/test/server/BUILD index 9e5e8fcbe8000..3d36c78a883d9 100644 --- a/test/server/BUILD +++ b/test/server/BUILD @@ -29,7 +29,6 @@ envoy_cc_test( "//source/common/upstream:cluster_manager_lib", "//source/extensions/stat_sinks/statsd:config", "//source/server:configuration_lib", - "//source/server/config/http:dynamic_opentracing_lib", "//source/server/config/network:raw_buffer_socket_lib", "//test/mocks:common_lib", "//test/mocks/network:network_mocks", diff --git a/test/server/config/http/BUILD b/test/server/config/http/BUILD index d34f3ceec2e96..b63b4494ff12b 100644 --- a/test/server/config/http/BUILD +++ b/test/server/config/http/BUILD @@ -26,34 +26,9 @@ envoy_cc_test( "//source/server/config/http:ip_tagging_lib", "//source/server/config/http:router_lib", "//source/server/config/http:squash_lib", - "//source/server/config/http:zipkin_lib", "//source/server/http:health_check_lib", "//test/mocks/access_log:access_log_mocks", "//test/mocks/server:server_mocks", "//test/test_common:utility_lib", ], ) - -envoy_cc_test( - name = "lightstep_config_test", - srcs = ["lightstep_config_test.cc"], - deps = [ - "//source/server/config/http:lightstep_lib", - "//test/mocks/server:server_mocks", - "//test/test_common:utility_lib", - ], -) - -envoy_cc_test( - name = "dynamic_opentracing_config_test", - srcs = ["dynamic_opentracing_config_test.cc"], - data = [ - "@io_opentracing_cpp//mocktracer:libmocktracer_plugin.so", - ], - deps = [ - "//source/server/config/http:dynamic_opentracing_lib", - "//test/mocks/server:server_mocks", - "//test/test_common:environment_lib", - "//test/test_common:utility_lib", - ], -) diff --git a/test/server/config/http/config_test.cc b/test/server/config/http/config_test.cc index dcc42c55456aa..ec63e12ac76de 100644 --- a/test/server/config/http/config_test.cc +++ b/test/server/config/http/config_test.cc @@ -1,5 +1,3 @@ -#include - #include "envoy/config/filter/http/router/v2/router.pb.h" #include "envoy/registry/registry.h" @@ -18,7 +16,6 @@ #include "server/config/http/ip_tagging.h" #include "server/config/http/router.h" #include "server/config/http/squash.h" -#include "server/config/http/zipkin_http_tracer.h" #include "server/config/network/http_connection_manager.h" #include "server/http/health_check.h" @@ -321,29 +318,6 @@ TEST(HttpFilterConfigTest, SquashFilterCorrectJson) { cb(filter_callback); } -TEST(HttpTracerConfigTest, ZipkinHttpTracer) { - NiceMock cm; - EXPECT_CALL(cm, get("fake_cluster")).WillRepeatedly(Return(&cm.thread_local_cluster_)); - - std::string valid_config = R"EOF( - { - "collector_cluster": "fake_cluster", - "collector_endpoint": "/api/v1/spans" - } - )EOF"; - Json::ObjectSharedPtr valid_json = Json::Factory::loadFromString(valid_config); - NiceMock server; - ZipkinHttpTracerFactory factory; - Tracing::HttpTracerPtr zipkin_tracer = factory.createHttpTracer(*valid_json, server, cm); - EXPECT_NE(nullptr, zipkin_tracer); -} - -TEST(HttpTracerConfigTest, DoubleRegistrationTest) { - EXPECT_THROW_WITH_MESSAGE( - (Registry::RegisterFactory()), EnvoyException, - "Double registration for name: 'envoy.zipkin'"); -} - } // namespace Configuration } // namespace Server } // namespace Envoy diff --git a/test/server/configuration_impl_test.cc b/test/server/configuration_impl_test.cc index 78be848aaa43f..76003adcd95bb 100644 --- a/test/server/configuration_impl_test.cc +++ b/test/server/configuration_impl_test.cc @@ -126,66 +126,6 @@ TEST_F(ConfigurationImplTest, SetUpstreamClusterPerConnectionBufferLimit) { server_.thread_local_.shutdownThread(); } -TEST_F(ConfigurationImplTest, ServiceClusterNotSetWhenLSTracing) { - std::string json = R"EOF( - { - "listeners" : [ - { - "address": "tcp://127.0.0.1:1234", - "filters": [] - } - ], - "cluster_manager": { - "clusters": [] - }, - "tracing": { - "http": { - "driver": { - "type": "lightstep", - "config": { - "collector_cluster": "cluster_0", - "access_token_file": "/etc/envoy/envoy.cfg" - } - } - } - }, - "admin": {"access_log_path": "/dev/null", "address": "tcp://1.2.3.4:5678"} - } - )EOF"; - - envoy::config::bootstrap::v2::Bootstrap bootstrap = TestUtility::parseBootstrapFromJson(json); - - server_.local_info_.node_.set_cluster(""); - MainImpl config; - EXPECT_THROW(config.initialize(bootstrap, server_, cluster_manager_factory_), EnvoyException); -} - -TEST_F(ConfigurationImplTest, ServiceClusterNotSetWhenOtDynamicTracing) { - std::string yaml = fmt::sprintf(R"EOF( - admin: - access_log_path: /dev/null - address: - socket_address: { address: 1.2.3.4, port_value: 5678 } - - tracing: - http: - name: envoy.dynamic.ot - config: - library: %s/external/io_opentracing_cpp/mocktracer/libmocktracer_plugin.so - config: { - "output_file" : "fake_file" - } - )EOF", - TestEnvironment::runfilesDirectory()); - - envoy::config::bootstrap::v2::Bootstrap bootstrap; - MessageUtil::loadFromYaml(yaml, bootstrap); - - server_.local_info_.node_.set_cluster(""); - MainImpl config; - config.initialize(bootstrap, server_, cluster_manager_factory_); -} - TEST_F(ConfigurationImplTest, NullTracerSetWhenTracingConfigurationAbsent) { std::string json = R"EOF( {