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
absl::StatusOr<Stats::SinkPtr>
18
StatsdSinkFactory::createStatsSink(const Protobuf::Message& config,
19
12
                                   Server::Configuration::ServerFactoryContext& server) {
20

            
21
12
  const auto& statsd_sink =
22
12
      MessageUtil::downcastAndValidate<const envoy::config::metrics::v3::StatsdSink&>(
23
12
          config, server.messageValidationContext().staticValidationVisitor());
24
12
  switch (statsd_sink.statsd_specifier_case()) {
25
3
  case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kAddress: {
26
3
    auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address());
27
3
    RETURN_IF_NOT_OK_REF(address_or_error.status());
28
3
    Network::Address::InstanceConstSharedPtr address = address_or_error.value();
29
3
    ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString());
30
3
    return std::make_unique<Common::Statsd::UdpStatsdSink>(server.threadLocal(), std::move(address),
31
3
                                                           false, statsd_sink.prefix());
32
3
  }
33
8
  case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kTcpClusterName:
34
8
    ENVOY_LOG(debug, "statsd TCP cluster: {}", statsd_sink.tcp_cluster_name());
35
8
    return Common::Statsd::TcpStatsdSink::create(server.localInfo(), statsd_sink.tcp_cluster_name(),
36
8
                                                 server.threadLocal(), server.clusterManager(),
37
8
                                                 server.scope(), statsd_sink.prefix());
38
  case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::STATSD_SPECIFIER_NOT_SET:
39
    break; // Fall through to PANIC
40
12
  }
41
  PANIC("unexpected statsd specifier case num");
42
}
43

            
44
21
ProtobufTypes::MessagePtr StatsdSinkFactory::createEmptyConfigProto() {
45
21
  return std::make_unique<envoy::config::metrics::v3::StatsdSink>();
46
21
}
47

            
48
61
std::string StatsdSinkFactory::name() const { return StatsdName; }
49

            
50
/**
51
 * Static registration for the statsd sink factory. @see RegisterFactory.
52
 */
53
LEGACY_REGISTER_FACTORY(StatsdSinkFactory, Server::Configuration::StatsSinkFactory, "envoy.statsd");
54

            
55
} // namespace Statsd
56
} // namespace StatSinks
57
} // namespace Extensions
58
} // namespace Envoy