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

[EBT] define global method for determining when telemetry has been shipped #140521

Closed
spalger opened this issue Sep 12, 2022 · 3 comments · Fixed by #144925
Closed

[EBT] define global method for determining when telemetry has been shipped #140521

spalger opened this issue Sep 12, 2022 · 3 comments · Fixed by #144925
Assignees
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc technical debt Improvement of the software architecture and operational architecture

Comments

@spalger
Copy link
Contributor

spalger commented Sep 12, 2022

In #140383 we added a request tracker which observes every request from the page and produces a promise for every request to telemetry-staging.elastic.co, which is resolved as soon as the request succeeds or fails. When a performance journey completes a three second timer is started, and when the three second timer is completed the listener for requests is stopped and all pending requests are awaited.

We do this to try and make sure that we are able to wait for all telemetry requests to complete without just placing an arbitrary delay on every journey.

There is still an edge case here that we might need to fix at some point: the EBT client buffers telemetry for 1 second and the timer which is created to build that 1 second collection of telemetry might not fire before our 3 second timer. Browsers delay timers for all sorts of reasons, and it would be ideal if we could be notified when the buffer is actually cleared and the telemetry up to that point has been sent successfully.

In order for browser automation to interact with the buffer at all there must be a global method written to the window object.

I'm thinking the method might work something like this:

  1. when method is called it creates a deferred value or something similar which will allow the promise to be resolved from elsewhere
  2. this deferred value is wrapped in a "queue flush notification" object and added to the queue
  3. the promise is returned from the method
  4. when the buffer is flushed and handled the "queue flush notification" objects are filtered from the buffered telemetry data
  5. all buffered telemetry data is sent
  6. on success/failure the "queue flush notifications" called to resolve the promises produced by the global function
@spalger spalger added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Sep 12, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@spalger
Copy link
Contributor Author

spalger commented Sep 12, 2022

cc @afharo

@afharo afharo added Feature:Telemetry technical debt Improvement of the software architecture and operational architecture labels Sep 12, 2022
@afharo
Copy link
Member

afharo commented Nov 10, 2022

@spalger @lizozom I created #144925 to implement the flush method that returns a promise that will resolve when the pending events are sent.

It's then leveraged in 2 places:

  • On the browser, it's exposed as window.KbnAnalytics.flush() so it can be called during CI.
  • On the server, it's awaited during shutdown to increase the chances of delivering all pending events.

Do you think this could work to fix this issue?

@afharo afharo self-assigned this Nov 10, 2022
afharo added a commit that referenced this issue Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc technical debt Improvement of the software architecture and operational architecture
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants