Skip to content

Commit

Permalink
tracing: fix random sample fraction percent (envoyproxy#8205)
Browse files Browse the repository at this point in the history
Signed-off-by: Pengyuan Bian <bianpengyuan@google.com>
  • Loading branch information
bianpengyuan committed Sep 11, 2019
1 parent 5e09e25 commit 802799a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
envoy::type::FractionalPercent random_sampling;
// TODO: Random sampling historically was an integer and default to out of 10,000. We should
// deprecate that and move to a straight fractional percent config.
random_sampling.set_numerator(
tracing_config.has_random_sampling() ? tracing_config.random_sampling().value() : 10000);
uint64_t random_sampling_numerator{PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(
tracing_config, random_sampling, 10000, 10000)};
random_sampling.set_numerator(random_sampling_numerator);
random_sampling.set_denominator(envoy::type::FractionalPercent::TEN_THOUSAND);
envoy::type::FractionalPercent overall_sampling;
overall_sampling.set_numerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,48 @@ TEST_F(HttpConnectionManagerConfigTest, SamplingConfigured) {
EXPECT_EQ(1, config.tracingConfig()->client_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::HUNDRED,
config.tracingConfig()->client_sampling_.denominator());
EXPECT_EQ(2, config.tracingConfig()->random_sampling_.numerator());
EXPECT_EQ(200, config.tracingConfig()->random_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::TEN_THOUSAND,
config.tracingConfig()->random_sampling_.denominator());
EXPECT_EQ(3, config.tracingConfig()->overall_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::HUNDRED,
config.tracingConfig()->overall_sampling_.denominator());
}

TEST_F(HttpConnectionManagerConfigTest, FractionalSamplingConfigured) {
const std::string yaml_string = R"EOF(
stat_prefix: ingress_http
internal_address_config:
unix_sockets: true
route_config:
name: local_route
tracing:
operation_name: ingress
client_sampling:
value: 0.1
random_sampling:
value: 0.2
overall_sampling:
value: 0.3
http_filters:
- name: envoy.router
)EOF";

HttpConnectionManagerConfig config(parseHttpConnectionManagerFromV2Yaml(yaml_string), context_,
date_provider_, route_config_provider_manager_,
scoped_routes_config_provider_manager_);

EXPECT_EQ(0, config.tracingConfig()->client_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::HUNDRED,
config.tracingConfig()->client_sampling_.denominator());
EXPECT_EQ(20, config.tracingConfig()->random_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::TEN_THOUSAND,
config.tracingConfig()->random_sampling_.denominator());
EXPECT_EQ(0, config.tracingConfig()->overall_sampling_.numerator());
EXPECT_EQ(envoy::type::FractionalPercent::HUNDRED,
config.tracingConfig()->overall_sampling_.denominator());
}

TEST_F(HttpConnectionManagerConfigTest, UnixSocketInternalAddress) {
const std::string yaml_string = R"EOF(
stat_prefix: ingress_http
Expand Down

0 comments on commit 802799a

Please sign in to comment.