Skip to content
Draft
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
32 changes: 32 additions & 0 deletions envoy/stats/stats_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,38 @@ static inline std::string statPrefixJoin(absl::string_view prefix, absl::string_
#define POOL_HISTOGRAM(POOL) POOL_HISTOGRAM_PREFIX(POOL, "")
#define POOL_TEXT_READOUT(POOL) POOL_TEXT_READOUT_PREFIX(POOL, "")

// Tagged variants of the POOL_*_PREFIX macros: create each stat directly on POOL with pre-encoded
// tags. BASE_PREFIX and PREFIX are Stats::StatNames (the tag-extracted and flat prefixes,
// pre-encoded once by the caller) and TAGS is a Stats::StatNameTagSpan. Callers must include
// "source/common/stats/utility.h". See Stats::Utility::counterFromTaggedPrefix.
#define POOL_COUNTER_TAGGED_PREFIX(POOL, BASE_PREFIX, TAGS, PREFIX) \
Envoy::Stats::Utility::counterFromTaggedPrefix((POOL), (BASE_PREFIX), (TAGS), (PREFIX), \
(FINISH_STAT_DECL_
#define POOL_GAUGE_TAGGED_PREFIX(POOL, BASE_PREFIX, TAGS, PREFIX) \
Envoy::Stats::Utility::gaugeFromTaggedPrefix((POOL), (BASE_PREFIX), (TAGS), (PREFIX), \
(FINISH_STAT_DECL_MODE_
#define POOL_HISTOGRAM_TAGGED_PREFIX(POOL, BASE_PREFIX, TAGS, PREFIX) \
Envoy::Stats::Utility::histogramFromTaggedPrefix((POOL), (BASE_PREFIX), (TAGS), (PREFIX), \
(FINISH_STAT_DECL_UNIT_
#define POOL_TEXT_READOUT_TAGGED_PREFIX(POOL, BASE_PREFIX, TAGS, PREFIX) \
Envoy::Stats::Utility::textReadoutFromTaggedPrefix((POOL), (BASE_PREFIX), (TAGS), (PREFIX), \
(FINISH_STAT_DECL_

// Convenience wrappers taking a Stats::TaggedStatName (see utility.h), which pre-encodes the
// tag-extracted prefix, the flat prefix and the tags.
#define POOL_COUNTER_TAGGED(POOL, TAGGED_NAME) \
POOL_COUNTER_TAGGED_PREFIX(POOL, (TAGGED_NAME).baseName(), (TAGGED_NAME).nameTags(), \
(TAGGED_NAME).name())
#define POOL_GAUGE_TAGGED(POOL, TAGGED_NAME) \
POOL_GAUGE_TAGGED_PREFIX(POOL, (TAGGED_NAME).baseName(), (TAGGED_NAME).nameTags(), \
(TAGGED_NAME).name())
#define POOL_HISTOGRAM_TAGGED(POOL, TAGGED_NAME) \
POOL_HISTOGRAM_TAGGED_PREFIX(POOL, (TAGGED_NAME).baseName(), (TAGGED_NAME).nameTags(), \
(TAGGED_NAME).name())
#define POOL_TEXT_READOUT_TAGGED(POOL, TAGGED_NAME) \
POOL_TEXT_READOUT_TAGGED_PREFIX(POOL, (TAGGED_NAME).baseName(), (TAGGED_NAME).nameTags(), \
(TAGGED_NAME).name())

#define NULL_STAT_DECL_(X) std::string(#X)),
#define NULL_STAT_DECL_IGNORE_MODE_(X, MODE) std::string(#X)),

Expand Down
2 changes: 2 additions & 0 deletions source/common/rds/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ envoy_cc_library(
"//source/common/config:resource_type_helper_lib",
"//source/common/config:subscription_factory_lib",
"//source/common/config:utility_lib",
"//source/common/config:well_known_names",
"//source/common/init:manager_lib",
"//source/common/init:target_lib",
"//source/common/init:watcher_lib",
"//source/common/protobuf:utility_lib",
"//source/common/stats:prefix_utility_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class RouteConfigProviderManagerImpl : public RouteConfigProviderManager<Rds, Ro
auto subscription = THROW_OR_RETURN_VALUE(
RdsRouteConfigSubscription::create(
std::move(config_update), std::move(resource_decoder), rds.config_source(),
rds.route_config_name(), manager_identifier, factory_context,
stat_prefix + absl::AsciiStrToLower(getRdsName()) + ".",
rds.route_config_name(), manager_identifier, factory_context, stat_prefix,
absl::AsciiStrToUpper(getRdsName()), manager_),
std::unique_ptr<RdsRouteConfigSubscription>);
auto provider = std::make_shared<RdsRouteConfigProviderImpl>(std::move(subscription),
Expand Down
43 changes: 42 additions & 1 deletion source/common/rds/rds_route_config_subscription.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
#include "source/common/rds/rds_route_config_subscription.h"

#include "source/common/common/logger.h"
#include "source/common/config/well_known_names.h"
#include "source/common/rds/util.h"
#include "source/common/stats/prefix_utility.h"

#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"

namespace Envoy {
namespace Rds {

namespace {

Stats::ScopeSharedPtr createStatsScope(Stats::Scope& scope, absl::string_view stat_prefix,
absl::string_view rds_type,
absl::string_view route_config_name) {

// If this is not for HTTP RDS (i.e. thrift/dubbo/generic), keep the previous
// behavior because there are no default tags for them.
// TODO(wbpcode): we should support all of them in the future.
if (!absl::StartsWith(stat_prefix, "http.") || !absl::EndsWith(stat_prefix, ".") ||
rds_type != "RDS") {
// Full flat name of the scope. For example:
// http.[CONN_MANAGER_PREFIX.]rds.(<route_config_name>.)
const std::string tagged_name =
absl::StrCat(stat_prefix, absl::AsciiStrToLower(rds_type), ".", route_config_name, ".");
return scope.createScopeWithTaggedName(tagged_name, {}, {});
}

const std::string lower_rds_type_and_dot = absl::AsciiStrToLower(rds_type) + ".";

// Merge the stat prefix from the connection manager with the RDS route.
const auto merged_prefix = Stats::mergeStatPrefix(
scope.symbolTable(),
/*prefix=*/stat_prefix,
/*base_name=*/lower_rds_type_and_dot,
/*tags=*/
{Stats::TagStringView{Envoy::Config::TagNames::get().RDS_ROUTE_CONFIG, route_config_name}},
/*name=*/absl::StrCat(lower_rds_type_and_dot, route_config_name, "."));

// http.[<stat_prefix>.]rds.(<route_config_name>.)<base_stat>
return scope.scopeFromTaggedName(merged_prefix.baseName(), merged_prefix.nameTags(),
merged_prefix.name());
}

} // namespace

absl::StatusOr<std::unique_ptr<RdsRouteConfigSubscription>> RdsRouteConfigSubscription::create(
RouteConfigUpdatePtr&& config_update,
Envoy::Config::OpaqueResourceDecoderSharedPtr&& resource_decoder,
Expand All @@ -31,7 +72,7 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(
const std::string& rds_type, RouteConfigProviderManager& route_config_provider_manager,
absl::Status& creation_status)
: route_config_name_(route_config_name),
scope_(factory_context.scope().createScope(stat_prefix + route_config_name_ + ".")),
scope_(createStatsScope(factory_context.scope(), stat_prefix, rds_type, route_config_name_)),
factory_context_(factory_context),
parent_init_target_(
fmt::format("RdsRouteConfigSubscription {} init {}", rds_type, route_config_name_),
Expand Down
2 changes: 2 additions & 0 deletions source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,12 @@ envoy_cc_library(
"//source/common/config:config_provider_lib",
"//source/common/config:resource_name_lib",
"//source/common/config:resource_type_helper_lib",
"//source/common/config:well_known_names",
"//source/common/config:xds_resource_lib",
"//source/common/init:manager_lib",
"//source/common/init:watcher_lib",
"//source/common/protobuf:utility_lib",
"//source/common/stats:prefix_utility_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
Expand Down
6 changes: 3 additions & 3 deletions source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(
absl::Status& creation_status)
: Rds::RdsRouteConfigSubscription(std::move(config_update), std::move(resource_decoder),
rds.config_source(), rds.route_config_name(),
manager_identifier, factory_context, stat_prefix + "rds.",
"RDS", route_config_provider_manager, creation_status),
manager_identifier, factory_context, stat_prefix, "RDS",
route_config_provider_manager, creation_status),
config_update_info_(static_cast<RouteConfigUpdateReceiver*>(
Rds::RdsRouteConfigSubscription::config_update_info_.get())) {}

Expand All @@ -65,7 +65,7 @@ absl::Status RdsRouteConfigSubscription::beforeProviderUpdate(
maybeCreateInitManager(routeConfigUpdate()->configInfo().value().version_, noop_init_manager,
resume_rds);
auto subscription_or_error = VhdsSubscription::createVhdsSubscription(
config_update_info_, factory_context_, stat_prefix_, route_config_provider_);
config_update_info_, factory_context_, stat_prefix_, route_config_provider_, true);
RETURN_IF_NOT_OK_REF(subscription_or_error.status());
vhds_subscription_ = std::move(subscription_or_error.value());
vhds_subscription_->registerInitTargetWithInitManager(
Expand Down
40 changes: 38 additions & 2 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
#include "source/common/common/utility.h"
#include "source/common/config/api_version.h"
#include "source/common/config/resource_name.h"
#include "source/common/config/well_known_names.h"
#include "source/common/config/xds_resource.h"
#include "source/common/init/manager_impl.h"
#include "source/common/init/watcher_impl.h"
#include "source/common/protobuf/utility.h"
#include "source/common/router/rds_impl.h"
#include "source/common/router/scoped_config_impl.h"
#include "source/common/stats/prefix_utility.h"

#include "absl/strings/str_join.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"

// Types are deeply nested under Envoy::Config::ConfigProvider; use 'using-directives' across all
// ConfigProvider related types for consistency.
Expand All @@ -34,6 +37,39 @@ using Envoy::Config::ScopedResume;

namespace Envoy {
namespace Router {

namespace {

// The scoped RDS stats scope is "http.<conn_manager_prefix>.scoped_rds.<name>.". `stat_prefix` is
// always of the form "http.<conn_manager_prefix>.", so recover the inner connection manager prefix
// and emit it
// (along with the scoped route config name) as a tag rather than baking it into the tag-extracted
// scope name.
Stats::ScopeSharedPtr createScopedRdsStatsScope(Stats::Scope& scope, absl::string_view stat_prefix,
absl::string_view name) {
// Defensively check that the stat_prefix is of the form "http.<conn_manager_prefix>."
if (!absl::StartsWith(stat_prefix, "http.") || !absl::EndsWith(stat_prefix, ".")) {
// Full flat name of the scope.
const std::string tagged_name = absl::StrCat(stat_prefix, "scoped_rds.", name, ".");
return scope.createScopeWithTaggedName(tagged_name, {}, {});
}

// Merge the stat prefix from the connection manager with the RDS route.
const auto merged_prefix = Stats::mergeStatPrefix(
scope.symbolTable(),
/*prefix=*/stat_prefix,
/*base_name=*/"scoped_rds.",
/*tags=*/
{Stats::TagStringView{Envoy::Config::TagNames::get().SCOPED_RDS_CONFIG, name}},
/*name=*/absl::StrCat("scoped_rds.", name, "."));

// http.[<stat_prefix>.]scoped_rds.(<scoped_route_config_name>.)<base_stat>
return scope.scopeFromTaggedName(merged_prefix.baseName(), merged_prefix.nameTags(),
merged_prefix.name());
}

} // namespace

namespace ScopedRoutesConfigProviderUtil {
ConfigProviderPtr create(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
Expand Down Expand Up @@ -139,7 +175,7 @@ ScopedRdsConfigSubscription::ScopedRdsConfigSubscription(
: DeltaConfigSubscriptionInstance("SRDS", manager_identifier, config_provider_manager,
factory_context),
factory_context_(factory_context), name_(name),
scope_(factory_context.scope().createScope(stat_prefix + "scoped_rds." + name + ".")),
scope_(createScopedRdsStatsScope(factory_context.scope(), stat_prefix, name)),
stats_({ALL_SCOPED_RDS_STATS(POOL_COUNTER(*scope_), POOL_GAUGE(*scope_))}),
resource_type_helper_(factory_context.messageValidationContext().dynamicValidationVisitor(),
"name"),
Expand Down
30 changes: 25 additions & 5 deletions source/common/router/vhds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#include "source/common/grpc/common.h"
#include "source/common/protobuf/utility.h"
#include "source/common/router/config_impl.h"
#include "source/common/stats/prefix_utility.h"

namespace Envoy {
namespace Router {

absl::StatusOr<VhdsSubscriptionPtr> VhdsSubscription::createVhdsSubscription(
RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
Rds::RouteConfigProvider* route_config_provider) {
Rds::RouteConfigProvider* route_config_provider, bool rds) {
const auto& vhds_config_source =
config_update_info->protobufConfigurationCast().vhds().config_source();
// VHDS only supports Delta xDS. This can be specified either explicitly via DELTA_GRPC
Expand Down Expand Up @@ -55,20 +56,39 @@ absl::StatusOr<VhdsSubscriptionPtr> VhdsSubscription::createVhdsSubscription(

auto status = absl::OkStatus();
auto ret = std::unique_ptr<VhdsSubscription>(new VhdsSubscription(
config_update_info, factory_context, stat_prefix, route_config_provider, status));
config_update_info, factory_context, stat_prefix, route_config_provider, rds, status));
RETURN_IF_ERROR(status);
return ret;
}

Stats::ScopeSharedPtr createStatsScope(Stats::Scope& scope, absl::string_view stat_prefix,
absl::string_view vhds_prefix, absl::string_view name) {
// Defensively check that the stat_prefix is of the form "http.<conn_manager_prefix>."
if (!absl::StartsWith(stat_prefix, "http.") || !absl::EndsWith(stat_prefix, ".")) {
// Full flat name of the scope.
const std::string tagged_name = absl::StrCat(stat_prefix, vhds_prefix, name, ".");
return scope.createScopeWithTaggedName(tagged_name, {}, {});
}

// Merge the stat prefix from the connection manager with the RDS route.
// TODO(wbpcode): there is no default tag for VHDS here so we concatenate the vhds_prefix with the
// name as the single base name without tags.
const auto merged_prefix = Stats::mergeStatPrefix(scope.symbolTable(), stat_prefix,
absl::StrCat(vhds_prefix, name, "."));
// http.[<stat_prefix>.]rds.vhds.(<vhds_config_name>.)<base_stat>
return scope.scopeFromTaggedName(merged_prefix.baseName(), merged_prefix.nameTags(),
merged_prefix.name());
}

// Implements callbacks to handle DeltaDiscovery protocol for VirtualHostDiscoveryService
VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix,
Rds::RouteConfigProvider* route_config_provider,
Rds::RouteConfigProvider* route_config_provider, bool rds,
absl::Status& status)
: config_update_info_(config_update_info),
scope_(factory_context.scope().createScope(
stat_prefix + "vhds." + config_update_info_->protobufConfigurationCast().name() + ".")),
scope_(createStatsScope(factory_context.scope(), stat_prefix, rds ? "rds.vhds." : "vhds.",
config_update_info_->protobufConfigurationCast().name())),
stats_({ALL_VHDS_STATS(POOL_COUNTER(*scope_))}),
init_target_(fmt::format("VhdsConfigSubscription {}",
config_update_info_->protobufConfigurationCast().name()),
Expand Down
4 changes: 2 additions & 2 deletions source/common/router/vhds.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class VhdsSubscription : public Envoy::Config::SubscriptionCallbacks,
createVhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix,
Rds::RouteConfigProvider* route_config_provider);
Rds::RouteConfigProvider* route_config_provider, bool rds = false);

~VhdsSubscription() override { init_target_.ready(); }

Expand All @@ -62,7 +62,7 @@ class VhdsSubscription : public Envoy::Config::SubscriptionCallbacks,
VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix, Rds::RouteConfigProvider* route_config_provider,
absl::Status& creation_status);
bool rds, absl::Status& creation_status);

// Config::SubscriptionCallbacks
absl::Status onConfigUpdate(const std::vector<Envoy::Config::DecodedResourceRef>&,
Expand Down
13 changes: 13 additions & 0 deletions source/common/stats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,16 @@ envoy_cc_library(
"//envoy/stats:stats_interface",
],
)

envoy_cc_library(
name = "prefix_utility_lib",
srcs = ["prefix_utility.cc"],
hdrs = ["prefix_utility.h"],
deps = [
":utility_lib",
"//envoy/stats:stats_interface",
"//envoy/stats:tag_interface",
"//source/common/common:assert_lib",
"//source/common/config:well_known_names",
],
)
Loading
Loading