Skip to content

Commit

Permalink
limit calculated sampling exponent (#37240)
Browse files Browse the repository at this point in the history
Ensure that calculated sampling exponent stays below a certain limit
Risk Level: Low
Testing: Unit test, manual
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: 
Fixes #37199

Signed-off-by: thomas.ebner <[email protected]>
  • Loading branch information
samohte authored Nov 20, 2024
1 parent 15e6a55 commit 005eb77
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ bug_fixes:
Reverted :ref:`custom header
<envoy_v3_api_msg_extensions.http.original_ip_detection.custom_header.v3.CustomHeaderConfig>` extension to its
original behavior by disabling automatic XFF header appending that was inadvertently introduced in PR #31831.
- area: tracers
change: |
Avoid possible overflow when setting span attributes in Dynatrace sampler.
removed_config_or_runtime:
# *Normally occurs at the end of the* :ref:`deprecation period <deprecated>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SamplingState SamplingController::getSamplingState(const std::string& sampling_k
}
absl::ReaderMutexLock ss_lock{&stream_summary_mutex_};
const uint32_t exp = stream_summary_->getN() / divisor;
return SamplingState{exp};
return SamplingState{std::min(exp, MAX_SAMPLING_EXPONENT)};
}

std::string SamplingController::getSamplingKey(const absl::string_view path_query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ TEST(SamplingControllerTest, TestWarmup) {
EXPECT_EQ(sc.getSamplingState("GET_1").getExponent(), 8);
EXPECT_EQ(sc.getSamplingState("GET_6").getExponent(), 8);
EXPECT_EQ(sc.getSamplingState("GET_789").getExponent(), 8);

offerEntry(sc, "GET_7", 10000);
EXPECT_EQ(sc.getSamplingState("GET_1").getExponent(), SamplingController::MAX_SAMPLING_EXPONENT);
EXPECT_EQ(sc.getSamplingState("GET_6").getExponent(), SamplingController::MAX_SAMPLING_EXPONENT);
EXPECT_EQ(sc.getSamplingState("GET_789").getExponent(),
SamplingController::MAX_SAMPLING_EXPONENT);
EXPECT_EQ(sc.getSamplingState("GET_7").getExponent(), SamplingController::MAX_SAMPLING_EXPONENT);
}

// Test getting sampling state from an empty SamplingController
Expand Down

0 comments on commit 005eb77

Please sign in to comment.