-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Made stats sinks a statically registered component #1506
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c427c6
Made Stats Sinks a statically registered component
mrice32 42ea55a
corrected doc formatting
mrice32 cf5fac0
Merge branch 'master' into sta_reg
mrice32 f99b5a5
Fixed post-merge issues and simplified PR
mrice32 441b3a7
removed debug lines
mrice32 d78014d
Responded to comments and added additional tests
mrice32 9dcc3a5
Modified the construction of proto in new tests
mrice32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,24 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "statsd_lib", | ||
srcs = ["statsd.cc"], | ||
hdrs = ["statsd.h"], | ||
external_deps = [ | ||
"envoy_bootstrap", | ||
], | ||
deps = [ | ||
"//include/envoy/registry", | ||
"//source/common/network:address_lib", | ||
"//source/common/stats:statsd_lib", | ||
"//source/server:configuration_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,53 @@ | ||
#include "server/config/stats/statsd.h" | ||
|
||
#include <string> | ||
|
||
#include "envoy/registry/registry.h" | ||
|
||
#include "common/stats/statsd.h" | ||
|
||
#include "api/bootstrap.pb.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
|
||
Stats::SinkPtr StatsdSinkFactory::createStatsSink(const Protobuf::Message& config, | ||
Server::Instance& server) { | ||
|
||
const auto& statsd_sink = dynamic_cast<const envoy::api::v2::StatsdSink&>(config); | ||
switch (statsd_sink.statsd_specifier_case()) { | ||
case envoy::api::v2::StatsdSink::kAddress: { | ||
Network::Address::InstanceConstSharedPtr address = | ||
Network::Utility::fromProtoAddress(statsd_sink.address()); | ||
ENVOY_LOG(info, "statsd UDP ip address: {}", address->asString()); | ||
return Stats::SinkPtr( | ||
new Stats::Statsd::UdpStatsdSink(server.threadLocal(), std::move(address))); | ||
break; | ||
} | ||
case envoy::api::v2::StatsdSink::kTcpClusterName: | ||
ENVOY_LOG(info, "statsd TCP cluster: {}", statsd_sink.tcp_cluster_name()); | ||
return Stats::SinkPtr(new Stats::Statsd::TcpStatsdSink( | ||
server.localInfo(), statsd_sink.tcp_cluster_name(), server.threadLocal(), | ||
server.clusterManager(), server.stats())); | ||
break; | ||
default: | ||
throw EnvoyException( | ||
fmt::format("No tcp_cluster_name or address provided for {} Stats::Sink config", name())); | ||
} | ||
} | ||
|
||
ProtobufTypes::MessagePtr StatsdSinkFactory::createEmptyConfigProto() { | ||
return std::unique_ptr<envoy::api::v2::StatsdSink>(new envoy::api::v2::StatsdSink()); | ||
} | ||
|
||
std::string StatsdSinkFactory::name() { return "envoy.statsd"; } | ||
|
||
/** | ||
* Static registration for the statsd sink factory. @see RegisterFactory. | ||
*/ | ||
static Registry::RegisterFactory<StatsdSinkFactory, StatsSinkFactory> register_; | ||
|
||
} // 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,28 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/server/instance.h" | ||
|
||
#include "server/configuration_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
|
||
/** | ||
* Config registration for the tcp statsd sink. @see StatsSinkFactory. | ||
*/ | ||
class StatsdSinkFactory : Logger::Loggable<Logger::Id::config>, public StatsSinkFactory { | ||
public: | ||
// StatsSinkFactory | ||
Stats::SinkPtr createStatsSink(const Protobuf::Message& config, Instance& server) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
|
||
std::string name() override; | ||
}; | ||
|
||
} // 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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Any header that is depended upon in
.{cc,h}
should be directly reflected in thedeps
in theBUILD
file. This avoids surprises when A depends on B providing C, but later on, B no longer depends on C. Since we lack tool automation for this in OSS, we don't really enforce it (I'm sure I'm guilty of many breaches of this), but best to try and shoot for it. Basically, you want IWYU (include what you use, i.e. have all include headers in a file directly for symbols that appear in the file) and thenBUILD
dep
pointing at libs providing the headers.