vaadin / platform

Vaadin platform 10+ is a Java web development platform based on Vaadin web components. If you don't know to which repository your bug report should be filed, use this and we'll move it to the right one.
https://vaadin.com
575 stars 79 forks source link

Usage Statistics tool doesn't collect data for Hilla and hybrid apps in Local Storage #6720

Closed mshabarov closed 2 months ago

mshabarov commented 3 months ago

Describe the bug

This ticket is a follow up for https://github.com/vaadin/platform/issues/6488.

Vaadin usage statistics tools (they involve few modules), that work in the browser, do not collect stats for Hilla and hybrid applications (Hilla + Flow) and do not send the stats to the stats server.

More precisely, the Local Storage vaadin.statistics.basket does not exist even after several reruns of Hilla applications, however the window.Vaadin.registrations array gets all the expected stats parameters. This leads also to ~/.vaadin/usage-statistics.json to not having any statistics (only some general fields, like timestamps, system info etc.).

Once the bundle mode (vaadin.frontend.hotdeploy=false) is enforced for Hilla and hybrid apps, the Local Storage gets populated as expected.

Taking into account these observations, I'd say the problem is somewhere in the Vite configuration, where the vaadin-udage-statistics.js module is generated (uncommented). So it's not generated, or it's not uncommented, or it's not loaded, or it's loaded in the wrong order in the browser, i.e. before window.Vaadin.registrations are populated with the data.

This fix was aimed to fix this anomaly, but looks like it's not enough.

The diagram below describes the data flows and possible problematic place:

image

Expected-behavior

Vaadin application should record the statistics to ~/.vaadin/usage-statistics.json after shutdown.

Reproduction

Can be reproduced with the branch in hybrid app example, where I've put extra code to trigger all the stats parameters listed in https://github.com/vaadin/platform/issues/6488.

  1. Back-up the file ~/.vaadin/usage-statistics.json and delete it.
  2. Delete Local Storage vaadin.statistics.basket in browser under "Application" tab in dev tools.
  3. ./mvnw
  4. Browse the app with both Safari, Firefox, and Chrome

Results: usage-statistics.json does not contain has-flow-route or has-endpoint or has-hilla-fs-route or @vaadin/hilla-file-router/createMenuItems parameters, it basically doesn't have any records.

local storages in Safari, Firefox, and Chrome have no vaadin.statistics.basket storages.

References

Vaadin Statistics Tool (browser part) - https://github.com/vaadin/vaadin-usage-statistics/blob/master/src/vaadin-usage-statistics.js Web-components part that collect stats - https://github.com/vaadin/web-components/blob/1a9fc33a212642bbd9862e5cf9b89bbf55dd150d/packages/component-base/src/element-mixin.js#L22 Vaadin Dev Tools that sends stats to server - https://github.com/vaadin/flow/blob/main/vaadin-dev-server/src/main/frontend/vaadin-dev-tools.ts

System Info

Vaadin 24.4.x and pre 24.5.x

Artur- commented 3 months ago

Vite does not preserve the comment inside the maybeGatherAndSendStats function so when it tries to uncomment and execute at runtime, it only runs function maybeGatherAndSendStats() {\n }

mshabarov commented 3 months ago

This may fix it - https://github.com/vaadin/vaadin-usage-statistics/pull/79, needs to be tested with the next platform release.

mshabarov commented 2 months ago

That fix is not enough as the problem still reproducible with 24.5.0.alpha14. But we'll investigate further why the vaadin-usage-statistics doesn't run.

UPD: re-tested with another fresh Hilla applications and can see the stats data in the local storage and json file.

mcollovati commented 2 months ago

Tested with 24.5.0.alpha15 and it seems to work as expected. Both local storage and JSON file are populated.

mshabarov commented 2 months ago

@jojule could you please test on your local with Vaadin 24.5.0.alpha15 ?