Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor]: Enhancement to selfTime calculation logic in TraceStatistics view #1901

Merged

Conversation

GLVSKiriti
Copy link
Contributor

@GLVSKiriti GLVSKiriti commented Oct 21, 2023

Which problem is this PR solving?

Description of the changes

  • When calculating selfTime of a span
  • selfTime is the total time spent in the span when it was not waiting on children.
    • So we skip the FOLLOWS_FROM type child spans
  • selfTime = duration - (total time consumed by child spans between span startTime and endTime)
  • This is implemented by using DRange similar to the logic in TraceGraph
    @yurishkuro

Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
@GLVSKiriti GLVSKiriti requested a review from a team as a code owner October 21, 2023 10:16
@GLVSKiriti GLVSKiriti requested review from yurishkuro and removed request for a team October 21, 2023 10:16
@GLVSKiriti GLVSKiriti changed the title Enhancement to selfTime calculation logic in TraceStatistics view [Refactor]: Enhancement to selfTime calculation logic in TraceStatistics view Oct 21, 2023
@GLVSKiriti
Copy link
Contributor Author

unitTests
These are three tests which are failing

@GLVSKiriti
Copy link
Contributor Author

  1. traceWithOverlappingChildrenLongerThanParent
    a10
    and final value of selfTotal is calculated from this

    oneColumnChange.selfTotal = Math.round((oneColumnChange.selfTotal / 1000) * 100) / 100;

    so the final selfTotal = 0.03 but I don't know why it is 10.33 in unit test

  2. traceWithTwoNonOverlappingChildren
    a11
    similarly selfTotal = 0.03

  3. traceWithSingleChildSpanLongerThanParent
    a12
    similarly selfTotal = 0.04

@GLVSKiriti
Copy link
Contributor Author

Is this calculations are correct Or am I doing wrong ?

@yurishkuro
Copy link
Member

Regarding the tests, I would recommend replacing the times / durations in the fixture files with smaller numbers that are easier to grok without a calculator, like start=100000, duration=100 (pick values to retain the overall magnitude, but make the numbers round)

Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
@codecov
Copy link

codecov bot commented Oct 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
...mponents/TracePage/CriticalPath/testCases/test3.js 100.00% <100.00%> (ø)
...mponents/TracePage/TraceStatistics/tableValues.tsx 98.99% <100.00%> (-0.34%) ⬇️

📢 Thoughts on this report? Let us know!.

Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
@yurishkuro yurishkuro added the changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements label Oct 22, 2023
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
GLVSKiriti and others added 3 commits October 24, 2023 00:11
…bleValues.tsx

Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: GLVSKiriti <116095646+GLVSKiriti@users.noreply.github.com>
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
@@ -315,18 +147,18 @@ function valueFirstDropdown(selectedTagKey: string, trace: Trace) {
for (let j = 0; j < allSpans.length; j++) {
Copy link
Member

Choose a reason for hiding this comment

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

Just to illustrate my earlier point about linear searches: with this loop in place we're doing O(N^2) work.

Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
Signed-off-by: GLVSKiriti <116095646+GLVSKiriti@users.noreply.github.com>
tempSelfChange += span.duration - duration;

return tempSelfChange;
return Math.round(spanRange.length / 10);
Copy link
Member

Choose a reason for hiding this comment

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

btw, I don't think rounding is necessary, length should always be divisible by 10.

@yurishkuro yurishkuro merged commit 614bfc9 into jaegertracing:main Oct 24, 2023
10 checks passed
@yurishkuro
Copy link
Member

Thanks!

@GLVSKiriti GLVSKiriti deleted the selfTimeEnhancementInTraceStatistics branch October 24, 2023 05:00
@maxgaponov
Copy link
Contributor

Hi, @GLVSKiriti and @yurishkuro . Sorry, I don't quite understand why we need this *10 logic in computeSelfTime function. Can you please explain it for me or give a test case?

We have the comment in the function:

//       range(1, 10).subtract(4, 8) => range([1, 3], [9-10])
//       length=(3-1)+(10-9)=2+1=3

But in my understanding if we have spanA(1, 10) and spanB(4, 8) then we can represent them as range(1, 9) and range(4, 7) accordingly. And range(1, 9).subtract(range(4, 7)) => range([1, 3], [8, 9]) (length=3+2=5 as DRange treats all intervals as inclusive).

@yurishkuro
Copy link
Member

@maxgaponov you may be right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements
Projects
None yet
3 participants