-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skeleton of a tracer for AWS X-Ray (#8526)
A skeleton tracer to incrementally add support for AWS X-Ray Risk Level: Low Testing: unit tests for functionality in util - the rest of files have no business logic to test yet Signed-off-by: Marco Magdy <mmagdy@gmail.com>
- Loading branch information
1 parent
37544e6
commit f68368f
Showing
21 changed files
with
689 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
}; | ||
|
||
using SamplingStrategyPtr = std::unique_ptr<SamplingStrategy>; | ||
|
||
} // namespace XRay | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.