Skip to content

Commit 9b1046f

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

File tree

16 files changed

+82
-89
lines changed

16 files changed

+82
-89
lines changed

DEPRECATED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ A logged warning is expected for each deprecated item that is in deprecation win
2323
is deprecated. Please use the new `upgrade_configs` in the
2424
[HttpConnectionManager](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.proto)
2525
instead.
26-
* Setting hosts via `hosts` field in `Cluster` is deprecated. Use `load_assignment` instead.
2726
* Use of the integer `percent` field in [FaultDelay](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/fault/v2/fault.proto)
2827
and in [FaultAbort](https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/http/fault/v2/fault.proto) is deprecated in favor
2928
of the new `FractionalPercent` based `percentage` field.
29+
* Setting hosts via `hosts` field in `Cluster` is deprecated. Use `load_assignment` instead.
3030

3131
## Version 1.7.0
3232

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 sampleFeatureEnabled(const std::string& key, uint64_t default_value,
116-
uint64_t num_buckets) const PURE;
115+
virtual bool featureEnabledEx(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 sampleFeatureEnabled(const std::string& key, uint64_t default_value,
133-
uint64_t random_value, uint64_t num_buckets) const PURE;
132+
virtual bool featureEnabledEx(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().sampleFeatureEnabled(
121+
return runtime_.snapshot().featureEnabledEx(
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().sampleFeatureEnabled("tracing.random_sampling",
208-
config.tracingConfig()->random_sampling_,
209-
result, 10000)) {
207+
} else if (runtime.snapshot().featureEnabledEx("tracing.random_sampling",
208+
config.tracingConfig()->random_sampling_, result,
209+
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().sampleFeatureEnabled(policy.runtimeKey(), 0, stable_random, 10000UL)) {
53+
!runtime.snapshot().featureEnabledEx(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::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);
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);
152152
}
153153

154-
bool SnapshotImpl::sampleFeatureEnabled(const std::string& key, uint64_t default_value,
155-
uint64_t random_value, uint64_t num_buckets) const {
154+
bool SnapshotImpl::featureEnabledEx(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 sampleFeatureEnabled(key, default_value, random_value, 100);
173+
return featureEnabledEx(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 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;
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;
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().sampleFeatureEnabled(
134+
bool enabled = config_->runtime().snapshot().featureEnabledEx(
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().sampleFeatureEnabled(
138+
enabled |= config_->runtime().snapshot().featureEnabledEx(
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().sampleFeatureEnabled(
147+
bool enabled = config_->runtime().snapshot().featureEnabledEx(
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().sampleFeatureEnabled(
151+
enabled |= config_->runtime().snapshot().featureEnabledEx(
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().sampleFeatureEnabled(
322+
if (!runtime_.snapshot().featureEnabledEx(
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_, sampleFeatureEnabled("access_log.test_key", 0, 42, 100))
207+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 0, 43, 100))
213+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 0, 55, 100))
220+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 0, 55, 100))
225+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 42, 10000))
248+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 43, 10000))
254+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 255, 10000))
261+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 255, 10000))
266+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 42, 1000000))
291+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_, sampleFeatureEnabled("access_log.test_key", 5, 43, 1000000))
297+
EXPECT_CALL(runtime_.snapshot_, featureEnabledEx("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_);

0 commit comments

Comments
 (0)