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

Users/rok/telemtry in m123 for older version #6823

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,55 @@ param (
[String]$psOnRemoteScriptBlockString = "Invoke-PsOnRemote -MachineDnsName $fqdn -ScriptPath `$scriptPath -WinRMPort $port -Credential `$credential -ScriptArguments `$scriptArguments -InitializationScriptPath `$initializationScriptPath -SessionVariables `$parsedSessionVariables $skipCACheckOption $httpProtocolOption $enableDetailedLoggingOption"
[scriptblock]$psOnRemoteScriptBlock = [scriptblock]::Create($psOnRemoteScriptBlockString)
$deploymentResponse = Invoke-Command -ScriptBlock $psOnRemoteScriptBlock


# Telemetry data logic through ps session
Copy link
Contributor

Choose a reason for hiding this comment

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

run all our BVT Test before merge

try{
if($skipCACheckOption)
{
$sessionOption = New-PSSessionOption -SkipCACheck
}
else
{
$sessionOption = New-PSSessionOption
}
$secpasswd = ConvertTo-SecureString $credential.Password -AsPlainText -Force
$psCredential = New-Object System.Management.Automation.PSCredential($credential.UserName, $secpasswd)
if($httpProtocolOption -eq '-UseHttp')
{
$session = New-PSSession -Computer $fqdn -Port $port -Credential $psCredential -SessionOption ($sessionOption )
}
else
{
$session = New-PSSession -Computer $fqdn -Port $port -Credential $psCredential -SessionOption ($sessionOption ) -UseSSL
}
$VmUuidHash = Invoke-Command -Session $session -ScriptBlock {
$sha = New-Object System.Security.Cryptography.SHA512CryptoServiceProvider
$computerDetails = Get-WmiObject -class Win32_ComputerSystemProduct -namespace root\CIMV2
$encoding = [system.Text.Encoding]::ASCII
$uuidHash = [System.BitConverter]::ToString( $sha.ComputeHash($encoding.GetBytes($computerDetails.UUID)))
$uuidHash = $uuidHash -replace "-" , ""
return $uuidHash
}
$isAzureVm = Invoke-Command -Session $session -ScriptBlock {
(Get-Process -Name 'WindowsAzureGuestAgent' -ErrorAction Ignore) | Select-Object -First 1 | ForEach-Object {
if($_.Path)
{
return $true
}
else
{
return $false
}
}
}
$deploymentResponse | Add-Member "IsAzureVm" $IsAzureVm -Force
$deploymentResponse | Add-Member "VmUuidHash" $VmUuidHash -Force
}
catch
{
Write-Verbose "Error during fetching telemetry = $_"
$deploymentResponse | Add-Member "TelemetryError" $_ -Force
}

Write-Output $deploymentResponse
}
60 changes: 60 additions & 0 deletions Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ $ErrorActionPreference = 'Stop'
$deploymentOperation = 'Deployment'

Copy link
Contributor

Choose a reason for hiding this comment

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

please remove all instances of this from this file

Write-Telemetry "DTLSDK_Error" $deploymentResponse.DeploymentSummary"

Copy link
Member

Choose a reason for hiding this comment

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

Refer #6889

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. @asranja Please review it.

$envOperationStatus = "Passed"
$jobId = $env:SYSTEM_JOBID;

# enabling detailed logging only when system.debug is true
$enableDetailedLoggingString = $env:system_debug
Expand All @@ -64,7 +65,63 @@ if ($enableDetailedLoggingString -ne "true")

# Telemetry
Import-Module $PSScriptRoot\ps_modules\TelemetryHelper
# Import all the dlls and modules which have cmdlets we need
Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal.psm1"
Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.dll"

function Write-DTLServiceDeprecationMessageIfRequired
{
param([string]$machine)

try
{
$jsonValue = ConvertFrom-Json $environmentName -ErrorAction Stop;
$validJson = $true;
}
catch
{
$validJson = $false;
}

if(!$validJson)
{
if(-not($machine.Contains('.')) -and -not($machine.Contains(':')) -and -not($machine.Contains(",")))
{
write-error "Deployments using 'test hub: machine groups' is no longer supported. Refer to https://go.microsoft.com/fwlink/?LinkID=799742&clcid=0x409 for more information or get help from Developer Community [https://developercommunity.visualstudio.com/spaces/21/index.html]."
}
}
}

function Publish-AzureTelemetry
{
param([object] $deploymentResponse,
[string] $jobId )
if($deploymentResponse){
$jsonString = -join("{")
if([bool]($deploymentResponse.PSobject.Properties.name -match "IsAzureVm")){
$jsonString = -join( $jsonString,
"`"IsAzureVm`" : `"$($deploymentResponse.IsAzureVm)`"" ,
",")
}
if([bool]($deploymentResponse.PSobject.Properties.name -match "VmUuidHash")){
$jsonString = -join( $jsonString,
"`"VmUuidHash`" : `"$($deploymentResponse.VmUuidHash)`"",
",")
}
if([bool]($deploymentResponse.PSobject.Properties.name -match "TelemetryError")){
$jsonString = -join( $jsonString,
"`"TelemetryError`" : `"$($deploymentResponse.TelemetryError)`"",
",")
}

$jsonString = -join( $jsonString,
"`"JobId`" : `"$jobId`"" , "}")
}

$telemetryString ="##vso[telemetry.publish area=TaskHub;feature=PowerShellOnTargetMachines]$jsonString"
Write-Host $telemetryString
}

try
{
$connection = Get-VssConnection -TaskContext $distributedTaskContext
Expand Down Expand Up @@ -105,6 +162,7 @@ if($runPowershellInParallel -eq "false" -or ( $resources.Count -eq 1 ) )
$status = $deploymentResponse.Status

Write-Output (Get-LocalizedString -Key "Deployment status for machine '{0}' : '{1}'" -ArgumentList $displayName, $status)
Publish-AzureTelemetry -deploymentResponse $deploymentResponse -jobId $jobId

if ($status -ne "Passed")
{
Expand Down Expand Up @@ -145,6 +203,8 @@ else

Write-ResponseLogs -operationName $deploymentOperation -fqdn $displayName -deploymentResponse $output
Write-Output (Get-LocalizedString -Key "Deployment status for machine '{0}' : '{1}'" -ArgumentList $displayName, $status)
Publish-AzureTelemetry -deploymentResponse $output -jobId $jobId

if($status -ne "Passed")
{
$envOperationStatus = "Failed"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellOnTargetMachines/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 47
"Patch": 51
},
"minimumAgentVersion": "1.104.0",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PowerShellOnTargetMachines/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 47
"Patch": 51
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why from version 47 to 51 ?
Because we have done hotfix for version 1 from chaitanya branch not through m123. In chaitanya branch last version for PS on target machine is 50 and window file copy is 42.

},
"minimumAgentVersion": "1.104.0",
"groups": [
Expand Down