Skip to content
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

repo reorg: move stat sinks #2970

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/common/config/well_known_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ typedef ConstSingleton<HttpTracerNameValues> HttpTracerNames;

/**
* Well-known stats sink names.
* TODO(mattklein123): Move this to extensions directory when the migration is complete.
* TODO(mattklein123): New filters should use the well known name: envoy.stat_sinks.name.
*/
class StatsSinkNameValues {
public:
Expand Down
34 changes: 0 additions & 34 deletions source/common/stats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "statsd_lib",
srcs = ["statsd.cc"],
hdrs = ["statsd.h"],
deps = [
"//include/envoy/event:dispatcher_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/network:connection_interface",
"//include/envoy/stats:stats_interface",
"//include/envoy/thread_local:thread_local_interface",
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/buffer:buffer_lib",
"//source/common/common:assert_lib",
"//source/common/common:utility_lib",
"//source/common/config:utility_lib",
],
)

envoy_cc_library(
name = "metrics_service_grpc_lib",
srcs = ["grpc_metrics_service_impl.cc"],
hdrs = ["grpc_metrics_service_impl.h"],
deps = [
"//include/envoy/grpc:async_client_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/singleton:instance_interface",
"//include/envoy/thread_local:thread_local_interface",
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/common:assert_lib",
"//source/common/grpc:async_client_lib",
"@envoy_api//envoy/service/metrics/v2:metrics_service_cc",
],
)

envoy_cc_library(
name = "thread_local_store_lib",
srcs = ["thread_local_store.cc"],
Expand Down
3 changes: 0 additions & 3 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ envoy_cc_library(
"//source/server/config/network:http_connection_manager_lib",
"//source/server/config/network:raw_buffer_socket_lib",
"//source/server/config/network:ssl_socket_lib",
"//source/server/config/stats:dog_statsd_lib",
"//source/server/config/stats:metrics_service_lib",
"//source/server/config/stats:statsd_lib",
"//source/server/http:health_check_lib",
] + envoy_all_extensions(),
)
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/all_extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ def envoy_all_extensions(repository = ""):
repository + "//source/extensions/filters/network/ratelimit:config",
repository + "//source/extensions/filters/network/redis_proxy:config",
repository + "//source/extensions/filters/network/tcp_proxy:config",
repository + "//source/extensions/stat_sinks/dog_statsd:config",
repository + "//source/extensions/stat_sinks/metrics_service:config",
repository + "//source/extensions/stat_sinks/statsd:config",
]

27 changes: 27 additions & 0 deletions source/extensions/stat_sinks/common/statsd/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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"],
deps = [
"//include/envoy/event:dispatcher_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/network:connection_interface",
"//include/envoy/stats:stats_interface",
"//include/envoy/thread_local:thread_local_interface",
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/buffer:buffer_lib",
"//source/common/common:assert_lib",
"//source/common/common:utility_lib",
"//source/common/config:utility_lib",
],
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common/stats/statsd.h"
#include "extensions/stat_sinks/common/statsd/statsd.h"

#include <chrono>
#include <cstdint>
Expand All @@ -14,7 +14,9 @@
#include "common/config/utility.h"

