Skip to content

Commit

Permalink
TraceFlagsExpected add and tested #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 28, 2022
1 parent dfea078 commit d24918a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
13 changes: 11 additions & 2 deletions Perf Testing pesterv5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1

#

$Checks = 'TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'TwoDigitYearCutoff'
$Checks = 'TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'TraceFlagsExpected'
Compare-CheckRuns -Checks $checks

<#
Expand All @@ -40,6 +40,15 @@ Set-DbcConfig policy.instancemaxdop.maxdop -Value 0
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7401'
Get-DbcConfigValue policy.traceflags.expected
Get-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred
Set-DbcConfig policy.traceflags.expected -Value 1117,1118
Set-DbcConfig policy.traceflags.expected -Value $null
Enable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1118
#>

# Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance
Expand Down
13 changes: 11 additions & 2 deletions Validate v4 adn v5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1

#

$Checks = 'TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'TwoDigitYearCutoff'
$Checks = 'TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'TraceFlagsExpected'
Compare-v4andv5Results -Checks $Checks

<#
Expand All @@ -40,6 +40,15 @@ Set-DbcConfig policy.instancemaxdop.maxdop -Value 0
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7402'
Get-DbcConfigValue policy.traceflags.expected
Get-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred
Set-DbcConfig policy.traceflags.expected -Value 1117,1118
Set-DbcConfig policy.traceflags.expected -Value $null
Enable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1118
#>

# Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance
Expand Down
15 changes: 14 additions & 1 deletion checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,21 @@ Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEac
Describe "Two Digit Year Cutoff" -Tag TwoDigitYearCutoff, Low, Instance -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.instance.TwoDigitYearCutoff
Context "Testing Two Digit Year Cutoff on <_.Name>" {
It "Two Digit Year Cutoff is set to <_.ConfigValues.TwoDigitYearCutoff> on <_.Name>" -Skip:$skip {
It "Two Digit Year Cutoff is set to <_.ConfigValues.TwoDigitYearCutoff> on <_.Name>" -Skip:$skip {
$PSItem.Configuration.TwoDigitYearCutoff.ConfigValue | Should -Be $psitem.ConfigValues.TwoDigitYearCutoff -Because 'This is the value that you have chosen for Two Digit Year Cutoff configuration'
}
}
}

Describe "Trace Flags Expected" -Tag TraceFlagsExpected, TraceFlag, High, Instance -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.instance.TraceFlagsExpected
Context "Testing Expected Trace Flags on <_.Name>" {
It "Expected No Trace Flags to exist on <_.Name>" -Skip:$skip -ForEach ($Psitem | Where-Object { $null -eq $psitem.ConfigValues.TraceFlagsExpected }) {
$PsItem.ExpectedTraceFlags.ActualTraceFlags.TraceFlag | Should -BeNullOrEmpty -Because "We expect that there will be no Trace Flags set on $($Psitem.Name) "
}
It "Expected Trace Flags <_.ExpectedTraceFlag> to exist on <_.InstanceName>" -Skip:$skip -ForEach ($PsItem.ExpectedTraceFlags | Where-Object { $psitem.ExpectedTraceFlag -ne 'null' }) {
$PsItem.ActualTraceFlags.TraceFlag | Should -Contain $PsItem.ExpectedTraceFlag -Because "We expect that Trace Flag $($PsItem.ExpectedTraceFlag) will be set on $($Psitem.InstanceName) "
}
}
}

41 changes: 29 additions & 12 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,41 @@ function NewGet-AllInstanceInfo {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TwoDigitYearCutoff' -Value (Get-DbcConfigValue policy.twodigityearcutoff)

}

'TraceFlagsExpected' {
$TraceFlagsExpected = Get-DbcConfigValue policy.traceflags.expected
$TraceFlagsActual = $Instance.EnumActiveGlobalTraceFlags()
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TraceFlagsExpected' -Value $TraceFlagsExpected
$ExpectedTraceFlags = $TraceFlagsExpected.Foreach{
[PSCustomObject]@{
InstanceName = $Instance.Name
ExpectedTraceFlag = $PSItem
ActualTraceFlags = $TraceFlagsActual
}
}
$ExpectedTraceFlags += [PSCustomObject]@{
InstanceName = $Instance.Name
ExpectedTraceFlag = 'null'
ActualTraceFlags = $TraceFlagsActual
}
}
Default { }
}

#build the object

$testInstanceObject = [PSCustomObject]@{
ComputerName = $Instance.ComputerName
InstanceName = $Instance.DbaInstanceName
Name = $Instance.Name
ConfigValues = $ConfigValues
VersionMajor = $Instance.VersionMajor
Configuration = if ($configurations) { $Instance.Configuration } else { $null }
Settings = $Instance.Settings
Logins = $Instance.Logins
Databases = $Instance.Databases
NumberOfLogFiles = $Instance.NumberOfLogFiles
MaxDopSettings = $MaxDopSettings
ComputerName = $Instance.ComputerName
InstanceName = $Instance.DbaInstanceName
Name = $Instance.Name
ConfigValues = $ConfigValues
VersionMajor = $Instance.VersionMajor
Configuration = if ($configurations) { $Instance.Configuration } else { $null }
Settings = $Instance.Settings
Logins = $Instance.Logins
Databases = $Instance.Databases
NumberOfLogFiles = $Instance.NumberOfLogFiles
MaxDopSettings = $MaxDopSettings
ExpectedTraceFlags = $ExpectedTraceFlags
}
if ($ScanForStartupProceduresDisabled) {
$StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{ $_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true }.count
Expand Down

0 comments on commit d24918a

Please sign in to comment.