Skip to content

Commit add2482

Browse files
committed
Removed the processor file and added comments to test file
1 parent cc58677 commit add2482

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_quickpulse/_processor.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_rate_limited_sampling.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def advance_time(self, nanoseconds_increment: int):
6363
def get_current_time_nanoseconds(self) -> int:
6464
return self.current_time
6565

66+
# Test sampling behavior with a high target rate and moderate span frequency
6667
def test_constant_rate_sampling(self):
6768
target_rate = 1000.0
6869
sampler = RateLimitedSampler(target_rate)
@@ -95,6 +96,7 @@ def test_constant_rate_sampling(self):
9596

9697
self.assertGreater(sampled_count, 0, "Should sample some spans with high target rate")
9798

99+
# Test throttling behavior under high volume of spans with low target rate
98100
def test_high_volume_sampling(self):
99101
target_rate = 5.0
100102
sampler = RateLimitedSampler(target_rate)
@@ -127,6 +129,7 @@ def test_high_volume_sampling(self):
127129
self.assertGreater(sampled_count, 0, "Should sample at least some spans even under high load")
128130
self.assertLess(sampled_count, num_spans * 0.1, "Should throttle significantly under high load")
129131

132+
# Test adaptive sampling when span arrival rate increases over time
130133
def test_rate_adaptation_increasing_load(self):
131134
target_rate = 20.0
132135
sampler = RateLimitedSampler(target_rate)
@@ -171,6 +174,7 @@ def test_rate_adaptation_increasing_load(self):
171174
self.assertLess(phase2_percentage, phase1_percentage,
172175
"Sampling percentage should decrease under high load")
173176

177+
# Test sampler instantiation with various target rates and description format
174178
def test_sampler_creation(self):
175179
for target_rate in [0.1, 0.5, 1.0, 5.0, 100.0]:
176180
sampler = RateLimitedSampler(target_rate)
@@ -180,10 +184,12 @@ def test_sampler_creation(self):
180184
f"RateLimitedSampler{{{target_rate}}}"
181185
)
182186

187+
# Test that negative target rates raise a ValueError
183188
def test_negative_rate_raises_error(self):
184189
with self.assertRaises(ValueError):
185190
RateLimitedSampler(-1.0)
186191

192+
# Test sampling behavior with zero target rate
187193
def test_zero_rate_sampling(self):
188194
sampler = RateLimitedSampler(0.0)
189195

@@ -198,6 +204,7 @@ def test_zero_rate_sampling(self):
198204
self.assertIn(result.decision, [Decision.RECORD_AND_SAMPLE, Decision.DROP])
199205
self.assertIn(_SAMPLE_RATE_KEY, result.attributes)
200206

207+
# Test that the same trace ID produces consistent sampling decisions
201208
def test_sampling_decision_consistency(self):
202209
sampler = RateLimitedSampler(50.0)
203210

@@ -217,6 +224,7 @@ def test_sampling_decision_consistency(self):
217224
self.assertEqual(result.decision, first_decision,
218225
"Sampling decision should be consistent for same trace ID")
219226

227+
# Test that sampling results include valid sample rate attributes
220228
def test_sampling_attributes(self):
221229
sampler = RateLimitedSampler(25.0)
222230

@@ -235,6 +243,7 @@ def test_sampling_attributes(self):
235243
self.assertGreaterEqual(float(sample_rate), 0.0)
236244
self.assertLessEqual(float(sample_rate), 100.0)
237245

246+
# Test sampling behavior with edge case trace ID values
238247
def test_sampler_with_extreme_trace_ids(self):
239248
sampler = RateLimitedSampler(1.0)
240249

@@ -264,6 +273,7 @@ def test_sampler_with_extreme_trace_ids(self):
264273
self.assertGreaterEqual(float(sample_rate), 0.0)
265274
self.assertLessEqual(float(sample_rate), 100.0)
266275

276+
# Test that sampler is thread-safe under concurrent access
267277
def test_thread_safety(self):
268278
sampler = RateLimitedSampler(10.0)
269279
results = []
@@ -293,6 +303,7 @@ def worker():
293303
self.assertIn(result.decision, [Decision.RECORD_AND_SAMPLE, Decision.DROP])
294304
self.assertIn(_SAMPLE_RATE_KEY, result.attributes)
295305

