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

Fix random sample fraction percent #8205

Merged
merged 2 commits into from
Sep 11, 2019
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Is this TODO still relevant? I miss context here. @mattklein123 @objectiser ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is still relevant, as random_sampling still waits to be migrated to fractional_percent.

// 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