Line data Source code
1 : #include "source/extensions/stat_sinks/statsd/config.h" 2 : 3 : #include <memory> 4 : 5 : #include "envoy/config/metrics/v3/stats.pb.h" 6 : #include "envoy/config/metrics/v3/stats.pb.validate.h" 7 : #include "envoy/registry/registry.h" 8 : 9 : #include "source/common/network/resolver_impl.h" 10 : #include "source/extensions/stat_sinks/common/statsd/statsd.h" 11 : 12 : namespace Envoy { 13 : namespace Extensions { 14 : namespace StatSinks { 15 : namespace Statsd { 16 : 17 : Stats::SinkPtr 18 : StatsdSinkFactory::createStatsSink(const Protobuf::Message& config, 19 0 : Server::Configuration::ServerFactoryContext& server) { 20 : 21 0 : const auto& statsd_sink = 22 0 : MessageUtil::downcastAndValidate<const envoy::config::metrics::v3::StatsdSink&>( 23 0 : config, server.messageValidationContext().staticValidationVisitor()); 24 0 : switch (statsd_sink.statsd_specifier_case()) { 25 0 : case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kAddress: { 26 0 : Network::Address::InstanceConstSharedPtr address = 27 0 : Network::Address::resolveProtoAddress(statsd_sink.address()); 28 0 : ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString()); 29 0 : return std::make_unique<Common::Statsd::UdpStatsdSink>(server.threadLocal(), std::move(address), 30 0 : false, statsd_sink.prefix()); 31 0 : } 32 0 : case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kTcpClusterName: 33 0 : ENVOY_LOG(debug, "statsd TCP cluster: {}", statsd_sink.tcp_cluster_name()); 34 0 : return std::make_unique<Common::Statsd::TcpStatsdSink>( 35 0 : server.localInfo(), statsd_sink.tcp_cluster_name(), server.threadLocal(), 36 0 : server.clusterManager(), server.scope(), statsd_sink.prefix()); 37 0 : case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::STATSD_SPECIFIER_NOT_SET: 38 0 : break; // Fall through to PANIC 39 0 : } 40 0 : PANIC("unexpected statsd specifier case num"); 41 0 : } 42 : 43 2 : ProtobufTypes::MessagePtr StatsdSinkFactory::createEmptyConfigProto() { 44 2 : return std::make_unique<envoy::config::metrics::v3::StatsdSink>(); 45 2 : } 46 : 47 42 : std::string StatsdSinkFactory::name() const { return StatsdName; } 48 : 49 : /** 50 : * Static registration for the statsd sink factory. @see RegisterFactory. 51 : */ 52 : LEGACY_REGISTER_FACTORY(StatsdSinkFactory, Server::Configuration::StatsSinkFactory, "envoy.statsd"); 53 : 54 : } // namespace Statsd 55 : } // namespace StatSinks 56 : } // namespace Extensions 57 : } // namespace Envoy