Skip to content

Commit 027e4cc

Browse files
committed
combine validate & perf test (so we don't get fast but broked)
1 parent bc2b135 commit 027e4cc

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

Diff for: PerfAndValidate-Checks.ps1

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
## To Test performance - I pull the dbatools docker repo and cd to the samples/stackoverflow Directory
2+
3+
## I changed the ports because I have some of them already running SQL
4+
5+
## line 17 - "7401:1433"
6+
## line 34 - "7402:1433"
7+
## line 52 - "7403:1433"
8+
9+
#then docker compose up -d
10+
11+
# cd to the root of dbachecks and checkout the pesterv5 branch
12+
13+
ipmo ./dbachecks.psd1
14+
15+
#
16+
17+
#$Checks = 'XpCmdShellDisabled','WhoIsActiveInstalled','CLREnabled','TraceFlagsNotExpected','TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
18+
$Checks = 'AsymmetricKeySize'
19+
20+
<#
21+
When there are default skips (some of the CIS checks) we need to set the configs and check
22+
23+
Set-DbcConfig skip.security.sadisabled -Value $false
24+
Set-DbcConfig skip.security.sadisabled -Value $true
25+
Get-DbcConfigValue skip.security.sadisabled
26+
27+
Set-DbcConfig skip.security.saexist -Value $false
28+
Set-DbcConfig skip.security.saexist -Value $true
29+
Get-DbcConfigValue skip.security.saexist
30+
31+
32+
Get-DbcConfigValue policy.instancemaxdop.userecommended
33+
Get-DbcConfigValue policy.instancemaxdop.maxdop
34+
Get-DbcConfigValue policy.instancemaxdop.excludeinstance
35+
36+
Set-DbcConfig policy.instancemaxdop.userecommended -Value $false
37+
Set-DbcConfig policy.instancemaxdop.userecommended -Value $true
38+
Set-DbcConfig policy.instancemaxdop.maxdop -Value 0
39+
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value $null
40+
Set-DbcConfig policy.instancemaxdop.excludeinstance -Value 'localhost,7401'
41+
42+
Get-DbcConfigValue policy.traceflags.expected
43+
Get-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred
44+
Set-DbcConfig policy.traceflags.expected -Value 1117,1118
45+
Set-DbcConfig policy.traceflags.expected -Value $null
46+
47+
Enable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
48+
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1117,1118
49+
Disable-DbaTraceFlag -SqlInstance $Sqlinstances -SqlCredential $cred -TraceFlag 1118
50+
51+
#>
52+
53+
# Load the function below and then you can keep running the checks defined above in v4 and v5 and compare the performance
54+
# You can keep updating the .Tests.ps1 files and rerunning the function without needing to re-import hte module
55+
56+
# If you change any of the functions you WILL need to re-import or better still use a new session
57+
58+
# If you get odd results - or you dont get any checks run
59+
60+
# run the import module and the Invoke Dbc Check with Verbose and that might show you New-Json messing
61+
# with your files or that you are looking in PSMOdulePath instead of Git Repo path (run Reset-dbcConfig to fix that)
62+
63+
function Invoke-PerfAndValidateChecks {
64+
param($Checks)
65+
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
66+
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
67+
$Sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'
68+
69+
$originalCode = {
70+
$global:v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -Check $Checks -SqlCredential $cred -legacy $true -Show None -PassThru
71+
}
72+
73+
$NewCode = {
74+
$global:v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -Check $Checks -SqlCredential $cred -legacy $false -Show None -PassThru
75+
}
76+
77+
$originalCodetrace = Trace-Script -ScriptBlock $originalCode
78+
$NewCodetrace = Trace-Script -ScriptBlock $NewCode
79+
80+
$originalCodeMessage = "With original Code it takes {0} MilliSeconds" -f $originalCodetrace.StopwatchDuration.TotalMilliseconds
81+
82+
83+
$savingMessage = "
84+
Running with
85+
86+
{3}
87+
88+
Checks against $($Sqlinstances.Count) SQL Containers
89+
90+
With original Code it takes {1} Seconds
91+
With New Code it takes {4} Seconds
92+
93+
New Code for these {5} checks
94+
is saving {0} seconds
95+
from a run of {1} seconds
96+
New Code runs in {2} % of the time
97+
" -f ('{0:N2}' -f ($originalCodetrace.StopwatchDuration.TotalSeconds - $NewCodetrace.StopwatchDuration.TotalSeconds)),('{0:N2}' -f $originalCodetrace.StopwatchDuration.TotalSeconds),('{0:N2}' -f (($NewCodetrace.StopwatchDuration.TotalSeconds/$originalCodetrace.StopwatchDuration.TotalSeconds) * 100)),($Checks -split ',' -join ',') ,('{0:N2}' -f $NewCodetrace.StopwatchDuration.TotalSeconds), $Checks.Count
98+
99+
Write-PSFMessage -Message $savingMessage -Level Output
100+
101+
102+
##validate we got the right answers too
103+
104+
If (Compare-Object $v5code.Configuration.Filter.Tag.Value $v4code.TagFilter) {
105+
$Message = "
106+
Uh-Oh - The Tag filters between v4 and v5 are not the same somehow.
107+
For v4 We returned
108+
{0}
109+
and
110+
For v5 we returned
111+
{1}
112+
" -f ($v4code.TagFilter | Out-String), ($v5code.Configuration.Filter.Tag.Value | Out-String)
113+
Write-PSFMessage -Message $Message -Level Warning
114+
}
115+
else {
116+
$message = "
117+
The Tags are the same"
118+
Write-PSFMessage -Message $Message -Level Output
119+
}
120+
121+
If (($v5code.TotalCount - $v5code.NotRunCount) -ne $v4code.TotalCount) {
122+
$Message = "
123+
Uh-Oh - The total tests run between v4 and v5 are not the same somehow.
124+
For v4 We ran
125+
{0} tests
126+
and
127+
For v5 we ran
128+
{1} tests
129+
The MOST COMMON REASON IS you have used Tags instead of Tag in your Describe block
130+
but TraceFlagsNotExpected will change that also
131+
" -f $v4code.TotalCount, ($v5code.TotalCount - $v5code.NotRunCount)
132+
Write-PSFMessage -Message $Message -Level Warning
133+
}
134+
else {
135+
$message = "
136+
The Total Tests Run are the same {0} {1} " -f $v4code.TotalCount, ($v5code.TotalCount - $v5code.NotRunCount)
137+
Write-PSFMessage -Message $Message -Level Output
138+
}
139+
140+
If ($v5code.PassedCount -ne $v4code.PassedCount) {
141+
$Message = "
142+
Uh-Oh - The total tests Passed between v4 and v5 are not the same somehow.
143+
For v4 We Passed
144+
{0} tests
145+
and
146+
For v5 we Passed
147+
{1} tests
148+
" -f $v4code.PassedCount, $v5code.PassedCount
149+
Write-PSFMessage -Message $Message -Level Warning
150+
}
151+
else {
152+
$message = "
153+
The Total Tests Passed are the same {0} {1} " -f $v4code.PassedCount, $v5code.PassedCount
154+
Write-PSFMessage -Message $Message -Level Output
155+
}
156+
157+
158+
If ($v5code.FailedCount -ne $v4code.FailedCount) {
159+
$Message = "
160+
Uh-Oh - The total tests Failed between v4 and v5 are not the same somehow.
161+
For v4 We Failed
162+
{0} tests
163+
and
164+
For v5 we Failed
165+
{1} tests
166+
" -f $v4code.FailedCount, $v5code.FailedCount
167+
Write-PSFMessage -Message $Message -Level Warning
168+
}
169+
else {
170+
$message = "
171+
The Total Tests Failed are the same {0} {1} " -f $v4code.FailedCount, $v5code.FailedCount
172+
Write-PSFMessage -Message $Message -Level Output
173+
}
174+
175+
If ($v5code.SkippedCount -ne $v4code.SkippedCount) {
176+
$Message = "
177+
Uh-Oh - The total tests Skipped between v4 and v5 are not the same somehow.
178+
For v4 We Skipped
179+
{0} tests
180+
and
181+
For v5 we Skipped
182+
{1} tests
183+
" -f $v4code.SkippedCount, $v5code.SkippedCount
184+
Write-PSFMessage -Message $Message -Level Warning
185+
}
186+
else {
187+
$message = "
188+
The Total Tests Skipped are the same {0} {1} "-f $v4code.SkippedCount, $v5code.SkippedCount
189+
Write-PSFMessage -Message $Message -Level Output
190+
}
191+
192+
193+
}
194+
195+
196+
# $Checks = 'DbaOperator'
197+
Invoke-PerfAndValidateChecks -Checks 'VirtualLogFile'

0 commit comments

Comments
 (0)