Skip to content

Diagnostics: limit events sent#793

Merged
tonidero merged 4 commits into
diagnosticsfrom
diagnostics-limit-events-sent
Feb 16, 2023
Merged

Diagnostics: limit events sent#793
tonidero merged 4 commits into
diagnosticsfrom
diagnostics-limit-events-sent

Conversation

@tonidero

@tonidero tonidero commented Feb 13, 2023

Copy link
Copy Markdown
Contributor

Description

Based on #785
Deals with CSDK-648

In this PR we add a limit to the number of events that can be sent to the backend and we add a diagnostics event tracking when this happens.

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.

Note that we currently perform this deleting + sending diagnostics event when syncing, not tracking. This means the file can potentially exceed the max number of events but it shouldn't be that much if we sync every time the SDK is configured. Also, note that if we fail syncing 3 times, we simply delete the whole file, so it shouldn't grow that much even if it keeps failing syncing. Lmk what you think!

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 separated this logic into this method to be able to send the MAX_EVENTS_STORED_LIMIT_REACHED event in the same sync we detect we've reached the limit. If we added tracking the event to the queue, we would sync the events that existed before, then add the event to the diagnostics file, so we would miss a sync for tracking these events.

@tonidero tonidero requested review from a team and cadamsdotcom February 13, 2023 13:06
@tonidero tonidero marked this pull request as ready for review February 13, 2023 13:06
@tonidero tonidero changed the title Diagnostics limit events sent Diagnostics: limit events sent Feb 13, 2023
@codecov

codecov Bot commented Feb 13, 2023

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (diagnostics@0f9a64e). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head de85a24 differs from pull request most recent head a5f1219. Consider uploading reports for the commit a5f1219 to get more accurate results

@@              Coverage Diff               @@
##             diagnostics     #793   +/-   ##
==============================================
  Coverage               ?   81.97%           
==============================================
  Files                  ?      127           
  Lines                  ?     4150           
  Branches               ?      521           
==============================================
  Hits                   ?     3402           
  Misses                 ?      542           
  Partials               ?      206           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

does this method need to be synchronized?

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.

Hmm I would say with our current calls the chances of a race condition are 0 but for the sake of completeness, you're correct 👍

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.

Actually, I've been thinking that while we can make this class support multi-threading, considering we are using the same thread for everything related to diagnostics that would complicate the class without need. I improved the docstring for DiagnosticsManager but lmk if you still think we should future-proof it against multi-threading.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

YAGNI 👍🏻 sometimes the best way to make things thread safe is to just document that a type can't be used from multiple threads and deal with that outside of the class, keeps things much simpler.

@tonidero tonidero force-pushed the diagnostics-manager branch from a6873d9 to 51d8760 Compare February 15, 2023 08:39
@tonidero tonidero force-pushed the diagnostics-limit-events-sent branch from 03e044b to fa7ab39 Compare February 15, 2023 10:08
Base automatically changed from diagnostics-manager to diagnostics February 16, 2023 08:58
@tonidero tonidero force-pushed the diagnostics-limit-events-sent branch from de85a24 to a5f1219 Compare February 16, 2023 09:31
@tonidero tonidero merged commit dc593f6 into diagnostics Feb 16, 2023
@tonidero tonidero deleted the diagnostics-limit-events-sent branch February 16, 2023 09:32
tonidero added a commit that referenced this pull request Feb 17, 2023
…795)

### Description
Based on #793 
This PR refactors previous code to split the `DiagnosticsManager` into
`DiagnosticsTracker` and `DiagnosticsSynchronizer`. This is a
prerequisite to avoid circular dependencies when tracking request data.
- Before:
`DiagnosticsManager`->`Backend`->`HttpClient`->`DiagnosticsManager`.
- After: `DiagnosticsSynchronizer`->`Backend` for syncing and
`HttpClient`->`DiagnosticsTracker` for tracking requests

I could have tried to extract this logic from the HttpClient, but that
would be a bigger refactor. This was the simplest solution I thought for
this problem. Also, sorry I didn't see that issue before. I didn't
modify the #785 PR directly to try to avoid some conflicts that would
happen if I did it there directly.
tonidero added a commit that referenced this pull request Feb 22, 2023
…795)

### Description
Based on #793 
This PR refactors previous code to split the `DiagnosticsManager` into
`DiagnosticsTracker` and `DiagnosticsSynchronizer`. This is a
prerequisite to avoid circular dependencies when tracking request data.
- Before:
`DiagnosticsManager`->`Backend`->`HttpClient`->`DiagnosticsManager`.
- After: `DiagnosticsSynchronizer`->`Backend` for syncing and
`HttpClient`->`DiagnosticsTracker` for tracking requests

I could have tried to extract this logic from the HttpClient, but that
would be a bigger refactor. This was the simplest solution I thought for
this problem. Also, sorry I didn't see that issue before. I didn't
modify the #785 PR directly to try to avoid some conflicts that would
happen if I did it there directly.
tonidero added a commit that referenced this pull request Feb 28, 2023
tonidero added a commit that referenced this pull request Feb 28, 2023
…795)

### Description
Based on #793 
This PR refactors previous code to split the `DiagnosticsManager` into
`DiagnosticsTracker` and `DiagnosticsSynchronizer`. This is a
prerequisite to avoid circular dependencies when tracking request data.
- Before:
`DiagnosticsManager`->`Backend`->`HttpClient`->`DiagnosticsManager`.
- After: `DiagnosticsSynchronizer`->`Backend` for syncing and
`HttpClient`->`DiagnosticsTracker` for tracking requests

I could have tried to extract this logic from the HttpClient, but that
would be a bigger refactor. This was the simplest solution I thought for
this problem. Also, sorry I didn't see that issue before. I didn't
modify the #785 PR directly to try to avoid some conflicts that would
happen if I did it there directly.
tonidero added a commit that referenced this pull request Feb 28, 2023
tonidero added a commit that referenced this pull request Feb 28, 2023
…795)

### Description
Based on #793 
This PR refactors previous code to split the `DiagnosticsManager` into
`DiagnosticsTracker` and `DiagnosticsSynchronizer`. This is a
prerequisite to avoid circular dependencies when tracking request data.
- Before:
`DiagnosticsManager`->`Backend`->`HttpClient`->`DiagnosticsManager`.
- After: `DiagnosticsSynchronizer`->`Backend` for syncing and
`HttpClient`->`DiagnosticsTracker` for tracking requests

I could have tried to extract this logic from the HttpClient, but that
would be a bigger refactor. This was the simplest solution I thought for
this problem. Also, sorry I didn't see that issue before. I didn't
modify the #785 PR directly to try to avoid some conflicts that would
happen if I did it there directly.
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