-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Skeleton of a tracer for AWS X-Ray #8526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6b85164
bbadcb4
b17c374
fa410cc
7be86ba
7464153
276b079
7ad797c
ab92985
553166a
49323b5
f21aa1c
d4242f5
e87a0e0
4abd180
c081d68
2a5f7e2
b16f0fb
5b9cb89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| # Trace driver for AWS X-Ray. | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "xray_lib", | ||
| srcs = [ | ||
| "util.cc", | ||
| "xray_tracer_impl.cc", | ||
| ], | ||
| hdrs = [ | ||
| "sampling_strategy.h", | ||
| "tracer.h", | ||
| "util.h", | ||
| "xray_configuration.h", | ||
| "xray_tracer_impl.h", | ||
| ], | ||
| deps = [ | ||
| "//include/envoy/common:time_interface", | ||
| "//include/envoy/server:instance_interface", | ||
| "//include/envoy/tracing:http_tracer_interface", | ||
| "//source/common/common:macros", | ||
| "//source/common/http:header_map_lib", | ||
| "//source/common/json:json_loader_lib", | ||
| "//source/common/tracing:http_tracer_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "config", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| deps = [ | ||
| ":xray_lib", | ||
| "//source/common/config:datasource_lib", | ||
| "//source/extensions/tracers:well_known_names", | ||
| "//source/extensions/tracers/common:factory_base_lib", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include "extensions/tracers/xray/config.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "common/common/utility.h" | ||
| #include "common/config/datasource.h" | ||
| #include "common/tracing/http_tracer_impl.h" | ||
|
|
||
| #include "extensions/tracers/well_known_names.h" | ||
| #include "extensions/tracers/xray/xray_tracer_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace XRay { | ||
|
|
||
| XRayTracerFactory::XRayTracerFactory() : FactoryBase(TracerNames::get().XRay) {} | ||
|
|
||
| Tracing::HttpTracerPtr | ||
| XRayTracerFactory::createHttpTracerTyped(const envoy::config::trace::v2::XRayConfig& proto_config, | ||
| Server::Instance& server) { | ||
| std::string sampling_rules_json; | ||
| try { | ||
| sampling_rules_json = | ||
| Config::DataSource::read(proto_config.sampling_rule_manifest(), true, server.api()); | ||
| } catch (EnvoyException& e) { | ||
| ENVOY_LOG(error, "Failed to read sampling rules manifest because of {}.", e.what()); | ||
| } | ||
|
|
||
| XRayConfiguration xconfig(proto_config.daemon_endpoint(), proto_config.segment_name(), | ||
| sampling_rules_json); | ||
| auto xray_driver = std::make_unique<XRay::Driver>(xconfig, server); | ||
|
|
||
| return std::make_unique<Tracing::HttpTracerImpl>(std::move(xray_driver), server.localInfo()); | ||
| } | ||
|
|
||
| /** | ||
| * Static registration for the XRay tracer. @see RegisterFactory. | ||
| */ | ||
| REGISTER_FACTORY(XRayTracerFactory, Server::Configuration::TracerFactory); | ||
|
|
||
| } // namespace XRay | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/config/trace/v2/trace.pb.validate.h" | ||
|
|
||
| #include "common/common/logger.h" | ||
|
|
||
| #include "extensions/tracers/common/factory_base.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace XRay { | ||
|
|
||
| /** | ||
| * Config registration for the XRay tracer. @see TracerFactory. | ||
| */ | ||
| class XRayTracerFactory : public Common::FactoryBase<envoy::config::trace::v2::XRayConfig>, | ||
| Logger::Loggable<Logger::Id::tracing> { | ||
| public: | ||
| XRayTracerFactory(); | ||
|
|
||
| private: | ||
| Tracing::HttpTracerPtr | ||
| createHttpTracerTyped(const envoy::config::trace::v2::XRayConfig& proto_config, | ||
| Server::Instance& server) override; | ||
| }; | ||
|
|
||
| } // namespace XRay | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <random> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| #include "common/common/macros.h" | ||
|
|
||
| #include "absl/strings/string_view.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace XRay { | ||
|
|
||
| struct SamplingRequest { | ||
| /** | ||
| * Creates a new SamplingRequest | ||
| * | ||
| * @param host_name The host name the request. | ||
| * @param http_method The http method of the request e.g. GET, POST, etc. | ||
| * @param http_url The path part of the URL of the request. | ||
| * @param service The name of the service (user specified) | ||
| * @param service_type The type of the service (user specified) | ||
| */ | ||
| SamplingRequest(absl::string_view host_name, absl::string_view http_method, | ||
| absl::string_view http_url) | ||
| : host_(host_name), http_method_(http_method), http_url_(http_url) {} | ||
|
|
||
| const std::string host_; | ||
| const std::string http_method_; | ||
| const std::string http_url_; | ||
| }; | ||
|
|
||
| /** | ||
| * Strategy provides an interface for implementing trace sampling strategies. | ||
| */ | ||
| class SamplingStrategy { | ||
| public: | ||
| explicit SamplingStrategy(uint64_t rng_seed) : rng_(rng_seed) {} | ||
| virtual ~SamplingStrategy() = default; | ||
|
|
||
| /** | ||
| * sampleRequest determines if the given request should be traced or not. | ||
| */ | ||
| virtual bool sampleRequest(const SamplingRequest& sampling_request) { | ||
| UNREFERENCED_PARAMETER(sampling_request); // unused for now | ||
| return rng_() % 100 == 42; | ||
| } | ||
|
|
||
| private: | ||
| std::mt19937 rng_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, this is totally fine for this PR, but for the real implementation, you should obtain randomness via a Runtime::RandomGenerator (I think from factory context), to allow proper dependency injection and deterministic tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a reasonable explanation for this. But we'll talk about it in the next PRs |
||
| }; | ||
|
|
||
| using SamplingStrategyPtr = std::unique_ptr<SamplingStrategy>; | ||
|
|
||
| } // namespace XRay | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/common/time.h" | ||
| #include "envoy/tracing/http_tracer.h" | ||
|
|
||
| #include "extensions/tracers/xray/sampling_strategy.h" | ||
|
|
||
| #include "absl/strings/string_view.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace XRay { | ||
|
|
||
| class Tracer { | ||
| public: | ||
| Tracer(absl::string_view segment_name, TimeSource& time_source) | ||
| : segment_name_(segment_name), time_source_(time_source) { | ||
| UNREFERENCED_PARAMETER(time_source_); | ||
| } | ||
|
|
||
| /** | ||
| * Starts a tracing span for XRay | ||
| */ | ||
| Tracing::SpanPtr startSpan() { return nullptr; } | ||
|
|
||
| private: | ||
| const std::string segment_name_; | ||
| TimeSource& time_source_; | ||
| }; | ||
|
|
||
| } // namespace XRay | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
Uh oh!
There was an error while loading. Please reload this page.