-
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.
config: refactor tracers to use Config::Utility (#4984)
Another PR for #4475. Refactor tracers config: move interface to include/ Introduce FactoryBase to reduce boiler plate Use Config::Utility to convert opaque config Risk Level: Low Testing: CI Docs Changes: N/A Release Notes: N/A Signed-off-by: Lizan Zhou <[email protected]>
- Loading branch information
Showing
24 changed files
with
209 additions
and
171 deletions.
There are no files selected for viewing
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 @@ | ||
#pragma once | ||
|
||
#include "envoy/common/pure.h" | ||
#include "envoy/server/instance.h" | ||
#include "envoy/tracing/http_tracer.h" | ||
|
||
#include "common/protobuf/protobuf.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
|
||
/** | ||
* Implemented by each Tracer and registered via Registry::registerFactory() or the convenience | ||
* class RegisterFactory. | ||
*/ | ||
class TracerFactory { | ||
public: | ||
virtual ~TracerFactory() {} | ||
|
||
/** | ||
* Create a particular HttpTracer implementation. If the implementation is unable to produce an | ||
* HttpTracer with the provided parameters, it should throw an EnvoyException in the case of | ||
* general error or a Json::Exception if the json configuration is erroneous. The returned | ||
* pointer should always be valid. | ||
* @param config supplies the proto configuration for the HttpTracer | ||
* @param server supplies the server instance | ||
*/ | ||
virtual Tracing::HttpTracerPtr createHttpTracer(const Protobuf::Message& config, | ||
Instance& server) PURE; | ||
|
||
/** | ||
* @return ProtobufTypes::MessagePtr create empty config proto message for v2. The tracing | ||
* config, which arrives in an opaque message, will be parsed into this empty proto. | ||
*/ | ||
virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; | ||
|
||
/** | ||
* Returns the identifying name for a particular implementation of tracer produced by the | ||
* factory. | ||
*/ | ||
virtual std::string name() PURE; | ||
}; | ||
|
||
} // namespace Configuration | ||
} // namespace Server | ||
} // 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,19 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "factory_base_lib", | ||
hdrs = ["factory_base.h"], | ||
deps = [ | ||
"//include/envoy/server:instance_interface", | ||
"//include/envoy/server:tracer_config_interface", | ||
"//source/common/config:utility_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,43 @@ | ||
#pragma once | ||
|
||
#include "envoy/server/instance.h" | ||
#include "envoy/server/tracer_config.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace Common { | ||
|
||
/** | ||
* Common base class for tracer factory registrations. Removes a substantial amount of | ||
* boilerplate. | ||
*/ | ||
template <class ConfigProto> class FactoryBase : public Server::Configuration::TracerFactory { | ||
public: | ||
// Server::Configuration::TracerFactory | ||
virtual Tracing::HttpTracerPtr createHttpTracer(const Protobuf::Message& config, | ||
Server::Instance& server) override { | ||
return createHttpTracerTyped(MessageUtil::downcastAndValidate<const ConfigProto&>(config), | ||
server); | ||
} | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return std::make_unique<ConfigProto>(); | ||
} | ||
|
||
std::string name() override { return name_; } | ||
|
||
protected: | ||
FactoryBase(const std::string& name) : name_(name) {} | ||
|
||
private: | ||
virtual Tracing::HttpTracerPtr createHttpTracerTyped(const ConfigProto& proto_config, | ||
Server::Instance& server) PURE; | ||
|
||
const std::string name_; | ||
}; | ||
|
||
} // namespace Common | ||
} // 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
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
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
Oops, something went wrong.