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

fix(telemetry): Enable telemetry on windows #7389

Merged
merged 7 commits into from
Jan 21, 2023
Merged

Conversation

Josh-Walker-GM
Copy link
Collaborator

Fixes #5901

Problem
Telemetry is disabled on windows due to the background process spawning console windows. This is too intrusive for users.

Changes

  1. The spawn options needed updating. The ability to easily do the detached, silent background process on windows is not quite there in nodejs. However one user essentially brute forced the spawn options and found that one combination does provide the functionality we require. See child_process - windowsHide not working with detached: true nodejs/node#21825 (comment). The options don't do what they look like they do.
  2. On windows the process.argv options don't return a string which is a valid JSON string array. They return something like [abc,def,xyz] rather than ["abc","def","xyz"]. We therefore need to pre-process this before passing it to yargs.

Outstanding

  1. I've tested this on my own windows 11 machine - it works. I've tested this on ubuntu WSL - it works. Needs more testing?
  2. Was this fix already known and rejected for some reason I am not aware of?

Notes

  1. Most of the time I had the fetch commented out but if telemetry reports a sudden burst of yarn rw info calls it was me.
  2. I attempted to alter as little of telemetry as possible. I was looking to reenable it not change it's functionality or implementation.

@Josh-Walker-GM Josh-Walker-GM added the release:fix This PR is a fix label Jan 20, 2023
@Josh-Walker-GM
Copy link
Collaborator Author

Ping: @thedavidprice

// On windows process.argv may not return an array of strings.
// It will look something like [a,b,c] rather than ["a","b","c"] so we must stringify them before parsing as JSON
// "os.type()" returns 'Windows_NT' on Windows. See https://nodejs.org/docs/latest-v12.x/api/os.html#os_os_type.
if (os.type() === 'Windows_NT') {
Copy link
Member

Choose a reason for hiding this comment

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

I realize this package already used os.type, but the rest of the codebase seems to use process.platform. Any benefit of using one or the other?

Copy link
Collaborator Author

@Josh-Walker-GM Josh-Walker-GM Jan 21, 2023

Choose a reason for hiding this comment

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

Not immediately aware of anything specific other than if we use process.platform it would be one less require? @cannikin had a specific reason behind this choice?

Copy link
Member

Choose a reason for hiding this comment

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

I probably didn't realize there even was a process.platform! Is there anything else telemetry uses from that os lib that isn't available through process?

Also the strings that process.platform returns may be different than what's returned by os? We would want to either convert them to be the same, or update the existing entries in the telemetry database to match, so we don't have different strings for the same platform.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that os is only used for the is windows conditionals.

The actual payload that's sent as telemetry is constructed from data from the envinfo package. That would mean no changes to the actual payload and so no data discontinuities. Unless I'm mistaken?

Copy link
Member

Choose a reason for hiding this comment

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

Sweet! Yeah let's axe it.

Copy link
Member

Choose a reason for hiding this comment

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

I found this https://stackoverflow.com/a/61744810/88106
Seems to suggest os.type() might be more reliable in VMs

Copy link
Collaborator Author

@Josh-Walker-GM Josh-Walker-GM Jan 21, 2023

Choose a reason for hiding this comment

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

The node docs https://nodejs.org/api/os.html#osplatform for os.platform() state that "The return value is equivalent to process.platform."

Although not sure if that SO comment was highlighting that that isn't reliable when operating in VMs.

EDIT: I guess we could just leave it as os.type(). It's worked this long without issues and it appears from the docs that Tobbe's right about being more reliable on VMs.

Copy link
Member

Choose a reason for hiding this comment

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

Turns out I was a genius all along! 😅

Copy link
Member

Tobbe commented Jan 21, 2023

Does that mean we should change the existing uses of process.platform to os.type()? 🙈

@Tobbe Tobbe enabled auto-merge (squash) January 21, 2023 21:03
@Tobbe Tobbe merged commit f49389d into main Jan 21, 2023
@Tobbe Tobbe deleted the jgmw-telemetry-improvise branch January 21, 2023 22:11
@redwoodjs-bot redwoodjs-bot bot added this to the next-release milestone Jan 21, 2023
jtoar pushed a commit that referenced this pull request Jan 22, 2023
* Update spawn options and argv processing for windows

* comment typo
@jtoar jtoar modified the milestones: next-release, v4.0.0 Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tech debt]: Re-enable telemetry for windows
4 participants