Skip to content

Commit 5952fd6

Browse files
Copilotmazhelez
andcommitted
Merge branch 'main' into copilot/fix-datetime-parsing-bug - resolve RELEASENOTES conflict
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
1 parent ad05b6b commit 5952fd6

3 files changed

Lines changed: 110 additions & 8 deletions

File tree

Actions/AnalyzeTests/TestResultAnalyzer.ps1

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $statusSkipped = " :question:"
99
# Returns both a summary part and a failures part
1010
$mdHelperPath = Join-Path -Path $PSScriptRoot -ChildPath "..\MarkDownHelper.psm1"
1111
Import-Module $mdHelperPath
12+
Import-Module (Join-Path $PSScriptRoot '..\TelemetryHelper.psm1' -Resolve)
1213

1314
#Helper function to build a markdown table.
1415
#Headers are an array of strings with format "label;alignment" where alignment is 'left', 'right' or 'center'
@@ -132,12 +133,14 @@ function GetTestResultSummaryMD {
132133

133134
$summarySb = [System.Text.StringBuilder]::new()
134135
$failuresSb = [System.Text.StringBuilder]::new()
136+
$totalTests = 0
137+
$totalTime = 0.0
138+
$totalFailed = 0
139+
$totalSkipped = 0
140+
135141
if (Test-Path -Path $testResultsFile -PathType Leaf) {
136142
$testResults = [xml](Get-Content -path $testResultsFile -Encoding UTF8)
137-
$totalTests = 0
138-
$totalTime = 0.0
139-
$totalFailed = 0
140-
$totalSkipped = 0
143+
141144
if ($testResults.testsuites) {
142145
$appNames = @($testResults.testsuites.testsuite | ForEach-Object { $_.Properties.property | Where-Object { $_.Name -eq "appName" } | ForEach-Object { $_.Value } } | Select-Object -Unique)
143146
if (-not $appNames) {
@@ -219,6 +222,19 @@ function GetTestResultSummaryMD {
219222
else {
220223
$failuresSummaryMD = ''
221224
}
225+
226+
# Log test metrics to telemetry
227+
$totalPassed = $totalTests - $totalFailed - $totalSkipped
228+
if ($totalTests -gt 0) {
229+
$telemetryData = [System.Collections.Generic.Dictionary[[System.String], [System.String]]]::new()
230+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalTests' -Value $totalTests.ToString()
231+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalPassed' -Value $totalPassed.ToString()
232+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalFailed' -Value $totalFailed.ToString()
233+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalSkipped' -Value $totalSkipped.ToString()
234+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalTime' -Value $totalTime.ToString()
235+
Trace-Information -Message "AL-Go Test Results - Tests" -AdditionalData $telemetryData
236+
}
237+
222238
$summarySb.ToString()
223239
$failuresSb.ToString()
224240
$failuresSummaryMD
@@ -320,6 +336,10 @@ function GetBcptSummaryMD {
320336
$lastCodeunitName = ''
321337
$lastOperationName = ''
322338

339+
$totalPassed = 0
340+
$totalFailed = 0
341+
$totalSkipped = 0
342+
323343
# calculate statistics on measurements, skipping the $skipMeasurements longest measurements
324344
foreach($suiteName in $bcpt.Keys) {
325345
$suite = $bcpt."$suiteName"
@@ -418,6 +438,16 @@ function GetBcptSummaryMD {
418438
}
419439
}
420440
$mdTableRow = @($thisSuiteName, $thisCodeunitID, $thisCodeunitName, $thisOperationName, $statusStr, $durationMinStr, $baseDurationMinStr, $diffDurationMinStr, $diffDurationMinPctStr, $numberOfSQLStmtsStr, $baseNumberOfSQLStmtsStr, $diffNumberOfSQLStmtsStr, $diffNumberOfSQLStmtsPctStr)
441+
442+
# Update test counts
443+
if ($statusStr) {
444+
switch ($statusStr) {
445+
$statusOK { $totalPassed++ }
446+
$statusWarning { $totalFailed++ }
447+
$statusError { $totalFailed++ }
448+
$statusSkipped { $totalSkipped++ }
449+
}
450+
}
421451
}
422452
}
423453
$mdTableRows.Add($mdTableRow) | Out-Null
@@ -438,6 +468,17 @@ function GetBcptSummaryMD {
438468
$summarySb.AppendLine("\n<i>No baseline provided. Copy a set of BCPT results to $([System.IO.Path]::GetFileName($baseLinePath)) in the project folder in order to establish a baseline.</i>") | Out-Null
439469
}
440470

471+
# Log BCPT metrics to telemetry
472+
$totalTests = $totalPassed + $totalFailed + $totalSkipped
473+
if ($totalTests -gt 0) {
474+
$telemetryData = [System.Collections.Generic.Dictionary[[System.String], [System.String]]]::new()
475+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalTests' -Value $totalTests.ToString()
476+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalPassed' -Value $totalPassed.ToString()
477+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalFailed' -Value $totalFailed.ToString()
478+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalSkipped' -Value $totalSkipped.ToString()
479+
Trace-Information -Message "AL-Go Test Results - BCPT Tests" -AdditionalData $telemetryData
480+
}
481+
441482
$summarySb.ToString()
442483
}
443484

@@ -449,13 +490,14 @@ function GetPageScriptingTestResultSummaryMD {
449490

450491
$summarySb = [System.Text.StringBuilder]::new()
451492
$failuresSb = [System.Text.StringBuilder]::new()
493+
$totalTests = 0
494+
$totalTime = 0.0
495+
$totalFailed = 0
496+
$totalSkipped = 0
497+
$totalPassed = 0
452498

453499
if (Test-Path -Path $testResultsFile -PathType Leaf) {
454500
$testResults = [xml](Get-Content -path $testResultsFile -Encoding UTF8)
455-
$totalTests = 0
456-
$totalTime = 0.0
457-
$totalFailed = 0
458-
$totalSkipped = 0
459501

460502
$rootFailureNode = [FailureNode]::new($false)
461503
if ($testResults.testsuites) {
@@ -524,6 +566,17 @@ function GetPageScriptingTestResultSummaryMD {
524566
$failuresSummaryMD = ''
525567
}
526568

569+
# Log test metrics to telemetry
570+
if ($totalTests -gt 0) {
571+
$telemetryData = [System.Collections.Generic.Dictionary[[System.String], [System.String]]]::new()
572+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalTests' -Value $totalTests.ToString()
573+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalPassed' -Value $totalPassed.ToString()
574+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalFailed' -Value $totalFailed.ToString()
575+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalSkipped' -Value $totalSkipped.ToString()
576+
Add-TelemetryProperty -Hashtable $telemetryData -Key 'TotalTime' -Value $totalTime.ToString()
577+
Trace-Information -Message "AL-Go Test Results - Page scripting Tests" -AdditionalData $telemetryData
578+
}
579+
527580
return @{
528581
SummaryMD = $summarySb.ToString()
529582
FailuresMD = $failuresSb.ToString()

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## AL-Go Telemetry updates
2+
3+
AL-Go telemetry now includes test results so you can more easily see how many AL tests, Page Scripting tests and BCPT tests ran in your workflows across all your repositories. Documentation for this can be found on [this article](https://github.com/microsoft/AL-Go/blob/main/Scenarios/EnablingTelemetry.md) on enabling telemetry.
4+
15
### Issues
26

37
- Issue 2045 DateTime parsing fails on non-US locale runners in WorkflowPostProcess.ps1

Scenarios/EnablingTelemetry.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ traces
8686
| where message contains "AL-Go action"
8787
```
8888

89+
The following query gets all telemetry emitted for test results
90+
91+
```
92+
traces
93+
| where timestamp > ago(7d)
94+
| project timestamp,
95+
message,
96+
severityLevel,
97+
RepositoryOwner = tostring(customDimensions.RepositoryOwner),
98+
RepositoryName = tostring(customDimensions.RepositoryName),
99+
RunId = tostring(customDimensions.RunId),
100+
RunNumber = tostring(customDimensions.RunNumber),
101+
RunAttempt = tostring(customDimensions.RunAttempt),
102+
RefName = tostring(customDimensions.RefName),
103+
TotalTests = todouble(customDimensions.TotalTests),
104+
TotalFailed = todouble(customDimensions.TotalFailed),
105+
TotalSkipped = todouble(customDimensions.TotalSkipped),
106+
TotalPassed = todouble(customDimensions.TotalPassed),
107+
TotalTime = todouble(customDimensions.TotalTime)
108+
| extend HtmlUrl = strcat("https://github.com/", RepositoryName, "/actions/runs/", RunId)
109+
| where message contains "AL-Go Test Results"
110+
```
111+
89112
## Telemetry events and data
90113

91114
AL-Go logs four different types of telemetry events: AL-Go action ran/failed and AL-Go workflow ran/failed. Each of those telemetry events provide slightly different telemetry but common dimensions for all of them are:
@@ -159,6 +182,28 @@ Additional Dimensions:
159182
| RunsOn | Value of the RunsOn setting |
160183
| ALGoVersion | The AL-Go version used for the workflow run |
161184

185+
### Test results
186+
187+
Telemetry messages:
188+
189+
- `AL-Go Test Results - Tests`
190+
- `AL-Go Test Results - Page scripting Tests`
191+
- `AL-Go Test Results - BCPT Tests`
192+
193+
SeverityLevel: 1
194+
195+
Additional Dimensions:
196+
197+
| Dimension | Description |
198+
|-----------|-------------|
199+
| TotalTests | The total number of tests executed |
200+
| TotalFailed | The number of tests that failed |
201+
| TotalSkipped | The number of tests that were skipped |
202+
| TotalPassed | The number of tests that passed |
203+
| TotalTime | The total time taken to execute all tests |
204+
205+
**Note:** The `TotalTime` dimension is not tracked for BCPT test results. For BCPT tests, only `TotalTests`, `TotalPassed`, `TotalFailed`, and `TotalSkipped` are available.
206+
162207
______________________________________________________________________
163208

164209
[back](../README.md)

0 commit comments

Comments
 (0)