Skip to content

Commit aef3da0

Browse files
committed
Undo rename featureEnabledEx to sampleFeatureEnabled
Signed-off-by: Venil Noronha <[email protected]>
1 parent 9b1046f commit aef3da0

File tree

15 files changed

+88
-81
lines changed

15 files changed

+88
-81
lines changed

include/envoy/runtime/runtime.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class Snapshot {
112112
* of [0, num_buckets).
113113
* @return true if the feature is enabled.
114114
*/
115-
virtual bool featureEnabledEx(const std::string& key, uint64_t default_value,
116-
uint64_t num_buckets) const PURE;
115+
virtual bool sampleFeatureEnabled(const std::string& key, uint64_t default_value,
116+
uint64_t num_buckets) const PURE;
117117

118118
/**
119119
* Test if a feature is enabled using a supplied stable random value and total number of buckets
@@ -129,8 +129,8 @@ class Snapshot {
129129
* of [0, num_buckets).
130130
* @return true if the feature is enabled.
131131
*/
132-
virtual bool featureEnabledEx(const std::string& key, uint64_t default_value,
133-
uint64_t random_value, uint64_t num_buckets) const PURE;
132+
virtual bool sampleFeatureEnabled(const std::string& key, uint64_t default_value,
133+
uint64_t random_value, uint64_t num_buckets) const PURE;
134134

135135
/**
136136
* Fetch raw runtime data based on key.

source/common/access_log/access_log_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool RuntimeFilter::evaluate(const RequestInfo::RequestInfo&,
118118
random_value = random_.random();
119119
}
120120

121-
return runtime_.snapshot().featureEnabledEx(
121+
return runtime_.snapshot().sampleFeatureEnabled(
122122
runtime_key_, percent_.numerator(), random_value,
123123
ProtobufPercentHelper::fractionalPercentDenominatorToInt(percent_));
124124
}

source/common/http/conn_manager_utility.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ void ConnectionManagerUtility::mutateTracingRequestHeader(Http::HeaderMap& reque
204204
UuidUtils::setTraceableUuid(x_request_id, UuidTraceStatus::Client);
205205
} else if (request_headers.EnvoyForceTrace()) {
206206
UuidUtils::setTraceableUuid(x_request_id, UuidTraceStatus::Forced);
207-
} else if (runtime.snapshot().featureEnabledEx("tracing.random_sampling",
208-
config.tracingConfig()->random_sampling_, result,
209-
10000)) {
207+
} else if (runtime.snapshot().sampleFeatureEnabled("tracing.random_sampling",
208+
config.tracingConfig()->random_sampling_,
209+
result, 10000)) {
210210
UuidUtils::setTraceableUuid(x_request_id, UuidTraceStatus::Sampled);
211211
}
212212
}

source/common/router/router.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool FilterUtility::shouldShadow(const ShadowPolicy& policy, Runtime::Loader& ru
5050
}
5151

5252
if (!policy.runtimeKey().empty() &&
53-
!runtime.snapshot().featureEnabledEx(policy.runtimeKey(), 0, stable_random, 10000UL)) {
53+
!runtime.snapshot().sampleFeatureEnabled(policy.runtimeKey(), 0, stable_random, 10000UL)) {
5454
return false;
5555
}
5656

source/common/runtime/runtime_impl.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ std::string RandomGeneratorImpl::uuid() {
146146
return std::string(uuid, UUID_LENGTH);
147147
}
148148

149-
bool SnapshotImpl::featureEnabledEx(const std::string& key, uint64_t default_value,
150-
uint64_t num_buckets) const {
151-
return featureEnabledEx(key, default_value, generator_.random(), num_buckets);
149+
bool SnapshotImpl::sampleFeatureEnabled(const std::string& key, uint64_t default_value,
150+
uint64_t num_buckets) const {
151+
return sampleFeatureEnabled(key, default_value, generator_.random(), num_buckets);
152152
}
153153

154-
bool SnapshotImpl::featureEnabledEx(const std::string& key, uint64_t default_value,
155-
uint64_t random_value, uint64_t num_buckets) const {
154+
bool SnapshotImpl::sampleFeatureEnabled(const std::string& key, uint64_t default_value,
155+
uint64_t random_value, uint64_t num_buckets) const {
156156
return random_value % num_buckets < std::min(getInteger(key, default_value), num_buckets);
157157
}
158158

@@ -170,7 +170,7 @@ bool SnapshotImpl::featureEnabled(const std::string& key, uint64_t default_value
170170

171171
bool SnapshotImpl::featureEnabled(const std::string& key, uint64_t default_value,
172172
uint64_t random_value) const {
173-
return featureEnabledEx(key, default_value, random_value, 100);
173+
return sampleFeatureEnabled(key, default_value, random_value, 100);
174174
}
175175

176176
const std::string& SnapshotImpl::get(const std::string& key) const {

source/common/runtime/runtime_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class SnapshotImpl : public Snapshot, public ThreadLocal::ThreadLocalObject {
6464
std::vector<OverrideLayerConstPtr>&& layers);
6565

6666
// Runtime::Snapshot
67-
bool featureEnabledEx(const std::string& key, uint64_t default_value,
68-
uint64_t num_buckets) const override;
69-
bool featureEnabledEx(const std::string& key, uint64_t default_value, uint64_t random_value,
70-
uint64_t num_buckets) const override;
67+
bool sampleFeatureEnabled(const std::string& key, uint64_t default_value,
68+
uint64_t num_buckets) const override;
69+
bool sampleFeatureEnabled(const std::string& key, uint64_t default_value, uint64_t random_value,
70+
uint64_t num_buckets) const override;
7171
bool featureEnabled(const std::string& key, uint64_t default_value) const override;
7272
bool featureEnabled(const std::string& key, uint64_t default_value,
7373
uint64_t random_value) const override;

source/extensions/filters/http/fault/fault_filter.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ Http::FilterHeadersStatus FaultFilter::decodeHeaders(Http::HeaderMap& headers, b
131131
}
132132

133133
bool FaultFilter::isDelayEnabled() {
134-
bool enabled = config_->runtime().snapshot().featureEnabledEx(
134+
bool enabled = config_->runtime().snapshot().sampleFeatureEnabled(
135135
DELAY_PERCENT_KEY, fault_settings_->delayPercentage().numerator(),
136136
ProtobufPercentHelper::fractionalPercentDenominatorToInt(fault_settings_->delayPercentage()));
137137
if (!downstream_cluster_delay_percent_key_.empty()) {
138-
enabled |= config_->runtime().snapshot().featureEnabledEx(
138+
enabled |= config_->runtime().snapshot().sampleFeatureEnabled(
139139
downstream_cluster_delay_percent_key_, fault_settings_->delayPercentage().numerator(),
140140
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
141141
fault_settings_->delayPercentage()));
@@ -144,11 +144,11 @@ bool FaultFilter::isDelayEnabled() {
144144
}
145145

146146
bool FaultFilter::isAbortEnabled() {
147-
bool enabled = config_->runtime().snapshot().featureEnabledEx(
147+
bool enabled = config_->runtime().snapshot().sampleFeatureEnabled(
148148
ABORT_PERCENT_KEY, fault_settings_->abortPercentage().numerator(),
149149
ProtobufPercentHelper::fractionalPercentDenominatorToInt(fault_settings_->abortPercentage()));
150150
if (!downstream_cluster_abort_percent_key_.empty()) {
151-
enabled |= config_->runtime().snapshot().featureEnabledEx(
151+
enabled |= config_->runtime().snapshot().sampleFeatureEnabled(
152152
downstream_cluster_abort_percent_key_, fault_settings_->abortPercentage().numerator(),
153153
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
154154
fault_settings_->abortPercentage()));

source/extensions/filters/network/mongo_proxy/proxy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ absl::optional<uint64_t> ProxyFilter::delayDuration() {
319319
return result;
320320
}
321321

322-
if (!runtime_.snapshot().featureEnabledEx(
322+
if (!runtime_.snapshot().sampleFeatureEnabled(
323323
MongoRuntimeConfig::get().FixedDelayPercent, fault_config_->delayPercentage().numerator(),
324324
ProtobufPercentHelper::fractionalPercentDenominatorToInt(
325325
fault_config_->delayPercentage()))) {

test/common/access_log/access_log_impl_test.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,25 @@ TEST_F(AccessLogImplTest, RuntimeFilter) {
204204

205205
// Value is taken from random generator.
206206
EXPECT_CALL(context_.random_, random()).WillOnce(Return(42));
207-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 0, 42, 100))
207+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 0, 42, 100))
208208
.WillOnce(Return(true));
209209
EXPECT_CALL(*file_, write(_));
210210
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
211211

212212
EXPECT_CALL(context_.random_, random()).WillOnce(Return(43));
213-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 0, 43, 100))
213+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 0, 43, 100))
214214
.WillOnce(Return(false));
215215
EXPECT_CALL(*file_, write(_)).Times(0);
216216
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
217217

218218
// Value is taken from x-request-id.
219219
request_headers_.addCopy("x-request-id", "000000ff-0000-0000-0000-000000000000");
220-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 0, 55, 100))
220+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 0, 55, 100))
221221
.WillOnce(Return(true));
222222
EXPECT_CALL(*file_, write(_));
223223
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
224224

225-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 0, 55, 100))
225+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 0, 55, 100))
226226
.WillOnce(Return(false));
227227
EXPECT_CALL(*file_, write(_)).Times(0);
228228
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
@@ -245,25 +245,25 @@ name: envoy.file_access_log
245245

246246
// Value is taken from random generator.
247247
EXPECT_CALL(context_.random_, random()).WillOnce(Return(42));
248-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 42, 10000))
248+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 42, 10000))
249249
.WillOnce(Return(true));
250250
EXPECT_CALL(*file_, write(_));
251251
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
252252

253253
EXPECT_CALL(context_.random_, random()).WillOnce(Return(43));
254-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 43, 10000))
254+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 43, 10000))
255255
.WillOnce(Return(false));
256256
EXPECT_CALL(*file_, write(_)).Times(0);
257257
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
258258

259259
// Value is taken from x-request-id.
260260
request_headers_.addCopy("x-request-id", "000000ff-0000-0000-0000-000000000000");
261-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 255, 10000))
261+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 255, 10000))
262262
.WillOnce(Return(true));
263263
EXPECT_CALL(*file_, write(_));
264264
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
265265

266-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 255, 10000))
266+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 255, 10000))
267267
.WillOnce(Return(false));
268268
EXPECT_CALL(*file_, write(_)).Times(0);
269269
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
@@ -288,13 +288,13 @@ name: envoy.file_access_log
288288
// Value should not be taken from x-request-id.
289289
request_headers_.addCopy("x-request-id", "000000ff-0000-0000-0000-000000000000");
290290
EXPECT_CALL(context_.random_, random()).WillOnce(Return(42));
291-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 42, 1000000))
291+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 42, 1000000))
292292
.WillOnce(Return(true));
293293
EXPECT_CALL(*file_, write(_));
294294
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);
295295

296296
EXPECT_CALL(context_.random_, random()).WillOnce(Return(43));
297-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("access_log.test_key", 5, 43, 1000000))
297+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("access_log.test_key", 5, 43, 1000000))
298298
.WillOnce(Return(false));
299299
EXPECT_CALL(*file_, write(_)).Times(0);
300300
log->log(&request_headers_, &response_headers_, &response_trailers_, request_info_);

test/common/http/conn_manager_utility_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ TEST_F(ConnectionManagerUtilityTest, NonTlsAlwaysForwardClientCert) {
891891

892892
// Sampling, global on.
893893
TEST_F(ConnectionManagerUtilityTest, RandomSamplingWhenGlobalSet) {
894-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("tracing.random_sampling", 10000, _, 10000))
894+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("tracing.random_sampling", 10000, _, 10000))
895895
.WillOnce(Return(true));
896896
EXPECT_CALL(runtime_.snapshot_, featureEnabled("tracing.global_enabled", 100, _))
897897
.WillOnce(Return(true));
@@ -905,7 +905,7 @@ TEST_F(ConnectionManagerUtilityTest, RandomSamplingWhenGlobalSet) {
905905

906906
// Sampling must not be done on client traced.
907907
TEST_F(ConnectionManagerUtilityTest, SamplingMustNotBeDoneOnClientTraced) {
908-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("tracing.random_sampling", 10000, _, 10000))
908+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("tracing.random_sampling", 10000, _, 10000))
909909
.Times(0);
910910
EXPECT_CALL(runtime_.snapshot_, featureEnabled("tracing.global_enabled", 100, _))
911911
.WillOnce(Return(true));
@@ -920,7 +920,7 @@ TEST_F(ConnectionManagerUtilityTest, SamplingMustNotBeDoneOnClientTraced) {
920920

921921
// Sampling, global off.
922922
TEST_F(ConnectionManagerUtilityTest, NoTraceWhenSamplingSetButGlobalNotSet) {
923-
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("tracing.random_sampling", 10000, _, 10000))
923+
EXPECT_CALL(runtime_.snapshot_, sampleFeatureEnabled("tracing.random_sampling", 10000, _, 10000))
924924
.WillOnce(Return(true));
925925
EXPECT_CALL(runtime_.snapshot_, featureEnabled("tracing.global_enabled", 100, _))
926926
.WillOnce(Return(false));

0 commit comments

Comments
 (0)