Skip to content
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
35 changes: 35 additions & 0 deletions include/envoy/local_info/local_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "envoy/common/pure.h"

namespace LocalInfo {

/**
* Information about the local environment.
*/
class LocalInfo {
public:
virtual ~LocalInfo() {}

/**
* Human readable network address. E.g., "127.0.0.1".
*/
virtual const std::string& address() const PURE;

/**
* Human readable zone name. E.g., "us-east-1a".
*/
virtual const std::string& zoneName() const PURE;

/**
* Human readable cluster name. E.g., "eta".
*/
virtual const std::string& clusterName() const PURE;

/**
* Human readable individual node name. E.g., "i-123456".
*/
virtual const std::string& nodeName() const PURE;
};

} // LocalInfo
5 changes: 3 additions & 2 deletions include/envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "envoy/access_log/access_log.h"
#include "envoy/api/api.h"
#include "envoy/local_info/local_info.h"
#include "envoy/ratelimit/ratelimit.h"
#include "envoy/runtime/runtime.h"
#include "envoy/server/admin.h"
Expand Down Expand Up @@ -160,9 +161,9 @@ class Instance {
virtual ThreadLocal::Instance& threadLocal() PURE;

/**
* @return the local IP address of the server
* @return information about the local environment the server is running in.
*/
virtual const std::string& getLocalAddress() PURE;
virtual const LocalInfo::LocalInfo& localInfo() PURE;
};

} // Server
15 changes: 0 additions & 15 deletions include/envoy/server/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ class Options {
*/
virtual uint64_t restartEpoch() PURE;

/**
* @return const std::string& the service cluster name where the server is running.
*/
virtual const std::string& serviceClusterName() PURE;

/**
* @return const std::string& the service node name where the server is running.
*/
virtual const std::string& serviceNodeName() PURE;

/**
* @return const std::string& the service zone where the server is running.
*/
virtual const std::string& serviceZone() PURE;

/**
* @return std::chrono::milliseconds the duration in msec between log flushes.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these comments to LocalInfo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already fixed.

*/
Expand Down
1 change: 0 additions & 1 deletion include/envoy/upstream/cluster_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class ClusterManager {
* Global configuration for any SDS clusters.
*/
struct SdsConfig {
std::string local_zone_name_;
std::string sds_cluster_name_;
std::chrono::milliseconds refresh_delay_;
};
Expand Down
14 changes: 7 additions & 7 deletions source/common/http/async_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const AsyncRequestImpl::NullShadowPolicy AsyncRequestImpl::RouteEntryImpl::shado
const AsyncRequestImpl::NullVirtualHost AsyncRequestImpl::RouteEntryImpl::virtual_host_;

AsyncClientImpl::AsyncClientImpl(const Upstream::ClusterInfo& cluster, Stats::Store& stats_store,
Event::Dispatcher& dispatcher, const std::string& local_zone_name,
Event::Dispatcher& dispatcher,
const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cm, Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
Router::ShadowWriterPtr&& shadow_writer,
const std::string& local_address)
: cluster_(cluster), config_("http.async-client.", local_zone_name, stats_store, cm, runtime,
random, std::move(shadow_writer), true),
dispatcher_(dispatcher), local_address_(local_address) {}
Router::ShadowWriterPtr&& shadow_writer)
: cluster_(cluster), config_("http.async-client.", local_info, stats_store, cm, runtime, random,
std::move(shadow_writer), true),
dispatcher_(dispatcher) {}

AsyncClientImpl::~AsyncClientImpl() {
while (!active_requests_.empty()) {
Expand Down Expand Up @@ -50,7 +50,7 @@ AsyncRequestImpl::AsyncRequestImpl(MessagePtr&& request, AsyncClientImpl& parent
router_.setDecoderFilterCallbacks(*this);
request_->headers().insertEnvoyInternalRequest().value(
Headers::get().EnvoyInternalRequestValues.True);
request_->headers().insertForwardedFor().value(parent_.local_address_);
request_->headers().insertForwardedFor().value(parent_.config_.local_info_.address());
router_.decodeHeaders(request_->headers(), !request_->body());
if (!complete_ && request_->body()) {
router_.decodeData(*request_->body(), true);
Expand Down
6 changes: 2 additions & 4 deletions source/common/http/async_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class AsyncRequestImpl;
class AsyncClientImpl final : public AsyncClient {
public:
AsyncClientImpl(const Upstream::ClusterInfo& cluster, Stats::Store& stats_store,
Event::Dispatcher& dispatcher, const std::string& local_zone_name,
Event::Dispatcher& dispatcher, const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cm, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, Router::ShadowWriterPtr&& shadow_writer,
const std::string& local_address);
Runtime::RandomGenerator& random, Router::ShadowWriterPtr&& shadow_writer);
~AsyncClientImpl();

// Http::AsyncClient
Expand All @@ -38,7 +37,6 @@ class AsyncClientImpl final : public AsyncClient {
Router::FilterConfig config_;
Event::Dispatcher& dispatcher_;
std::list<std::unique_ptr<AsyncRequestImpl>> active_requests_;
const std::string local_address_;

friend class AsyncRequestImpl;
};
Expand Down
4 changes: 2 additions & 2 deletions source/common/http/filter/ratelimit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ FilterHeadersStatus Filter::decodeHeaders(HeaderMap& headers, bool) {
fmt::format("ratelimit.{}.http_filter_enabled", route_key), 100)) {
continue;
}
rate_limit.populateDescriptors(*route, descriptors, config_->localServiceCluster(), headers,
callbacks_->downstreamAddress());
rate_limit.populateDescriptors(*route, descriptors, config_->localInfo().clusterName(),
headers, callbacks_->downstreamAddress());
}

if (!descriptors.empty()) {
Expand Down
10 changes: 5 additions & 5 deletions source/common/http/filter/ratelimit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "envoy/http/filter.h"
#include "envoy/local_info/local_info.h"
#include "envoy/ratelimit/ratelimit.h"
#include "envoy/runtime/runtime.h"

Expand All @@ -15,22 +16,21 @@ namespace RateLimit {
*/
class FilterConfig {
public:
FilterConfig(const Json::Object& config, const std::string& local_service_cluster,
FilterConfig(const Json::Object& config, const LocalInfo::LocalInfo& local_info,
Stats::Store& stats_store, Runtime::Loader& runtime)
: domain_(config.getString("domain")), stage_(config.getInteger("stage", 0)),
local_service_cluster_(local_service_cluster), stats_store_(stats_store),
runtime_(runtime) {}
local_info_(local_info), stats_store_(stats_store), runtime_(runtime) {}

const std::string& domain() const { return domain_; }
const std::string& localServiceCluster() const { return local_service_cluster_; }
const LocalInfo::LocalInfo& localInfo() const { return local_info_; }
int64_t stage() const { return stage_; }
Runtime::Loader& runtime() { return runtime_; }
Stats::Store& stats() { return stats_store_; }

private:
const std::string domain_;
int64_t stage_;
const std::string local_service_cluster_;
const LocalInfo::LocalInfo& local_info_;
Stats::Store& stats_store_;
Runtime::Loader& runtime_;
};
Expand Down
26 changes: 26 additions & 0 deletions source/common/local_info/local_info_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "envoy/local_info/local_info.h"

namespace LocalInfo {

class LocalInfoImpl : public LocalInfo {
public:
LocalInfoImpl(const std::string address, const std::string zone_name,
const std::string cluster_name, const std::string node_name)
: address_(address), zone_name_(zone_name), cluster_name_(cluster_name),
node_name_(node_name) {}

const std::string& address() const override { return address_; }
const std::string& zoneName() const override { return zone_name_; }
const std::string& clusterName() const override { return cluster_name_; }
const std::string& nodeName() const override { return node_name_; }

private:
const std::string address_;
const std::string zone_name_;
const std::string cluster_name_;
const std::string node_name_;
};

} // LocalInfo
18 changes: 9 additions & 9 deletions source/common/router/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ void Filter::chargeUpstreamCode(const Http::HeaderMap& response_headers,
Http::CodeUtility::ResponseStatInfo info{
config_.stats_store_, cluster_->statPrefix(), response_headers, internal_request,
route_->virtualHost().name(), request_vcluster_ ? request_vcluster_->name() : "",
config_.service_zone_, upstreamZone(upstream_host), is_canary};
config_.local_info_.zoneName(), upstreamZone(upstream_host), is_canary};

Http::CodeUtility::chargeResponseStat(info);

for (const std::string& alt_prefix : alt_stat_prefixes_) {
Http::CodeUtility::ResponseStatInfo info{config_.stats_store_, alt_prefix, response_headers,
internal_request, "", "", config_.service_zone_,
upstreamZone(upstream_host), is_canary};
Http::CodeUtility::ResponseStatInfo info{
config_.stats_store_, alt_prefix, response_headers, internal_request, "", "",
config_.local_info_.zoneName(), upstreamZone(upstream_host), is_canary};

Http::CodeUtility::chargeResponseStat(info);
}
Expand Down Expand Up @@ -481,16 +481,16 @@ void Filter::onUpstreamComplete() {
Http::CodeUtility::ResponseTimingInfo info{
config_.stats_store_, cluster_->statPrefix(), response_time,
upstream_request_->upstream_canary_, internal_request, route_->virtualHost().name(),
request_vcluster_ ? request_vcluster_->name() : "", config_.service_zone_,
request_vcluster_ ? request_vcluster_->name() : "", config_.local_info_.zoneName(),
upstreamZone(upstream_request_->upstream_host_)};

Http::CodeUtility::chargeResponseTiming(info);

for (const std::string& alt_prefix : alt_stat_prefixes_) {
Http::CodeUtility::ResponseTimingInfo info{config_.stats_store_, alt_prefix, response_time,
upstream_request_->upstream_canary_,
internal_request, "", "", config_.service_zone_,
upstreamZone(upstream_request_->upstream_host_)};
Http::CodeUtility::ResponseTimingInfo info{
config_.stats_store_, alt_prefix, response_time, upstream_request_->upstream_canary_,
internal_request, "", "", config_.local_info_.zoneName(),
upstreamZone(upstream_request_->upstream_host_)};

Http::CodeUtility::chargeResponseTiming(info);
}
Expand Down
11 changes: 6 additions & 5 deletions source/common/router/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "envoy/http/codec.h"
#include "envoy/http/codes.h"
#include "envoy/http/filter.h"
#include "envoy/local_info/local_info.h"
#include "envoy/router/shadow_writer.h"
#include "envoy/runtime/runtime.h"
#include "envoy/stats/stats_macros.h"
Expand Down Expand Up @@ -69,18 +70,18 @@ class FilterUtility {
*/
class FilterConfig {
public:
FilterConfig(const std::string& stat_prefix, const std::string& service_zone, Stats::Store& stats,
Upstream::ClusterManager& cm, Runtime::Loader& runtime,
FilterConfig(const std::string& stat_prefix, const LocalInfo::LocalInfo& local_info,
Stats::Store& stats, Upstream::ClusterManager& cm, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, ShadowWriterPtr&& shadow_writer,
bool emit_dynamic_stats)
: stats_store_(stats), service_zone_(service_zone), cm_(cm), runtime_(runtime),
random_(random), stats_{ALL_ROUTER_STATS(POOL_COUNTER_PREFIX(stats, stat_prefix))},
: stats_store_(stats), local_info_(local_info), cm_(cm), runtime_(runtime), random_(random),
stats_{ALL_ROUTER_STATS(POOL_COUNTER_PREFIX(stats, stat_prefix))},
emit_dynamic_stats_(emit_dynamic_stats), shadow_writer_(std::move(shadow_writer)) {}

ShadowWriter& shadowWriter() { return *shadow_writer_; }

Stats::Store& stats_store_;
const std::string service_zone_;
const LocalInfo::LocalInfo& local_info_;
Upstream::ClusterManager& cm_;
Runtime::Loader& runtime_;
Runtime::RandomGenerator& random_;
Expand Down
6 changes: 3 additions & 3 deletions source/common/stats/statsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ void UdpStatsdSink::onTimespanComplete(const std::string& name, std::chrono::mil
writer().writeTimer(name, ms);
}

TcpStatsdSink::TcpStatsdSink(const std::string& stat_cluster, const std::string& stat_host,
TcpStatsdSink::TcpStatsdSink(const LocalInfo::LocalInfo& local_info,
const std::string& cluster_name, ThreadLocal::Instance& tls,
Upstream::ClusterManager& cluster_manager)
: stat_cluster_(stat_cluster), stat_host_(stat_host), cluster_name_(cluster_name), tls_(tls),
: local_info_(local_info), cluster_name_(cluster_name), tls_(tls),
tls_slot_(tls.allocateSlot()), cluster_manager_(cluster_manager) {

if (!cluster_manager.get(cluster_name)) {
throw EnvoyException(fmt::format("unknown TCP statsd upstream cluster: {}", cluster_name));
}

if (stat_cluster.empty() || stat_host.empty()) {
if (local_info_.clusterName().empty() || local_info_.nodeName().empty()) {
throw EnvoyException(
fmt::format("TCP statsd requires setting --service-cluster and --service-node"));
}
Expand Down
9 changes: 4 additions & 5 deletions source/common/stats/statsd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "envoy/local_info/local_info.h"
#include "envoy/network/connection.h"
#include "envoy/stats/stats.h"
#include "envoy/thread_local/thread_local.h"
Expand Down Expand Up @@ -56,9 +57,8 @@ class UdpStatsdSink : public Sink {
*/
class TcpStatsdSink : public Sink {
public:
TcpStatsdSink(const std::string& stat_cluster, const std::string& stat_host,
const std::string& cluster_name, ThreadLocal::Instance& tls,
Upstream::ClusterManager& cluster_manager);
TcpStatsdSink(const LocalInfo::LocalInfo& local_info, const std::string& cluster_name,
ThreadLocal::Instance& tls, Upstream::ClusterManager& cluster_manager);

// Stats::Sink
void flushCounter(const std::string& name, uint64_t delta) override {
Expand Down Expand Up @@ -100,8 +100,7 @@ class TcpStatsdSink : public Sink {
bool shutdown_{};
};

std::string stat_cluster_;
std::string stat_host_;
const LocalInfo::LocalInfo& local_info_;
std::string cluster_name_;
ThreadLocal::Instance& tls_;
uint32_t tls_slot_;
Expand Down
6 changes: 3 additions & 3 deletions source/common/tracing/http_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ LightStepSink::TlsLightStepTracer::TlsLightStepTracer(lightstep::Tracer tracer,
: tracer_(tracer), sink_(sink) {}

LightStepSink::LightStepSink(const Json::Object& config, Upstream::ClusterManager& cluster_manager,
Stats::Store& stats, const std::string& service_node,
Stats::Store& stats, const LocalInfo::LocalInfo& local_info,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
std::unique_ptr<lightstep::TracerOptions> options)
: collector_cluster_(config.getString("collector_cluster")), cm_(cluster_manager),
stats_store_(stats),
tracer_stats_{LIGHTSTEP_TRACER_STATS(POOL_COUNTER_PREFIX(stats, "tracing.lightstep."))},
service_node_(service_node), tls_(tls), runtime_(runtime), options_(std::move(options)),
local_info_(local_info), tls_(tls), runtime_(runtime), options_(std::move(options)),
tls_slot_(tls.allocateSlot()) {
if (!cm_.get(collector_cluster_)) {
throw EnvoyException(fmt::format("{} collector cluster is not defined on cluster manager level",
Expand Down Expand Up @@ -257,7 +257,7 @@ void LightStepSink::flushTrace(const Http::HeaderMap& request_headers, const Htt
lightstep::SetTag("downstream cluster",
valueOrDefault(request_headers.EnvoyDownstreamServiceCluster(), "-")),
lightstep::SetTag("user agent", valueOrDefault(request_headers.UserAgent(), "-")),
lightstep::SetTag("node id", service_node_)});
lightstep::SetTag("node id", local_info_.nodeName())});

if (request_info.responseCode().valid() &&
Http::CodeUtility::is5xx(request_info.responseCode().value())) {
Expand Down
8 changes: 5 additions & 3 deletions source/common/tracing/http_tracer_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "envoy/local_info/local_info.h"
#include "envoy/runtime/runtime.h"
#include "envoy/thread_local/thread_local.h"
#include "envoy/tracing/http_tracer.h"
Expand Down Expand Up @@ -101,8 +102,9 @@ class HttpTracerImpl : public HttpTracer {
class LightStepSink : public HttpSink {
public:
LightStepSink(const Json::Object& config, Upstream::ClusterManager& cluster_manager,
Stats::Store& stats, const std::string& service_node, ThreadLocal::Instance& tls,
Runtime::Loader& runtime, std::unique_ptr<lightstep::TracerOptions> options);
Stats::Store& stats, const LocalInfo::LocalInfo& local_info,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
std::unique_ptr<lightstep::TracerOptions> options);

// Tracer::HttpSink
void flushTrace(const Http::HeaderMap& request_headers, const Http::HeaderMap& response_headers,
Expand Down Expand Up @@ -133,7 +135,7 @@ class LightStepSink : public HttpSink {
Upstream::ClusterManager& cm_;
Stats::Store& stats_store_;
LightstepTracerStats tracer_stats_;
const std::string service_node_;
const LocalInfo::LocalInfo& local_info_;
ThreadLocal::Instance& tls_;
Runtime::Loader& runtime_;
std::unique_ptr<lightstep::TracerOptions> options_;
Expand Down
Loading