Skip to content

Commit

Permalink
session bug + remove telemetry from low level functions (#3509)
Browse files Browse the repository at this point in the history
Session caching didn't really work in the latest preview
+ telemetry in the low level functions can be measured in perf.

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk committed Apr 25, 2024
1 parent de974c8 commit 83f0b87
Show file tree
Hide file tree
Showing 25 changed files with 25 additions and 265 deletions.
2 changes: 2 additions & 0 deletions AppHandling/Publish-NavContainerApp.ps1
Expand Up @@ -310,6 +310,7 @@ try {
}
else {
[ScriptBlock] $scriptblock = { Param($appFile, $skipVerification, $sync, $install, $upgrade, $tenant, $syncMode, $packageType, $scope, $language, $PublisherAzureActiveDirectoryTenantId, $force, $ignoreIfAppExists)
$prevPreference = $ProgressPreference; $ProgressPreference = "SilentlyContinue"
$publishArgs = @{ "packageType" = $packageType }
if ($scope) {
$publishArgs += @{ "Scope" = $scope }
Expand Down Expand Up @@ -394,6 +395,7 @@ try {
Start-NavAppDataUpgrade -ServerInstance $ServerInstance -Publisher $appPublisher -Name $appName -Version $appVersion -Tenant $tenant @installArgs
}
}
$ProgressPreference = $prevPreference
}
if ($isCloudBcContainer) {
$containerPath = Join-Path 'C:\DL' ([System.IO.Path]::GetFileName($appfile))
Expand Down
11 changes: 0 additions & 11 deletions Common/Download-File.ps1
Expand Up @@ -30,9 +30,6 @@ function Download-File {
[int] $timeout = 100
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$replaceUrls = @{
"https://go.microsoft.com/fwlink/?LinkID=844461" = "https://bcartifacts.azureedge.net/prerequisites/DotNetCore.1.0.4_1.1.1-WindowsHosting.exe"
"https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi" = "https://bcartifacts.azureedge.net/prerequisites/rewrite_2.0_rtw_x64.msi"
Expand Down Expand Up @@ -99,12 +96,4 @@ try {
}
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Download-File
2 changes: 1 addition & 1 deletion ContainerHandling/Get-NavContainerSession.ps1
Expand Up @@ -30,7 +30,7 @@ function Get-BcContainerSession {
$session = $sessions[$containerName]
try {
$platformVersion = Invoke-Command -Session $session -ScriptBlock { [System.Version](get-item 'C:\Program Files\Microsoft Dynamics NAV\*\Service\Microsoft.Dynamics.Nav.Server.exe').Versioninfo.FileVersion }
if ($platformVersion -ge 24 -and ($usePwsh -xor $session.ConfigurationName -eq 'PowerShell.7')) {
if ($platformVersion.Major -ge 24 -and ($usePwsh -xor $session.ConfigurationName -eq 'PowerShell.7')) {
# Cannot use existing session
Remove-PSSession -Session $session
$sessions.Remove($containerName)
Expand Down
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerArtifactUrl.ps1
Expand Up @@ -16,9 +16,6 @@ function Get-BcContainerArtifactUrl {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$inspect = docker inspect $containerName | ConvertFrom-Json
$artifactUrlEnv = $inspect.config.Env | Where-Object { $_ -like "artifactUrl=*" }
if ($artifactUrlEnv) {
Expand All @@ -28,13 +25,5 @@ try {
return ""
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerArtifactUrl -Value Get-BcContainerArtifactUrl
Export-ModuleMember -Function Get-BcContainerArtifactUrl -Alias Get-NavContainerArtifactUrl
12 changes: 0 additions & 12 deletions ContainerInfo/Get-NavContainerCountry.ps1
Expand Up @@ -17,23 +17,11 @@ function Get-BcContainerCountry {
[string] $containerOrImageName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.country)"

}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerCountry -Value Get-BcContainerCountry
Export-ModuleMember -Function Get-BcContainerCountry -Alias Get-NavContainerCountry
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerDebugInfo.ps1
Expand Up @@ -45,9 +45,6 @@ function Get-BcContainerDebugInfo {
[switch] $CopyToClipboard
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$debugInfo = @{}
$inspect = docker inspect $containerName | ConvertFrom-Json

Expand Down Expand Up @@ -107,13 +104,5 @@ try {

return $debugInfoJson
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerDebugInfo -Value Get-BcContainerDebugInfo
Export-ModuleMember -Function Get-BcContainerDebugInfo -Alias Get-NavContainerDebugInfo
10 changes: 0 additions & 10 deletions ContainerInfo/Get-NavContainerEula.ps1
Expand Up @@ -18,21 +18,11 @@ function Get-BcContainerEula {
[string] $containerOrImageName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.Eula)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerEula -Value Get-BcContainerEula
Export-ModuleMember -Function Get-BcContainerEula -Alias Get-NavContainerEula
10 changes: 0 additions & 10 deletions ContainerInfo/Get-NavContainerEventLog.ps1
Expand Up @@ -23,8 +23,6 @@ function Get-BcContainerEventLog {
[switch] $doNotOpen
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Write-Host "Getting event log for $containername"

$eventLogFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "EventLogs"
Expand All @@ -46,13 +44,5 @@ try {
Start-Process -FilePath $eventLogName | Out-Null
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerEventLog -Value Get-BcContainerEventLog
Export-ModuleMember -Function Get-BcContainerEventLog -Alias Get-NavContainerEventLog
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerGenericTag.ps1
Expand Up @@ -17,22 +17,11 @@ function Get-BcContainerGenericTag {
[string] $containerOrImageName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('tag').Count -eq 0) {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.tag)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerGenericTag -Value Get-BcContainerGenericTag
Export-ModuleMember -Function Get-BcContainerGenericTag -Alias Get-NavContainerGenericTag
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerId.ps1
Expand Up @@ -15,9 +15,6 @@ function Get-BcContainerId {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$id = ""
docker ps --format "{{.ID}}:{{.Names}}" -a --no-trunc | ForEach-Object {
$ps = $_.split(':')
Expand All @@ -36,13 +33,5 @@ try {
}
$id
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerId -Value Get-BcContainerId
Export-ModuleMember -Function Get-BcContainerId -Alias Get-NavContainerId
12 changes: 0 additions & 12 deletions ContainerInfo/Get-NavContainerImageLabels.ps1
Expand Up @@ -17,9 +17,6 @@ function Get-BcContainerImageLabels {
[PSCredential] $registryCredential
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient

Expand Down Expand Up @@ -72,15 +69,6 @@ try {
}
catch {
}

}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageLabels -Value Get-BcContainerImageLabels
Export-ModuleMember -Function Get-BcContainerImageLabels -Alias Get-NavContainerImageLabels
10 changes: 0 additions & 10 deletions ContainerInfo/Get-NavContainerImageName.ps1
Expand Up @@ -16,18 +16,8 @@ function Get-BcContainerImageName {
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerName | ConvertFrom-Json
return "$($inspect.Config.Image)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageName -Value Get-BcContainerImageName
Export-ModuleMember -Function Get-BcContainerImageName -Alias Get-NavContainerImageName
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerImageTags.ps1
Expand Up @@ -19,9 +19,6 @@ function Get-BcContainerImageTags {
[int] $pageSize = -1
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient

Expand Down Expand Up @@ -77,13 +74,5 @@ try {
catch {
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerImageTags -Value Get-BcContainerImageTags
Export-ModuleMember -Function Get-BcContainerImageTags -Alias Get-NavContainerImageTags
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerIpAddress.ps1
Expand Up @@ -18,9 +18,6 @@ function Get-BcContainerIpAddress {
[string] $networkName = ""
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$ip = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock {
$ip = ""
$ips = Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne "127.0.0.1" }
Expand All @@ -47,13 +44,5 @@ try {
}
return $ip
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerIpAddress -Value Get-BcContainerIpAddress
Export-ModuleMember -Function Get-BcContainerIpAddress -Alias Get-NavContainerIpAddress
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerLegal.ps1
Expand Up @@ -18,22 +18,11 @@ function Get-BcContainerLegal {
[string] $containerOrImageName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.legal)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerLegal -Value Get-BcContainerLegal
Export-ModuleMember -Function Get-BcContainerLegal -Alias Get-NavContainerLegal
10 changes: 0 additions & 10 deletions ContainerInfo/Get-NavContainerLicenseInformation.ps1
Expand Up @@ -13,19 +13,9 @@ Function Get-BcContainerLicenseInformation {
[String] $ContainerName = $bcContainerHelperConfig.defaultContainerName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock {
Get-NavServerInstance | Export-NAVServerLicenseInformation
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerLicenseInformation -Value Get-BcContainerLicenseInformation
Export-ModuleMember -Function Get-BcContainerLicenseInformation -Alias Get-NavContainerLicenseInformation
11 changes: 0 additions & 11 deletions ContainerInfo/Get-NavContainerName.ps1
Expand Up @@ -15,18 +15,7 @@ function Get-BcContainerName {
[string] $containerId
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

docker ps --format='{{.Names}}' -a --filter "id=$containerId"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerName -Value Get-BcContainerName
Export-ModuleMember -Function Get-BcContainerName -Alias Get-NavContainerName
10 changes: 0 additions & 10 deletions ContainerInfo/Get-NavContainerNavVersion.ps1
Expand Up @@ -17,21 +17,11 @@ function Get-BcContainerNavVersion {
[string] $containerOrImageName
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$inspect = docker inspect $containerOrImageName | ConvertFrom-Json
if ($inspect.Config.Labels.psobject.Properties.Match('maintainer').Count -eq 0 -or $inspect.Config.Labels.maintainer -ne "Dynamics SMB") {
throw "Container $containerOrImageName is not a NAV/BC container"
}
return "$($inspect.Config.Labels.version)-$($inspect.Config.Labels.country)"
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Set-Alias -Name Get-NavContainerNavVersion -Value Get-BcContainerNavVersion
Export-ModuleMember -Function Get-BcContainerNavVersion -Alias Get-NavContainerNavVersion

0 comments on commit 83f0b87

Please sign in to comment.