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

Added telemetries #7474

Merged
merged 8 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@

[Parameter(ParameterSetName = "ApplicationParameterFilePath")]
[Parameter(ParameterSetName = "ApplicationName")]
[Switch]$CompressPackage
[Switch]$CompressPackage,

[Parameter(ParameterSetName = "ApplicationParameterFilePath")]
[Parameter(ParameterSetName = "ApplicationName")]
[ref]$status
Copy link
Contributor

Choose a reason for hiding this comment

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

$status is good candidate global variable - then you won't need to pass along.

Copy link
Author

Choose a reason for hiding this comment

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

Lets us PassByReference as its more controlled and always safer then to use Global variable

Copy link
Author

Choose a reason for hiding this comment

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

Passing an extra optional parameter (with reference) still seems fine to me as there is no extra memory usage

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case there does not seem to be usual problems related to global variables. Before execution a command will set status and that will always be the truth - we don't have multi-threading or parallelization in our flow.
I am in favor of global as code will be cleaner without need to pass $status everywhere.

Copy link
Author

Choose a reason for hiding this comment

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

Using global variable now.

)


Expand Down Expand Up @@ -142,6 +146,7 @@

if (!$SkipPackageValidation)
{
$status.value = "NewApp-TestingApplicationPackage"
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove redundant Test-. Keep it only in deploy.ps1

Copy link
Author

Choose a reason for hiding this comment

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

Will raise a separate PR for the same

Copy link
Contributor

Choose a reason for hiding this comment

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

Please file an issue for that - otherwise we will miss it.

Copy link
Author

Choose a reason for hiding this comment

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

if (!$packageValidationSuccess)
{
Expand Down Expand Up @@ -217,6 +222,7 @@

try
{
$status.value = "NewApp-RemovingApplication"
$app | Remove-ServiceFabricApplication -Force
}
catch [System.TimeoutException]
Expand All @@ -230,6 +236,7 @@
# It will unregister the existing application's type and version even if its different from the application being created,
if ((Get-ServiceFabricApplication | Where-Object {$_.ApplicationTypeVersion -eq $($app.ApplicationTypeVersion) -and $_.ApplicationTypeName -eq $($app.ApplicationTypeName)}).Count -eq 0)
{
$status.value = "NewApp-UnregisteringApplicationType"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than settings similar status multiple places, you can move it to separate method and call it from both New/upgrade file. I don't think adding "NewApp-" or "UpgradeApp-" prefix is necessary.

Copy link
Author

@kuvinodms kuvinodms Jun 15, 2018

Choose a reason for hiding this comment

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

Adding these prefixes will give us clear idea about the code flow without any need to look in other trace to decide whether code is in Create flow or Upgrade flow.
Lets keep it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to know whether it is upgrade or new when lets say registering the package? This information seems to be redundant.
On the positive side we will be able to move code to common functions and re-use them.

Copy link
Author

Choose a reason for hiding this comment

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

Removing it in the hope that we don't need to know whether code failed in CreateApp or UpgradeApp.

Unregister-ServiceFabricApplicationType -ApplicationTypeName $($app.ApplicationTypeName) -ApplicationTypeVersion $($app.ApplicationTypeVersion) -Force -TimeoutSec $UnregisterPackageTimeoutSec
}
}
Expand All @@ -250,13 +257,14 @@
}
if (!$typeIsInUse)
{
$status.value = "NewApp-UnregisteringRegisteredApplicationType"
Write-Host (Get-VstsLocString -Key SFSDK_UnregisteringExistingAppType -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
$reg | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
$ApplicationTypeAlreadyRegistered = $false
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_UnableToUnregisterAppType)
}
$ApplicationTypeAlreadyRegistered = $false
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Author

Choose a reason for hiding this comment

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

Its a bug since !$? check for last command ran successfully or not and $ApplicationTypeAlreadyRegistered = $false is not the one for which we're checking for

}
else
{
Expand Down Expand Up @@ -302,7 +310,7 @@
Write-Warning (Get-VstsLocString -Key SFSDK_CompressPackageWarning $InstalledSdkVersion)
}
}

$status.value = "NewApp-CopyingApplicationPackage"
Copy-ServiceFabricApplicationPackage @copyParameters
if (!$?)
{
Expand All @@ -319,12 +327,13 @@
}

Write-Host (Get-VstsLocString -Key SFSDK_RegisterAppType)
$status.value = "NewApp-RegisteringApplicationType"
Register-ServiceFabricApplicationType @registerParameters
if (!$?)
{
throw (Get-VstsLocString -Key SFSDK_RegisterAppTypeFailed)
}

$status.value = "NewApp-RemovingApplicationPackage"
Write-Host (Get-VstsLocString -Key SFSDK_RemoveAppPackage)
Remove-ServiceFabricApplicationPackage -ApplicationPackagePathInImageStore $applicationPackagePathInImageStore -ImageStoreConnectionString $imageStoreConnectionString
}
Expand All @@ -347,7 +356,7 @@
$ApplicationParameter = Merge-Hashtables -HashTableOld $appParamsFromFile -HashTableNew $ApplicationParameter
}
}

$status.value = "NewApp-CreatingNewApplication"
New-ServiceFabricApplication -ApplicationName $ApplicationName -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion -ApplicationParameter $ApplicationParameter
if (!$?)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ function Publish-UpgradedServiceFabricApplication

[Parameter(ParameterSetName = "ApplicationParameterFilePath")]
[Parameter(ParameterSetName = "ApplicationName")]
[Switch]$SkipUpgradeSameTypeAndVersion
[Switch]$SkipUpgradeSameTypeAndVersion,

[Parameter(ParameterSetName = "ApplicationParameterFilePath")]
[Parameter(ParameterSetName = "ApplicationName")]
[ref]$status
)

if (!(Test-Path -LiteralPath $ApplicationPackagePath))
Expand Down Expand Up @@ -191,6 +195,7 @@ function Publish-UpgradedServiceFabricApplication

if (!$SkipPackageValidation)
{
$status.value = "UpgradeApp-TestingApplicationPackage"
$packageValidationSuccess = (Test-ServiceFabricApplicationPackage $AppPkgPathToUse -ImageStoreConnectionString $imageStoreConnectionString)
if (!$packageValidationSuccess)
{
Expand Down Expand Up @@ -235,6 +240,7 @@ function Publish-UpgradedServiceFabricApplication
if (!$typeIsInUse)
{
Write-Host (Get-VstsLocString -Key SFSDK_UnregisteringExistingAppType -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
$status.value = "UpgradeApp-UnregisteringRegisteredApplicationType"
$reg | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
$ApplicationTypeAlreadyRegistered = $false
}
Expand Down Expand Up @@ -281,6 +287,7 @@ function Publish-UpgradedServiceFabricApplication
}
}

$status.value = "UpgradeApp-CopyingApplicationPackage"
Copy-ServiceFabricApplicationPackage @copyParameters
if (!$?)
{
Expand All @@ -296,6 +303,7 @@ function Publish-UpgradedServiceFabricApplication
$registerParameters['TimeOutSec'] = $RegisterPackageTimeoutSec
}

$status.value = "UpgradeApp-RegisteringApplicationType"
Write-Host (Get-VstsLocString -Key SFSDK_RegisterAppType)
Register-ServiceFabricApplicationType @registerParameters
if (!$?)
Expand Down Expand Up @@ -335,16 +343,17 @@ function Publish-UpgradedServiceFabricApplication
}

Write-Host (Get-VstsLocString -Key SFSDK_StartAppUpgrade)
$status.value = "UpgradeApp-StartingApplicationUpgrade"
Start-ServiceFabricApplicationUpgrade @UpgradeParameters
}
catch
{
Write-Host (Get-VstsLocString -Key SFSDK_StartUpgradeFailed -ArgumentList $_.Exception.Message)

try
{
if (!$ApplicationTypeAlreadyRegistered)
{
$status.value = "UpgradeApp-UnregisteringApplicationType"
Write-Host (Get-VstsLocString -Key SFSDK_UnregisterAppTypeOnUpgradeFailure -ArgumentList @($names.ApplicationTypeName, $names.ApplicationTypeVersion))
Unregister-ServiceFabricApplicationType -ApplicationTypeName $names.ApplicationTypeName -ApplicationTypeVersion $names.ApplicationTypeVersion -Force -TimeoutSec $UnregisterPackageTimeoutSec
}
Expand Down Expand Up @@ -380,6 +389,7 @@ function Publish-UpgradedServiceFabricApplication
{
try
{
$status.value = "UpgradeApp-UnregisteringUnusedApplicationType"
$registeredAppTypes | Unregister-ServiceFabricApplicationType -Force -TimeoutSec $UnregisterPackageTimeoutSec
}
catch [System.Fabric.FabricException]
Expand Down
10 changes: 9 additions & 1 deletion Tasks/ServiceFabricDeployV1/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ try {
}
}

$status = "ConnectingToCluster"
# Connect to cluster
Connect-ServiceFabricClusterFromServiceEndpoint -ClusterConnectionParameters $clusterConnectionParameters -ConnectedServiceEndpoint $connectedServiceEndpoint

Expand Down Expand Up @@ -107,6 +108,7 @@ try {

if (!$skipValidation)
{
$status = "TestingApplicationPackage"
$isPackageValid = Test-ServiceFabricApplicationPackage -ApplicationPackagePath $applicationPackagePath
}

Expand Down Expand Up @@ -176,16 +178,22 @@ try {
$publishParameters['UpgradeParameters'] = $upgradeParameters
$publishParameters['UnregisterUnusedVersions'] = $unregisterUnusedVersions
$publishParameters['SkipUpgradeSameTypeAndVersion'] = $skipUpgrade
$publishParameters['Status'] = [ref]$status

Publish-UpgradedServiceFabricApplication @publishParameters
}
else
{
$publishParameters['Action'] = "RegisterAndCreate"
$publishParameters['OverwriteBehavior'] = Get-VstsInput -Name overwriteBehavior
$publishParameters['Status'] = [ref]$status

Publish-NewServiceFabricApplication @publishParameters
}
} finally {
}
catch {
Write-Telemetry "Task_InternalError" "TaskStatus: $status | Exception: $_.Exception.GetType().FullName"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove words "TaskStatus:" and "Exception:". We can use convention to have status and exception type separated by | without any space.

Copy link
Author

Choose a reason for hiding this comment

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

Used it for readability. If you don't see any use then lets remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is redundant. As we will never need to see full string. We will always query this data via kusto and it is easier to write query without these extra characters

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to re-throw?

Copy link
Author

Choose a reason for hiding this comment

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

Yes we need to re throw

finally {
Trace-VstsLeavingInvocation $MyInvocation
}