From 2a4e1778eda2c4b641c12188dd5cf80b92012ced Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 9 Apr 2018 12:17:20 +0900 Subject: [PATCH 1/3] remove support for file to opt-out of telemetry, only support env var --- .gitignore | 3 --- DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY | 0 README.md | 2 +- assets/files.wxs | 4 ---- build.psm1 | 3 --- .../host/msh/Telemetry.cs | 13 ++----------- src/powershell-unix/powershell-unix.csproj | 2 +- src/powershell-win-core/powershell-win-core.csproj | 2 +- tools/appveyor.psm1 | 7 ++----- .../build-and-run-pwsh.sh | 3 --- tools/travis.ps1 | 7 ++----- 11 files changed, 9 insertions(+), 37 deletions(-) create mode 100644 DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY diff --git a/.gitignore b/.gitignore index 5e0a2cf5b16..4d4e69760b4 100644 --- a/.gitignore +++ b/.gitignore @@ -46,9 +46,6 @@ dotnet-uninstall-debian-packages.sh *.nupkg *.AppImage -# ignore the telemetry semaphore file -DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY - # default location for produced nuget packages /nuget-artifacts diff --git a/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY b/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY new file mode 100644 index 00000000000..e69de29bb2d diff --git a/README.md b/README.md index 3ff3bb15855..07a25e91491 100644 --- a/README.md +++ b/README.md @@ -230,7 +230,7 @@ License: By requesting and using the Container OS Image for Windows containers, ### Telemetry By default, PowerShell collects the OS description and the version of PowerShell (equivalent to `$PSVersionTable.OS` and `$PSVersionTable.GitCommitId`) using [Application Insights](https://azure.microsoft.com/en-us/services/application-insights/). -To opt-out of sending telemetry, delete the file `DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY` before starting PowerShell from the installed location. +To opt-out of sending telemetry, create an environment variable called `POWERSHELL_TELEMETRY_OPTOUT` set to a value of `1` before starting PowerShell from the installed location. The telemetry we collect fall under the [Microsoft Privacy Statement](https://privacy.microsoft.com/en-us/privacystatement/). ## Governance diff --git a/assets/files.wxs b/assets/files.wxs index 8e8d60b9799..b33e2e2fb7d 100644 --- a/assets/files.wxs +++ b/assets/files.wxs @@ -193,9 +193,6 @@ - - - @@ -1890,7 +1887,6 @@ - diff --git a/build.psm1 b/build.psm1 index 2bb5f6c243f..983d9398986 100644 --- a/build.psm1 +++ b/build.psm1 @@ -453,9 +453,6 @@ function Start-PSBuild { } } - # create the telemetry flag file - $null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY" - # Add .NET CLI tools to PATH Find-Dotnet diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs index 12008425843..6cb45a34a26 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs @@ -19,18 +19,9 @@ namespace Microsoft.PowerShell /// internal static class ApplicationInsightsTelemetry { - // The semaphore file which indicates whether telemetry should be sent - // This is temporary code waiting on the acceptance and implementation of the configuration spec - // The name of the file by when present in $PSHOME will enable telemetry. - // If this file is not present, no telemetry will be sent. - private const string TelemetrySemaphoreFilename = "DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"; + // If this env var is true, yes, or 1, telemetry will NOT be sent. private const string TelemetryOptoutEnvVar = "POWERSHELL_TELEMETRY_OPTOUT"; - // The path to the semaphore file which enables telemetry - private static string TelemetrySemaphoreFilePath = Path.Combine( - Utils.DefaultPowerShellAppBase, - TelemetrySemaphoreFilename); - // Telemetry client to be reused when we start sending more telemetry private static TelemetryClient _telemetryClient = null; @@ -76,7 +67,7 @@ private static void SendTelemetry(string eventName, Dictionarypay try { // if the semaphore file exists, try to send telemetry - var enabled = Utils.NativeFileExists(TelemetrySemaphoreFilePath) && !GetEnvironmentVariableAsBool(TelemetryOptoutEnvVar, false); + var enabled = GetEnvironmentVariableAsBool(TelemetryOptoutEnvVar, false); if (!enabled) { diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj index 947af707237..d49023ef59d 100644 --- a/src/powershell-unix/powershell-unix.csproj +++ b/src/powershell-unix/powershell-unix.csproj @@ -16,7 +16,7 @@ PreserveNewest PreserveNewest - + PreserveNewest PreserveNewest diff --git a/src/powershell-win-core/powershell-win-core.csproj b/src/powershell-win-core/powershell-win-core.csproj index 136ab9e1df7..1c767029390 100644 --- a/src/powershell-win-core/powershell-win-core.csproj +++ b/src/powershell-win-core/powershell-win-core.csproj @@ -20,7 +20,7 @@ PreserveNewest PreserveNewest - + PreserveNewest PreserveNewest diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index d290e394a23..f98d39b987e 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -347,11 +347,8 @@ function Invoke-AppVeyorTest Write-Host -Foreground Green 'Running all CoreCLR tests..' } - # Remove telemetry semaphore file in CI - $telemetrySemaphoreFilepath = Join-Path $env:CoreOutput DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY - if ( Test-Path "${telemetrySemaphoreFilepath}" ) { - Remove-Item -Force ${telemetrySemaphoreFilepath} - } + # Disable telemetry in CI + $env:POWERSHELL_TELEMETRY_OPTOUT = 1 Start-PSPester -Terse -bindir $env:CoreOutput -outputFile $testResultsNonAdminFile -Unelevate -Tag @() -ExcludeTag ($ExcludeTag + @('RequireAdminOnWindows')) Write-Host -Foreground Green 'Upload CoreCLR Non-Admin test results' diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh index 4cc8a1c5348..2624f2b6d96 100755 --- a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh @@ -53,9 +53,6 @@ make -j cd ../.. dotnet restore $dotnetArguments -# Add telemetry file -touch DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY - # run ResGen cd src/ResGen dotnet run diff --git a/tools/travis.ps1 b/tools/travis.ps1 index ae13cd28812..28a9d3d836c 100644 --- a/tools/travis.ps1 +++ b/tools/travis.ps1 @@ -224,11 +224,8 @@ elseif($Stage -eq 'Build') $pesterParam['IncludeFailingTest'] = $true } - # Remove telemetry semaphore file in CI - $telemetrySemaphoreFilepath = Join-Path $output DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY - if ( Test-Path "${telemetrySemaphoreFilepath}" ) { - Remove-Item -force ${telemetrySemaphoreFilepath} - } + # Disable telemetry in CI + $env:POWERSHELL_TELEMETRY_OPTOUT = 1 # Running tests which do not require sudo. $pesterPassThruNoSudoObject = Start-PSPester @pesterParam From cebea478e27da37e021dd936dab0c1404b9ca7a7 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 10 Apr 2018 07:32:54 +0900 Subject: [PATCH 2/3] address PR feedback --- .travis.yml | 1 + appveyor.yml | 3 +++ build.psm1 | 7 ++++++- src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs | 3 +-- tools/appveyor.psm1 | 3 --- tools/travis.ps1 | 3 --- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 898cda2f514..6d1db46ce9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,6 +58,7 @@ after_success: # travis-ci will quit using the cache if an enviroment variable changes env: - CACHE_VERSION=netcoreapp.2.0.6-sdk.2.1.4 + - POWERSHELL_TELEMETRY_OPTOUT=1 # timeout uploading cache after 6 minutes (360 seconds) cache: diff --git a/appveyor.yml b/appveyor.yml index 5d52f914402..2dd6198324d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,9 @@ cache: nuget: project_feed: true +environment: + POWERSHELL_TELEMETRY_OPTOUT: 1 + install: - git submodule update --init - ps: Import-Module .\tools\Appveyor.psm1 diff --git a/build.psm1 b/build.psm1 index 983d9398986..d5a4c6ab379 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1051,7 +1051,9 @@ Restore the module to '$Pester' by running: Publish-PSTestTools | ForEach-Object {Write-Host $_} # All concatenated commands/arguments are suffixed with the delimiter (space) - $command = "" + + # Disable telemetry for all startups of pwsh in tests + $command = "`$env:POWERSHELL_TELEMETRY_OPTOUT = 1;" if ($Terse) { $command += "`$ProgressPreference = 'silentlyContinue'; " @@ -1152,6 +1154,8 @@ Restore the module to '$Pester' by running: # To ensure proper testing, the module path must not be inherited by the spawned process try { $originalModulePath = $env:PSModulePath + $originalTelemetry = $env:POWERSHELL_TELEMETRY_OPTOUT + $env:POWERSHELL_TELEMETRY_OPTOUT = 1 if ($Unelevate) { Start-UnelevatedProcess -process $powershell -arguments @('-noprofile', '-c', $Command) @@ -1228,6 +1232,7 @@ Restore the module to '$Pester' by running: } } finally { $env:PSModulePath = $originalModulePath + $env:POWERSHELL_TELEMETRY_OPTOUT = $originalTelemetry if ($Unelevate) { Remove-Item $outputBufferFilePath diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs index 6cb45a34a26..4548d3b8145 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs @@ -66,8 +66,7 @@ private static void SendTelemetry(string eventName, Dictionarypay { try { - // if the semaphore file exists, try to send telemetry - var enabled = GetEnvironmentVariableAsBool(TelemetryOptoutEnvVar, false); + var enabled = !GetEnvironmentVariableAsBool(name : TelemetryOptoutEnvVar, defaultValue : false); if (!enabled) { diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index f98d39b987e..483e8433079 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -347,9 +347,6 @@ function Invoke-AppVeyorTest Write-Host -Foreground Green 'Running all CoreCLR tests..' } - # Disable telemetry in CI - $env:POWERSHELL_TELEMETRY_OPTOUT = 1 - Start-PSPester -Terse -bindir $env:CoreOutput -outputFile $testResultsNonAdminFile -Unelevate -Tag @() -ExcludeTag ($ExcludeTag + @('RequireAdminOnWindows')) Write-Host -Foreground Green 'Upload CoreCLR Non-Admin test results' Update-AppVeyorTestResults -resultsFile $testResultsNonAdminFile diff --git a/tools/travis.ps1 b/tools/travis.ps1 index 28a9d3d836c..94b37d7fc07 100644 --- a/tools/travis.ps1 +++ b/tools/travis.ps1 @@ -224,9 +224,6 @@ elseif($Stage -eq 'Build') $pesterParam['IncludeFailingTest'] = $true } - # Disable telemetry in CI - $env:POWERSHELL_TELEMETRY_OPTOUT = 1 - # Running tests which do not require sudo. $pesterPassThruNoSudoObject = Start-PSPester @pesterParam From 5085ca65a1c3b2b22a39c74384750a431c9ca9db Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 11 Apr 2018 11:24:29 -0700 Subject: [PATCH 3/3] make env variables global --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d1db46ce9a..9298ab22700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,9 @@ after_success: # travis-ci will quit using the cache if an enviroment variable changes env: - - CACHE_VERSION=netcoreapp.2.0.6-sdk.2.1.4 - - POWERSHELL_TELEMETRY_OPTOUT=1 + global: + - CACHE_VERSION=netcoreapp.2.0.6-sdk.2.1.4 + - POWERSHELL_TELEMETRY_OPTOUT=1 # timeout uploading cache after 6 minutes (360 seconds) cache: