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

Report first-time install metric to Particular when a user installs NServiceBus #4280

Merged
merged 9 commits into from Nov 17, 2016

Conversation

indualagarsamy
Copy link
Contributor

@indualagarsamy indualagarsamy commented Nov 8, 2016

Relates to:
https://github.com/Particular/OptimizeTrialExtensions/issues/114
#4262
https://github.com/Particular/Operations.Website.Backend/pull/237

Release Notes

We have removed the page that pops up after installing the NServiceBus NuGet package as the general consensus is that developers don't like it. Examples:

However the page served an alternate purpose which was to indicate when someone has installed the NuGet package for the first time, information we use to determine if we are reaching developers with our message. In place of the popup page, we have added code to the installation PowerShell script that sends a web request to our server to indicate that a first-time installation has occurred to that we can retain this statistic while still removing the post-installation pop-up page.

In, the new reworked PS Script, the majority of the script is now run as a background job. The advantages to this approach are:

  • Background jobs run async to the main script
  • Background jobs run silently even if they fail
  • Also, it will be easier to debug any issues encountered in the script. Tracing is also turned on in the background job so the execution path is visible. The job output can be obtained by using:
  Receive-Job -name particular.analytics 

Pros:

  • Makes sure this metric report is only done inside a development environment.
  • Can continue to use the pre-existing google analytics that tracks installs as opposed to first time execution

Cons:

  • We are continuing to use and add more stuff to init.ps1 when we are actually trying to get rid of it.
  • Creates more problems, see: init.ps1 freezing with VS2015 #4235
  • This approach is bad for the long term. The latest nuget has already deprecated install/uninstall scripts
  • While the init script is technically still supported for now, the future remains unclear. Also, when installing the nuget into a project.json-based project, the install/uninstall scripts will be ignored.

@gbiellem @andreasohlund - please have a look.

@indualagarsamy
Copy link
Contributor Author

@gbiellem - i'm done. Please review. If happy, go ahead and remove the WIP.

timbussmann
timbussmann previously approved these changes Nov 8, 2016
}
Catch [Exception] {
Write-Warning $error[0]
}
finally {
if ($wc){
$wc.Dispose()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this guaranteed to work? According to the doco upload async asynchronously uploads without blocking which means the finally block can be executed during the upload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danielmarbach - See http://stackoverflow.com/questions/1999858/how-bad-is-it-to-not-dispose-in-powershell

As far as I know, the call will execute asynchronously, even after the package manager is done and back to the console. I tested this by running the backend locally and set a breakpoint. The nuget install completed and got back to the prompt but the code was still invoked and waiting at the breakpoint I set.

Also this is a one time thing. We are not calling this script over and over. IMO, it shouldn't have any impact. What exact changes are you requesting here? Do you have any suggestions of what I can add here in the powershell?

@gbiellem - your thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

I think what @danielmarbach is getting at is since the powershell script is never awaiting the result of the async UploadValuesAsync call, that means the finally block could be executed and dispose the WebClient before the call finishes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct what @bording said

@timbussmann timbussmann changed the title WIP: Reporting first time install metric to Particular when a first time user installs NServiceBus [WIP] Reporting first time install metric to Particular when a first time user installs NServiceBus Nov 8, 2016
$postData.Add("version", $packageversion)
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.UploadValuesAsync($url,"post", $postdata)
Copy link
Contributor

Choose a reason for hiding this comment

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

since we don't catch the exception here, what happens with the script if an exception is thrown? is that swallowed the same way as in a c# app or will this break the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timbussmann - I have tested this scenario with a bad url. It does not break the script.
I also tested it by disabling the network adapter and running the nuget install (from local source), errors do not get reported.

@indualagarsamy indualagarsamy added this to the 6.1.0 milestone Nov 9, 2016
@indualagarsamy indualagarsamy self-assigned this Nov 9, 2016
@gbiellem
Copy link
Contributor

@indualagarsamy

I reworked the PS Script as you requested. The way it works now is the majority of the script is run as a background job. The advantages to this approach are:

  • background jobs run async to the main script
  • background jobs run silently even if they fail

I'm hoping that as well as addressing what you wanted it may also address the hanging issue in #4235. Since we can't reproduce that issue it's hard to know for sure.

I've also turned tracing on in the background job so you can see the execution path.
You can do this by dumping the job output using

Receive-Job -name particular.analytics 

You'll see in the script if the Job exists in the current PS session the script skips it so for testing you'll need to remove the job between runs...

Remove-Job -name particular.analytics

If you're not familiar with PS Jobs take a look at https://technet.microsoft.com/en-us/library/hh847783(v=wps.620).aspx

I've made a few other tweaks to simplify it. Please smoke test it and see what you think

@timbussmann
Copy link
Contributor

@indualagarsamy please remove the WIP prefix if you think this one is good to go now.

@gbiellem
Copy link
Contributor

@timbussmann It's not ready. @indualagarsamy and I found an issue when smoke testing it.
We're working on it now

@indualagarsamy indualagarsamy changed the title [WIP] Reporting first time install metric to Particular when a first time user installs NServiceBus Reporting first time install metric to Particular when a first time user installs NServiceBus Nov 17, 2016
@indualagarsamy
Copy link
Contributor Author

@Particular/nservicebus-maintainers - Both @gbiellem and I have tested this PS script. The only change we made in addition to @gbiellem's previous changes were to ensure that we don't display the notice message to an existing user if the user simply uninstalls/reinstalls the nuget package.

We've tested this end to end. This should address @danielmarbach's original concern of disposing the httpclient. We are now using the above approach to keep the installing the package completely asynchronous in relation to making the web request call.

Please review and merge.

$platformKeyPath = 'HKCU:SOFTWARE\ParticularSoftware'

if ((Test-Path $nserviceBusKeyPath) -or (Test-Path $platformKeyPath)) {
New-Event -SourceIdentifier $noticeEvent -Sender "analytics" -MessageData "existing"
Copy link
Contributor

Choose a reason for hiding this comment

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

that event doesn't seem to be used, is this still required?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's used, without it the wait-event at the end of the script would have to wait for the timeout

Copy link
Contributor

@timbussmann timbussmann left a comment

Choose a reason for hiding this comment

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

looks good based on my very limited PS knowledge

@indualagarsamy
Copy link
Contributor Author

@Particular/nservicebus-maintainers - The build is failing on a code inspection check. However, this PR has not made any code changes other than the powershell script. Can you please have a look.
@andreasohlund - it might be that the fix to app_packages isn't working. See below:

NServiceBus.Core/App_Packages/Particular.Licensing
 UserSidChecker.cs (1)
10: Expression is always true

@bording bording dismissed danielmarbach’s stale review November 17, 2016 23:49

Concern has been addressed

Copy link
Member

@bording bording left a comment

Choose a reason for hiding this comment

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

LGTM

@bording bording changed the title Reporting first time install metric to Particular when a first time user installs NServiceBus Report first-time install metric to Particular when a user installs NServiceBus Nov 17, 2016
@bording bording merged commit c0a0118 into develop Nov 17, 2016
@bording bording deleted the powershell-is-back branch November 17, 2016 23:57
@danielmarbach danielmarbach mentioned this pull request Dec 8, 2016
38 tasks
indualagarsamy pushed a commit to Particular/PlatformInstaller that referenced this pull request Dec 8, 2016
gbiellem pushed a commit to Particular/PlatformInstaller that referenced this pull request Dec 13, 2016
* Privacy policy inclusions

Relates to Particular/NServiceBus#4280
Relates to #193

* removed the last updated timestamp
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.

None yet

6 participants