namespace Envoy {
namespace Stats {
namespace Extensions {
namespace StatSinks {
namespace Common {
namespace Statsd {

Writer::Writer(Network::Address::InstanceConstSharedPtr address) {
Expand Down Expand Up @@ -43,42 +45,42 @@ UdpStatsdSink::UdpStatsdSink(ThreadLocal::SlotAllocator& tls,
});
}

void UdpStatsdSink::flushCounter(const Counter& counter, uint64_t delta) {
void UdpStatsdSink::flushCounter(const Stats::Counter& counter, uint64_t delta) {
const std::string message(
fmt::format("envoy.{}:{}|c{}", getName(counter), delta, buildTagStr(counter.tags())));
tls_->getTyped<Writer>().write(message);
}

void UdpStatsdSink::flushGauge(const Gauge& gauge, uint64_t value) {
void UdpStatsdSink::flushGauge(const Stats::Gauge& gauge, uint64_t value) {
const std::string message(
fmt::format("envoy.{}:{}|g{}", getName(gauge), value, buildTagStr(gauge.tags())));
tls_->getTyped<Writer>().write(message);
}

void UdpStatsdSink::onHistogramComplete(const Histogram& histogram, uint64_t value) {
void UdpStatsdSink::onHistogramComplete(const Stats::Histogram& histogram, uint64_t value) {
// For statsd histograms are all timers.
const std::string message(fmt::format("envoy.{}:{}|ms{}", getName(histogram),
std::chrono::milliseconds(value).count(),
buildTagStr(histogram.tags())));
tls_->getTyped<Writer>().write(message);
}

const std::string UdpStatsdSink::getName(const Metric& metric) {
const std::string UdpStatsdSink::getName(const Stats::Metric& metric) {
if (use_tag_) {
return metric.tagExtractedName();
} else {
return metric.name();
}
}

const std::string UdpStatsdSink::buildTagStr(const std::vector<Tag>& tags) {
const std::string UdpStatsdSink::buildTagStr(const std::vector<Stats::Tag>& tags) {
if (!use_tag_ || tags.empty()) {
return "";
}

std::vector<std::string> tag_strings;
tag_strings.reserve(tags.size());
for (const Tag& tag : tags) {
for (const Stats::Tag& tag : tags) {
tag_strings.emplace_back(tag.name_ + ":" + tag.value_);
}
return "|#" + StringUtil::join(tag_strings, ",");
Expand Down Expand Up @@ -227,5 +229,7 @@ uint64_t TcpStatsdSink::TlsSink::usedBuffer() {
}

} // namespace Statsd
} // namespace Stats
} // namespace Common
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once

#include <chrono>
#include <cstdint>
#include <string>

#include "envoy/local_info/local_info.h"
#include "envoy/network/connection.h"
#include "envoy/stats/stats.h"
Expand All @@ -13,7 +9,9 @@
#include "common/buffer/buffer_impl.h"

namespace Envoy {
namespace Stats {
namespace Extensions {
namespace StatSinks {
namespace Common {
namespace Statsd {

/**
Expand All @@ -37,7 +35,7 @@ class Writer : public ThreadLocal::ThreadLocalObject {
/**
* Implementation of Sink that writes to a UDP statsd address.
*/
class UdpStatsdSink : public Sink {
class UdpStatsdSink : public Stats::Sink {
public:
UdpStatsdSink(ThreadLocal::SlotAllocator& tls, Network::Address::InstanceConstSharedPtr address,
const bool use_tag);
Expand All @@ -51,18 +49,18 @@ class UdpStatsdSink : public Sink {

// Stats::Sink
void beginFlush() override {}
void flushCounter(const Counter& counter, uint64_t delta) override;
void flushGauge(const Gauge& gauge, uint64_t value) override;
void flushCounter(const Stats::Counter& counter, uint64_t delta) override;
void flushGauge(const Stats::Gauge& gauge, uint64_t value) override;
void endFlush() override {}
void onHistogramComplete(const Histogram& histogram, uint64_t value) override;
void onHistogramComplete(const Stats::Histogram& histogram, uint64_t value) override;

// Called in unit test to validate writer construction and address.
int getFdForTests() { return tls_->getTyped<Writer>().getFdForTests(); }
bool getUseTagForTest() { return use_tag_; }

private:
const std::string getName(const Metric& metric);
const std::string buildTagStr(const std::vector<Tag>& tags);
const std::string getName(const Stats::Metric& metric);
const std::string buildTagStr(const std::vector<Stats::Tag>& tags);

ThreadLocal::SlotPtr tls_;
Network::Address::InstanceConstSharedPtr server_address_;
Expand All @@ -72,7 +70,7 @@ class UdpStatsdSink : public Sink {
/**
* Per thread implementation of a TCP stats flusher for statsd.
*/
class TcpStatsdSink : public Sink {
class TcpStatsdSink : public Stats::Sink {
public:
TcpStatsdSink(const LocalInfo::LocalInfo& local_info, const std::string& cluster_name,
ThreadLocal::SlotAllocator& tls, Upstream::ClusterManager& cluster_manager,
Expand All @@ -81,17 +79,17 @@ class TcpStatsdSink : public Sink {
// Stats::Sink
void beginFlush() override { tls_->getTyped<TlsSink>().beginFlush(true); }

void flushCounter(const Counter& counter, uint64_t delta) override {
void flushCounter(const Stats::Counter& counter, uint64_t delta) override {
tls_->getTyped<TlsSink>().flushCounter(counter.name(), delta);
}

void flushGauge(const Gauge& gauge, uint64_t value) override {
void flushGauge(const Stats::Gauge& gauge, uint64_t value) override {
tls_->getTyped<TlsSink>().flushGauge(gauge.name(), value);
}

void endFlush() override { tls_->getTyped<TlsSink>().endFlush(true); }

void onHistogramComplete(const Histogram& histogram, uint64_t value) override {
void onHistogramComplete(const Stats::Histogram& histogram, uint64_t value) override {
// For statsd histograms are all timers.
tls_->getTyped<TlsSink>().onTimespanComplete(histogram.name(),
std::chrono::milliseconds(value));
Expand Down Expand Up @@ -141,5 +139,7 @@ class TcpStatsdSink : public Sink {
};

} // namespace Statsd
} // namespace Stats
} // namespace Common
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy
26 changes: 26 additions & 0 deletions source/extensions/stat_sinks/dog_statsd/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
licenses(["notice"]) # Apache 2
# Stats sink for the DataDog (https://www.datadoghq.com/) variant of the statsd protocol
# (https://docs.datadoghq.com/developers/dogstatsd/).

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "config",
srcs = ["config.cc"],
hdrs = ["config.h"],
deps = [
"//include/envoy/registry",
"//source/common/config:well_known_names",
"//source/common/network:address_lib",
"//source/common/network:resolver_lib",
"//source/extensions/stat_sinks/common/statsd:statsd_lib",
"//source/server:configuration_lib",
"@envoy_api//envoy/config/metrics/v2:stats_cc",
],
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "server/config/stats/dog_statsd.h"

#include <string>
#include "extensions/stat_sinks/dog_statsd/config.h"

#include "envoy/config/metrics/v2/stats.pb.h"
#include "envoy/config/metrics/v2/stats.pb.validate.h"
#include "envoy/registry/registry.h"

#include "common/config/well_known_names.h"
#include "common/network/resolver_impl.h"
#include "common/stats/statsd.h"

#include "extensions/stat_sinks/common/statsd/statsd.h"

namespace Envoy {
namespace Server {
namespace Configuration {
namespace Extensions {
namespace StatSinks {
namespace DogStatsd {

Stats::SinkPtr DogStatsdSinkFactory::createStatsSink(const Protobuf::Message& config,
Server::Instance& server) {
Expand All @@ -21,8 +21,8 @@ Stats::SinkPtr DogStatsdSinkFactory::createStatsSink(const Protobuf::Message& co
Network::Address::InstanceConstSharedPtr address =
Network::Address::resolveProtoAddress(sink_config.address());
ENVOY_LOG(debug, "dog_statsd UDP ip address: {}", address->asString());
return Stats::SinkPtr(
new Stats::Statsd::UdpStatsdSink(server.threadLocal(), std::move(address), true));
return std::make_unique<Common::Statsd::UdpStatsdSink>(server.threadLocal(), std::move(address),
true);
}

ProtobufTypes::MessagePtr DogStatsdSinkFactory::createEmptyConfigProto() {
Expand All @@ -35,8 +35,10 @@ std::string DogStatsdSinkFactory::name() { return Config::StatsSinkNames::get().
/**
* Static registration for the this sink factory. @see RegisterFactory.
*/
static Registry::RegisterFactory<DogStatsdSinkFactory, StatsSinkFactory> register_;
static Registry::RegisterFactory<DogStatsdSinkFactory, Server::Configuration::StatsSinkFactory>
register_;

} // namespace Configuration
} // namespace Server
} // namespace DogStatsd
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#pragma once

#include <string>

#include "envoy/server/instance.h"

#include "server/configuration_impl.h"

namespace Envoy {
namespace Server {
namespace Configuration {
namespace Extensions {
namespace StatSinks {
namespace DogStatsd {

/**
* Config registration for the DogStatsD compatible statsd sink. @see StatsSinkFactory.
*/
class DogStatsdSinkFactory : Logger::Loggable<Logger::Id::config>, public StatsSinkFactory {
class DogStatsdSinkFactory : Logger::Loggable<Logger::Id::config>,
public Server::Configuration::StatsSinkFactory {
public:
Stats::SinkPtr createStatsSink(const Protobuf::Message& config, Instance& server) override;
Stats::SinkPtr createStatsSink(const Protobuf::Message& config,
Server::Instance& server) override;

ProtobufTypes::MessagePtr createEmptyConfigProto() override;

std::string name() override;
};

} // namespace Configuration
} // namespace Server
} // namespace DogStatsd
} // namespace StatSinks
} // namespace Extensions
} // namespace Envoy
Loading