Open nulltrope opened 1 year ago
Seems that the imlementation is different with the docs' description. You can try to specify a fractional percent directly with a proto struct. Or the integer value will be treat as percent value with a denominator 100.
bool SnapshotImpl::featureEnabled(absl::string_view key,
const envoy::type::v3::FractionalPercent& default_value,
uint64_t random_value) const {
const auto& entry = key.empty() ? values_.end() : values_.find(key);
envoy::type::v3::FractionalPercent percent;
if (entry != values_.end() && entry->second.fractional_percent_value_.has_value()) {
percent = entry->second.fractional_percent_value_.value();
} else if (entry != values_.end() && entry->second.uint_value_.has_value()) {
// Check for > 100 because the runtime value is assumed to be specified as
// an integer, and it also ensures that truncating the uint64_t runtime
// value into a uint32_t percent numerator later is safe
if (entry->second.uint_value_.value() > 100) {
return true;
}
// The runtime value was specified as an integer rather than a fractional
// percent proto. To preserve legacy semantics, we treat it as a percentage
// (i.e. denominator of 100).
percent.set_numerator(entry->second.uint_value_.value());
percent.set_denominator(envoy::type::v3::FractionalPercent::HUNDRED);
} else {
percent = default_value;
}
// When numerator > denominator condition is always evaluates to TRUE
// It becomes hard to debug why configuration does not work in case of wrong numerator.
// Log debug message that numerator is invalid.
uint64_t denominator_value =
ProtobufPercentHelper::fractionalPercentDenominatorToInt(percent.denominator());
if (percent.numerator() > denominator_value) {
ENVOY_LOG(debug,
"WARNING runtime key '{}': numerator ({}) > denominator ({}), condition always "
"evaluates to true",
key, percent.numerator(), denominator_value);
}
return ProtobufPercentHelper::evaluateFractionalPercent(percent, random_value);
}
Should we fix the implementation or just update the doc? @phlax (Seems update doc)
Should we fix the implementation or just update the doc? @phlax (Seems update doc)
apologies i missed this previously - i would say update the docs - as the current implementation is what anyone using it will expect - even if docs are wrong
happy to review prs - i only half follow the actual issue
I forgot this pr completely. 🤣 Okay I will creat a simple patch.
it seems a simple doc update, i can try this. cc @wbpcode 🤣
Title: Documentation: runtime tracing.random_sampling inaccurate
Description: The Runtime documentation for
tracing.random_sampling
states that the value should be between 0-10000, however in my testing it seems that in reality, any value >= 100 will result in all requests emitting traces. Note: I have only been able to test with the Datadog trace provider, as that is what I have setup to use, so I can't confirm whether this is isolated to the Datadog provider or not.Repro steps:
tracing.random_sampling
to any value over 100, e.g. 1000Config: (Only including the relevant config snippets)
And an example HTTP connection manager config: