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

✨ [RUMF-1207] collect concurrent actions #1434

Merged
merged 5 commits into from
Mar 25, 2022

Conversation

BenoitZugmeyer
Copy link
Member

Motivation

Follow-up of #1432 : this actually implements concurrent actions behind a FF

Changes

  • Adjust contextHistory to allow multiple active entries
  • Relax the condition discarding any new action occuring while another is still active.

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner March 21, 2022 16:34
@BenoitZugmeyer BenoitZugmeyer marked this pull request as draft March 21, 2022 16:35
})
expect((serverRumEvents[0] as RumActionEvent).action.id).not.toEqual('7890')
expect((serverRumEvents[0] as RumActionEvent).action.id).toEqual(generatedRawRumActionEvent.action.id)
Copy link
Member Author

Choose a reason for hiding this comment

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

I made this change because I feared that not.toEqual was not specific enough now that it can be either an array or a string.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good

Base automatically changed from benoit/concurrent-actions-1 to main March 23, 2022 14:49
* Simplify the test context from `{ value: string }` to `string`. As
  we'll write a few more tests, it will help to have more concise
  values.

* `startClocks` is in fact called `startTime` in the code

* Add a test to make sure that calling `find()` without argument does
  not return the last closed context.
Because we'll have multiple concurrent action entries, we need to change
the `ContextHistory` to support this. With this commit:

* instead of keeping a reference to the current active context, the
  context history now returns the reference with associated methods to
  "close" and "remove" it. The code using context history is able to
  keep multiple references to the active contexts.

* a new `findAll` method is introduced returning a list of contexts
  instead of a single context that we'll use to get multiple action ids.
This commit changes the `action.id` typings to support either a single
string or an array. It impacts:
* any event that can be an action child
* the internal monitoring context
* the internal context, so logs will also inherit from this change
Finally, remove the "one action at a time" limitation and collect a new
action for every click, even if another one is ongoing.

To do this, we still need to keep a reference to pending actions because
we need to discard them:
* when a view is created (this will be removed in a future PR)
* when stopping action collections (for tests)

This is somewhat cumbersome, but not a huge deal either.
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/concurrent-actions-2 branch from d4bb96d to 6beff83 Compare March 23, 2022 15:03
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2022

Codecov Report

Merging #1434 (7a008e6) into main (6cbb7f5) will increase coverage by 0.02%.
The diff coverage is 97.95%.

@@            Coverage Diff             @@
##             main    #1434      +/-   ##
==========================================
+ Coverage   89.86%   89.88%   +0.02%     
==========================================
  Files         107      107              
  Lines        4291     4291              
  Branches      952      952              
==========================================
+ Hits         3856     3857       +1     
+ Misses        435      434       -1     
Impacted Files Coverage Δ
.../domain/rumEventsCollection/action/trackActions.ts 96.36% <88.88%> (+0.06%) ⬆️
packages/core/src/domain/session/sessionManager.ts 100.00% <100.00%> (ø)
packages/core/src/tools/contextHistory.ts 100.00% <100.00%> (ø)
packages/rum-core/src/domain/urlContexts.ts 100.00% <100.00%> (ø)
packages/rum-core/src/domain/viewContexts.ts 100.00% <100.00%> (ø)
packages/core/src/tools/timeUtils.ts 100.00% <0.00%> (+2.85%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review March 23, 2022 15:12
* Return the latest context that was active during `startTime`, or the currently active context
* if no `startTime` is provided. This method assumes that entries are not overlapping.
*/
find(startTime: RelativeTime = END_OF_TIMES): Context | undefined {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it could be more expressive to have a find() with a required param and a getActive() a bit like before.
Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it, but we almost always use find() with an optional argument (see here here here) so it would mean duplicate all those methods too, which is not ideal.

Comment on lines +58 to 65
for (const entry of this.entries) {
if (entry.startTime <= startTime) {
if (startTime <= entry.endTime) {
return entry.context
}
break
}
if (startTime >= previousContext.startTime) {
return previousContext.context
}
}
Copy link
Collaborator

@amortemousque amortemousque Mar 24, 2022

Choose a reason for hiding this comment

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

Isn't this code equal to findAll(startTime)[0]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we could replace this by that. But we don't really need to iterate over all entries for find, so the current find implementation is in fact an optimization that was present in the previous ContextHistory implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it. The optimization for findAll we talked about was not possible after investigation, but I still simplified the find method as you suggested.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I changed my mind, I think the find method should keep this optimization. Who knows, maybe an app could have many URL changes, and produce a lot of views. In this case, without optimization, all events produced will need to iterate over all views, which will have a performance impact.

})
expect((serverRumEvents[0] as RumActionEvent).action.id).not.toEqual('7890')
expect((serverRumEvents[0] as RumActionEvent).action.id).toEqual(generatedRawRumActionEvent.action.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/concurrent-actions-2 branch from 6b35d63 to 6beff83 Compare March 25, 2022 11:40
@BenoitZugmeyer BenoitZugmeyer merged commit 41dd4be into main Mar 25, 2022
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/concurrent-actions-2 branch March 25, 2022 13:27
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.

3 participants