1
#include "source/extensions/stat_sinks/graphite_statsd/config.h"
2

            
3
#include <memory>
4

            
5
#include "envoy/extensions/stat_sinks/graphite_statsd/v3/graphite_statsd.pb.h"
6
#include "envoy/extensions/stat_sinks/graphite_statsd/v3/graphite_statsd.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
#include "source/extensions/stat_sinks/common/statsd/tag_formats.h"
12

            
13
namespace Envoy {
14
namespace Extensions {
15
namespace StatSinks {
16
namespace GraphiteStatsd {
17

            
18
absl::StatusOr<Stats::SinkPtr>
19
GraphiteStatsdSinkFactory::createStatsSink(const Protobuf::Message& config,
20
5
                                           Server::Configuration::ServerFactoryContext& server) {
21

            
22
5
  const auto& statsd_sink = MessageUtil::downcastAndValidate<
23
5
      const envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink&>(
24
5
      config, server.messageValidationContext().staticValidationVisitor());
25
5
  switch (statsd_sink.statsd_specifier_case()) {
26
4
  case envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink::StatsdSpecifierCase::
27
4
      kAddress: {
28
4
    auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address());
29
4
    RETURN_IF_NOT_OK_REF(address_or_error.status());
30
4
    Network::Address::InstanceConstSharedPtr address = address_or_error.value();
31
4
    ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString());
32
4
    absl::optional<uint64_t> max_bytes;
33
4
    if (statsd_sink.has_max_bytes_per_datagram()) {
34
1
      max_bytes = statsd_sink.max_bytes_per_datagram().value();
35
1
    }
36
4
    return std::make_unique<Common::Statsd::UdpStatsdSink>(server.threadLocal(), std::move(address),
37
4
                                                           true, statsd_sink.prefix(), max_bytes,
38
4
                                                           Common::Statsd::getGraphiteTagFormat());
39
4
  }
40
  case envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink::StatsdSpecifierCase::
41
      STATSD_SPECIFIER_NOT_SET:
42
    break;
43
5
  }
44
  PANIC("unexpected statsd specifier enum");
45
}
46

            
47
8
ProtobufTypes::MessagePtr GraphiteStatsdSinkFactory::createEmptyConfigProto() {
48
8
  return std::make_unique<envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink>();
49
8
}
50

            
51
13
std::string GraphiteStatsdSinkFactory::name() const { return "envoy.stat_sinks.graphite_statsd"; }
52

            
53
/**
54
 * Static registration for the statsd sink factory. @see RegisterFactory.
55
 */
56
LEGACY_REGISTER_FACTORY(GraphiteStatsdSinkFactory, Server::Configuration::StatsSinkFactory,
57
                        "envoy.graphite_statsd");
58

            
59
} // namespace GraphiteStatsd
60
} // namespace StatSinks
61
} // namespace Extensions
62
} // namespace Envoy