306+
# Test inheriting sampling decision from sampled parent span with sample rate
296307
def test_parent_span_sampled_with_sample_rate(self):
297308
sampler = RateLimitedSampler(10.0)
298309

@@ -310,6 +321,7 @@ def test_parent_span_sampled_with_sample_rate(self):
310321
self.assertEqual(result.decision, Decision.RECORD_AND_SAMPLE)
311322
self.assertEqual(result.attributes[_SAMPLE_RATE_KEY], 75.0)
312323

324+
# Test inheriting sampling decision from non-sampled parent span with sample rate
313325
def test_parent_span_not_sampled_with_sample_rate(self):
314326
sampler = RateLimitedSampler(10.0)
315327

@@ -327,6 +339,7 @@ def test_parent_span_not_sampled_with_sample_rate(self):
327339
self.assertEqual(result.decision, Decision.DROP)
328340
self.assertEqual(result.attributes[_SAMPLE_RATE_KEY], 0.0)
329341

342+
# Test parent span with 100% sample rate maintains decision
330343
def test_parent_span_sampled_with_100_percent_sample_rate(self):
331344
sampler = RateLimitedSampler(5.0)
332345

@@ -344,6 +357,7 @@ def test_parent_span_sampled_with_100_percent_sample_rate(self):
344357
self.assertEqual(result.decision, Decision.RECORD_AND_SAMPLE)
345358
self.assertEqual(result.attributes[_SAMPLE_RATE_KEY], 100.0)
346359

360+
# Test that remote parent spans are ignored for sampling decisions
347361
def test_parent_span_remote_ignored(self):
348362
sampler = RateLimitedSampler(5.0)
349363

@@ -366,6 +380,7 @@ def test_parent_span_remote_ignored(self):
366380

367381
self.assertNotEqual(result.attributes[_SAMPLE_RATE_KEY], 80.0)
368382

383+
# Test parent span without sample rate attribute uses local sampling
369384
def test_parent_span_no_sample_rate_attribute(self):
370385
sampler = RateLimitedSampler(5.0)
371386

@@ -390,6 +405,7 @@ def test_parent_span_no_sample_rate_attribute(self):
390405
sample_rate = result.attributes[_SAMPLE_RATE_KEY]
391406
self.assertIsInstance(sample_rate, (int, float))
392407

408+
# Test handling parent span with invalid span context
393409
def test_parent_span_invalid_context(self):
394410
sampler = RateLimitedSampler(5.0)
395411

@@ -418,6 +434,7 @@ def test_parent_span_invalid_context(self):
418434
sample_rate = result.attributes[_SAMPLE_RATE_KEY]
419435
self.assertIsInstance(sample_rate, (int, float))
420436

437+
# Test sampling behavior when no parent context is provided
421438
def test_no_parent_context_uses_local_sampling(self):
422439
sampler = RateLimitedSampler(5.0)
423440

@@ -437,6 +454,7 @@ def test_no_parent_context_uses_local_sampling(self):
437454
sample_rate = result.attributes[_SAMPLE_RATE_KEY]
438455
self.assertIsInstance(sample_rate, (int, float))
439456

457+
# Test that original span attributes are preserved in sampling result
440458
def test_parent_context_preserves_original_attributes(self):
441459
sampler = RateLimitedSampler(10.0)
442460

@@ -464,6 +482,7 @@ def test_parent_context_preserves_original_attributes(self):
464482

465483
class TestUtilityFunctions(unittest.TestCase):
466484

485+
# Test that DJB2 hash produces consistent results for the same input
467486
def test_djb2_hash_consistency(self):
468487
from azure.monitor.opentelemetry.exporter.export.trace._utils import _get_DJB2_sample_score
469488

@@ -473,6 +492,7 @@ def test_djb2_hash_consistency(self):
473492

474493
self.assertTrue(all(score == scores[0] for score in scores))
475494

495+
# Test DJB2 hash function with edge case inputs
476496
def test_djb2_hash_edge_cases(self):
477497
from azure.monitor.opentelemetry.exporter.export.trace._utils import _get_DJB2_sample_score
478498

0 commit comments

Comments
 (0)