From 5706f31ef381ad2d2b0a0867c5fa2db4d7c815ee Mon Sep 17 00:00:00 2001 From: SQLDbaWithABeard Date: Wed, 27 Apr 2022 14:46:42 +0100 Subject: [PATCH] MaxDopInstance added and tested #882 --- Perf Testing pesterv5.ps1 | 17 +++++++++++-- Validate v4 adn v5.ps1 | 16 +++++++++++-- checks/Instancev5.Tests.ps1 | 18 +++++++++++--- internal/functions/NewGet-AllInstanceInfo.ps1 | 24 +++++++++++++++---- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Perf Testing pesterv5.ps1 b/Perf Testing pesterv5.ps1 index c7324169..51bd97b6 100644 --- a/Perf Testing pesterv5.ps1 +++ b/Perf Testing pesterv5.ps1 @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1 # -$Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'ErrorLogCount' +$Checks = 'MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' +$Checks = 'MaxDopInstance' Compare-CheckRuns -Checks $checks <# @@ -28,7 +28,20 @@ Get-DbcConfigValue skip.security.sadisabled Set-DbcConfig skip.security.saexist -Value $false Set-DbcConfig skip.security.saexist -Value $true Get-DbcConfigValue skip.security.saexist + + +Get-DbcConfigValue policy.instancemaxdop.userecommended +Get-DbcConfigValue policy.instancemaxdop.maxdop +Get-DbcConfigValue policy.instancemaxdop.excludeinstance + +Set-DbcConfig policy.instancemaxdop.userecommended -Value $false +Set-DbcConfig policy.instancemaxdop.userecommended -Value $true +Set-DbcConfig policy.instancemaxdop.maxdop -Value 0 +Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null +Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7401' + #> + # Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance # You can keep updating the .Tests.ps1 files and rerunning the function without needing to re-import hte module diff --git a/Validate v4 adn v5.ps1 b/Validate v4 adn v5.ps1 index 83f995ec..8890170c 100644 --- a/Validate v4 adn v5.ps1 +++ b/Validate v4 adn v5.ps1 @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1 # -$Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'ErrorLogCount' +$Checks = 'MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' +$Checks = 'MaxDopInstance' Compare-v4andv5Results -Checks $Checks <# @@ -28,6 +28,18 @@ Get-DbcConfigValue skip.security.sadisabled Set-DbcConfig skip.security.saexist -Value $false Set-DbcConfig skip.security.saexist -Value $true Get-DbcConfigValue skip.security.saexist + + +Get-DbcConfigValue policy.instancemaxdop.userecommended +Get-DbcConfigValue policy.instancemaxdop.maxdop +Get-DbcConfigValue policy.instancemaxdop.excludeinstance + +Set-DbcConfig policy.instancemaxdop.userecommended -Value $false +Set-DbcConfig policy.instancemaxdop.userecommended -Value $true +Set-DbcConfig policy.instancemaxdop.maxdop -Value 0 +Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null +Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7402' + #> # Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance diff --git a/checks/Instancev5.Tests.ps1 b/checks/Instancev5.Tests.ps1 index 49f6d49c..a2fe9365 100644 --- a/checks/Instancev5.Tests.ps1 +++ b/checks/Instancev5.Tests.ps1 @@ -189,10 +189,22 @@ Describe "Model Database Growth" -Tag ModelDbGrowth, Low, Instance -ForEach $Ins Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $InstancesToTest { $skip = Get-DbcConfigValue skip.instance.ErrorLogCount Context "Checking error log count on <_.Name>" { - It "Error log count should be greater or equal to <_.ConfigValues.errorLogCount> on <_.Name>" -Skip:$skip{ - $psitem.NumberOfLogFiles | Should -BeGreaterOrEqual $psitem.ConfigValues.errorLogCount -Because "We expect to have at least $($psitem.ConfigValues.errorLogCount) number of error log files" + It "Error log count should be greater or equal to <_.ConfigValues.errorLogCount> on <_.Name>" -Skip:$skip { + $psitem.NumberOfLogFiles | Should -BeGreaterOrEqual $psitem.ConfigValues.errorLogCount -Because "We expect to have at least $($psitem.ConfigValues.errorLogCount) number of error log files" } } } - +Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) { + $skip = Get-DbcConfigValue skip.instance.MaxDopInstance + Context "Testing Instance MaxDop Value on <_.Name>" { + #if UseRecommended - check that the CurrentInstanceMaxDop property returned from Test-DbaMaxDop matches the the RecommendedMaxDop property + It "Instance Level MaxDop setting should be correct on <_.Name>" -Skip:$Skip -ForEach ($Psitem | Where-Object { $psitem.ConfigValues.UseRecommendedMaxDop -eq $true }) { + $psitem.MaxDopSettings.CurrentInstanceMaxDop | Should -Be $psitem.MaxDopSettings.RecommendedMaxDop -Because "We expect the MaxDop Setting to be the default recommended value $($psitem.MaxDopSettings.RecommendedMaxDop)" + } + #if not UseRecommended - check that the CurrentInstanceMaxDop property returned from Test-DbaMaxDop matches the MaxDopValue parameter + It "Instance Level MaxDop setting should be correct on <_.Name>" -Skip:$Skip -ForEach($Psitem | Where-Object { $psitem.ConfigValues.UseRecommendedMaxDop -ne $true }) { + $psitem.MaxDopSettings.CurrentInstanceMaxDop | Should -Be $psitem.ConfigValues.InstanceMaxDop -Because "We expect the MaxDop Setting to be the value you specified $($psitem.ConfigValues.InstanceMaxDop)" + } + } +} diff --git a/internal/functions/NewGet-AllInstanceInfo.ps1 b/internal/functions/NewGet-AllInstanceInfo.ps1 index 809dac82..a4f882c9 100644 --- a/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -13,7 +13,8 @@ function NewGet-AllInstanceInfo { $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.LogFile], $false) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.DataFile], $false) - + # set the default init fields for all the tags + # Server Initial fields $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) $ServerInitFields.Add("VersionMajor") | Out-Null # so we can check versions @@ -117,7 +118,7 @@ function NewGet-AllInstanceInfo { } 'ErrorlogCount' { - $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) + $ServerInitFields.Add("NumberOfLogFiles") | Out-Null # so we can check versions $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server], $ServerInitFields) $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) # I think we need to re-initialise here @@ -125,12 +126,26 @@ function NewGet-AllInstanceInfo { $ConfigValues | Add-Member -MemberType NoteProperty -Name 'errorLogCount' -Value (Get-DbcConfigValue policy.errorlog.logcount) } + 'MaxDopInstance' { + #Test-DbaMaxDop needs these because it checks every database as well + $DatabaseInitFields.Add("IsAccessible") | Out-Null # so we can check if its accessible + $DatabaseInitFields.Add("IsSystemObject ") | Out-Null # so we can check if its accessible + $DatabaseInitFields.Add("MaxDop ") | Out-Null # so we can check if its accessible + $DatabaseInitFields.Add("Name ") | Out-Null # so we can check if its accessible + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], $DatabaseInitFields) + $DatabaseInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database]) # I think we need to re-initialise here + + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'UseRecommendedMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.userecommended) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'InstanceMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.maxdop) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'ExcludeInstanceMaxDop' -Value (Get-DbcConfigValue policy.instancemaxdop.excludeinstance) + if ($Instance.Name -notin $ConfigValues.ExcludeInstanceMaxDop) { + $MaxDopSettings = (Test-DbaMaxDop -SqlInstance $Instance)[0] # because we dont care about the database maxdops here - potentially we could store it and use it for DatabaseMaxDop ? + } + } Default { } } - # set the default init fields for all the tags - #build the object $testInstanceObject = [PSCustomObject]@{ @@ -144,6 +159,7 @@ function NewGet-AllInstanceInfo { Logins = $Instance.Logins Databases = $Instance.Databases NumberOfLogFiles = $Instance.NumberOfLogFiles + MaxDopSettings = $MaxDopSettings } if ($ScanForStartupProceduresDisabled) { $StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{ $_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true }.count