Skip to content

RUM-9130: Fix flaky TraceWriterTest M log error and proceed W write() { serialization failed }#2565

Merged
aleksandr-gringauz merged 1 commit into
developfrom
aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test
Mar 25, 2025
Merged

RUM-9130: Fix flaky TraceWriterTest M log error and proceed W write() { serialization failed }#2565
aleksandr-gringauz merged 1 commit into
developfrom
aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test

Conversation

@aleksandr-gringauz

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixed a flaky test. Had to parametrize SpanForgeryFactory in order to control forging the samplingPriority field. I am not sure it is a canonical way of doing things so feel free to criticize.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test branch from bb36104 to 31b362d Compare March 24, 2025 17:12
@aleksandr-gringauz
aleksandr-gringauz marked this pull request as ready for review March 24, 2025 17:26
@aleksandr-gringauz
aleksandr-gringauz requested review from a team as code owners March 24, 2025 17:26
@codecov-commenter

codecov-commenter commented Mar 24, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.10%. Comparing base (2270254) to head (7faab76).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2565      +/-   ##
===========================================
- Coverage    70.11%   70.10%   -0.01%     
===========================================
  Files          803      803              
  Lines        30144    30146       +2     
  Branches      5046     5046              
===========================================
- Hits         21135    21133       -2     
+ Misses        7610     7607       -3     
- Partials      1399     1406       +7     
Files with missing lines Coverage Δ
...datadog/android/trace/internal/data/TraceWriter.kt 94.12% <100.00%> (+0.37%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

0xnm
0xnm previously approved these changes Mar 24, 2025
Comment on lines +332 to +338
private fun generateSpanListWithPriorities(forge: Forge, priorities: Set<Int>): MutableList<DDSpan> {
return forge.aList {
SpanForgeryFactory { frg, span ->
span.samplingPriority = frg.anElementFrom(priorities)
}.getForgery(forge)
}.toMutableList()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be done simpler, without the need to do changes in SpanForgeryFactory (plus it can be an extension method):

Suggested change
private fun generateSpanListWithPriorities(forge: Forge, priorities: Set<Int>): MutableList<DDSpan> {
return forge.aList {
SpanForgeryFactory { frg, span ->
span.samplingPriority = frg.anElementFrom(priorities)
}.getForgery(forge)
}.toMutableList()
}
private fun Forge.spansWithPriorities(forge: Forge, priorities: Set<Int>): MutableList<DDSpan> {
return aList {
getForgery<DDSpan>().apply { span.samplingPriority = anElementFrom(priorities) }
}.toMutableList()
}

but I'm okay with keeping the proposed change as well.

@aleksandr-gringauz aleksandr-gringauz Mar 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be done simpler

I did it the way you describe at first. But this actually is a different solution that didn't quite work.

  1. Suppose SpanForgeryFactory sets samplingPriority to PrioritySampling.USER_DROP here.
  2. Then we change it the way you describe to PrioritySampling.UNSET. PrioritySampling.UNSET satisfies the condition !in DROP_SAMPLING_PRIORITIES, it was used in the test before, so we probably should not forget about it.
  3. Here PrioritySampling.UNSET is ignored.
  4. We end up with a failed test because we have PrioritySampling.USER_DROP as priority.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, makes sense then for PrioritySampling.UNSET case

Comment on lines +95 to +96
private val KEEP_SAMPLING_PRIORITIES = setOf(PrioritySampling.SAMPLER_KEEP, PrioritySampling.USER_KEEP)
internal val KEEP_AND_UNSET_SAMPLING_PRIORITIES = KEEP_SAMPLING_PRIORITIES + PrioritySampling.UNSET

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably these are needed only for tests? maybe put them in the TraceWriterTest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it is better this way because if you put KEEP_AND_UNSET_SAMPLING_PRIORITIES in test source set, when it is needed in the main source set later we will end up with duplicate code with very high chance. These things should probably be grouped together even if some are needed only in tests for now.

jonathanmos
jonathanmos previously approved these changes Mar 25, 2025
@aleksandr-gringauz
aleksandr-gringauz dismissed stale reviews from jonathanmos and 0xnm via 887d426 March 25, 2025 11:56
@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test branch from 31b362d to 887d426 Compare March 25, 2025 11:56
@aleksandr-gringauz

Copy link
Copy Markdown
Contributor Author

just resolved conflicts

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test branch from 887d426 to 7faab76 Compare March 25, 2025 11:57
@aleksandr-gringauz
aleksandr-gringauz merged commit 245c50a into develop Mar 25, 2025
@aleksandr-gringauz
aleksandr-gringauz deleted the aleksandr-gringauz/rum-9130/fix-flacky-trace-writer-test branch March 25, 2025 17:04
@0xnm 0xnm mentioned this pull request Mar 28, 2025
3 tasks
aleksandr-gringauz added a commit that referenced this pull request Mar 28, 2025
…-flacky-trace-writer-test

RUM-9130: Fix flaky TraceWriterTest M log error and proceed W write() { serialization failed }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants