Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: child modules telemetry check #4370

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
375a183
add child modules
ReneHezser Feb 3, 2025
54ce808
- initial child modules don't need to bump the parent
ReneHezser Feb 3, 2025
40fe96d
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 3, 2025
9590175
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 4, 2025
aa67fb6
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 6, 2025
5dcf3f5
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 7, 2025
0949f88
Update utilities/pipelines/staticValidation/compliance/module.tests.ps1
ReneHezser Feb 7, 2025
257510b
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 10, 2025
83272f8
simplify and cleanup
ReneHezser Feb 12, 2025
d26bfe1
cleanup
ReneHezser Feb 12, 2025
9e19743
cleanup
ReneHezser Feb 12, 2025
dae48f6
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 12, 2025
473ee35
generate an error instead of a warning
ReneHezser Feb 13, 2025
a5d1d17
changed logic to use variable
ReneHezser Feb 13, 2025
ab04d15
telemetry tests adjusted for published modules and not only toplevel
ReneHezser Feb 13, 2025
541a50f
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 14, 2025
5b801d0
updates
ReneHezser Feb 14, 2025
fe1e40b
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 14, 2025
34f6232
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 17, 2025
7881784
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 17, 2025
b3f1806
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 17, 2025
1db3d87
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 19, 2025
4cc2725
Merge branch 'Azure:main' into child-modules-telemetry-check
ReneHezser Feb 20, 2025
562ee04
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 21, 2025
1307c58
updated res modules to pass test
ReneHezser Feb 21, 2025
1183e87
fixed web site
ReneHezser Feb 21, 2025
e21913b
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 21, 2025
61fd032
Update utilities/pipelines/staticValidation/compliance/module.tests.ps1
ReneHezser Feb 22, 2025
8aba717
cleanup
ReneHezser Feb 22, 2025
d35f9c4
Merge branch 'main' into child-modules-telemetry-check
ReneHezser Feb 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to run the static validation step only on the whole library before merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. No red pipeline is a result of this PR. I've updated all res modules to fulfill the new spec.

Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Describe 'File/folder tests' -Tag 'Modules' {
}

# if the child modules version has been increased, the main modules version should be increased as well
It '[<moduleFolderName>] main module version should be increased if the child version number has been increased.' -TestCases ($moduleFolderTestCases | Where-Object { (-Not $_.isTopLevelModule) }) {
It '[<moduleFolderName>] main module version should be increased if the child version number has been increased.' -TestCases ($moduleFolderTestCases | Where-Object { -Not $_.isTopLevelModule }) {

param (
[string] $moduleFolderPath
Expand All @@ -128,7 +128,8 @@ Describe 'File/folder tests' -Tag 'Modules' {
$parentFolderPath = Split-Path -Path $moduleFolderPath -Parent
$moduleVersion = Get-ModuleTargetVersion -ModuleFolderPath $parentFolderPath

($childModuleVersion.EndsWith('.0') -and -not $moduleVersion.EndsWith('.0')) | Should -Be $false
# the first release of a child module does not require the parent module to be updated
($childModuleVersion -ne '0.1.0' -and $childModuleVersion.EndsWith('.0') -and -not $moduleVersion.EndsWith('.0')) | Should -Be $false
}
}

Expand Down Expand Up @@ -487,6 +488,7 @@ Describe 'Module tests' -Tag 'Module' {
readMeFilePath = Join-Path (Split-Path $templateFilePath) 'README.md'
isTopLevelModule = ($resourceTypeIdentifier -split '[\/|\\]').Count -eq 2
moduleType = $moduleType
versionFileExists = Test-Path (Join-Path -Path $moduleFolderPath 'version.json')
}
}
}
Expand Down Expand Up @@ -866,8 +868,10 @@ Describe 'Module tests' -Tag 'Module' {
}

Context 'Resources' {
# If any resources in the module are deployed, a telemetry deployment should be carried out as well
It '[<moduleFolderName>] Telemetry deployment should be present in the template.' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule -and $_.templateFileContent.resources.count -gt 0 }) {
# If any resources in the module are deployed, a telemetry deployment should be carried out as well. Ignore e.g. utility modules
It '[<moduleFolderName>] Telemetry deployment should be present in the template.' -TestCases ($moduleFolderTestCases | Where-Object {
$_.versionFileExists -and $_.templateFileContent.resources.count -gt 0
}) {

param(
[hashtable] $templateFileContent
Expand All @@ -884,7 +888,7 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeployment | Should -Not -BeNullOrEmpty -Because 'A telemetry resource with name prefix [46d3xbcp] should be present in the template'
}

It '[<moduleFolderName>] Telemetry deployment should have correct condition in the template.' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) {
It '[<moduleFolderName>] Telemetry deployment should have correct condition in the template.' -TestCases ($moduleFolderTestCases | Where-Object { $_.versionFileExists }) {

param(
[hashtable] $templateFileContent
Expand All @@ -907,7 +911,7 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeployment.condition | Should -Be "[parameters('enableTelemetry')]"
}

It '[<moduleFolderName>] Telemetry deployment should have expected inner output for verbosity.' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) {
It '[<moduleFolderName>] Telemetry deployment should have expected inner output for verbosity.' -TestCases ($moduleFolderTestCases | Where-Object { $_.versionFileExists }) {

param(
[hashtable] $templateFileContent
Expand All @@ -931,7 +935,7 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeployment.properties.template.outputs['telemetry'].value | Should -Be 'For more information, see https://aka.ms/avm/TelemetryInfo'
}

It '[<moduleFolderName>] Telemetry deployment should have expected telemetry identifier.' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) {
It '[<moduleFolderName>] Telemetry deployment should have expected telemetry identifier.' -TestCases ($moduleFolderTestCases | Where-Object { $_.versionFileExists }) {

param(
[string] $templateFilePath,
Expand Down Expand Up @@ -992,6 +996,58 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeploymentName = $telemetryDeployment.name # The AVM telemetry prefix
$telemetryDeploymentName | Should -Match "$expectedTelemetryIdentifier"
}

It '[<moduleFolderName>] Variable "enableReferencedModulesTelemetry" should exist and set to "false" if module references other modules with dedicated telemetry.' -TestCases $moduleFolderTestCases {

param(
[hashtable] $templateFileContent
)

# get all referenced modules, that offer a telemetry parameter
$referencesWithTelemetry = $templateFileContent.resources.Values | Where-Object {
$_.type -eq 'Microsoft.Resources/deployments' -and
$_.properties.template.parameters.Keys -contains 'enableTelemetry'
}

if ($referencesWithTelemetry.Count -eq 0) {
Set-ItResult -Skipped -Because 'no modules with dedicated telemetry are deployed.'
return
}

$templateFileContent.variables.Keys | Should -Contain 'enableReferencedModulesTelemetry'
$templateFileContent.variables.enableReferencedModulesTelemetry | Should -Be $false
}

It '[<moduleFolderName>] Telemetry should be disabled for referenced modules with dedicated telemetry.' -TestCases $moduleFolderTestCases {

param(
[hashtable] $templateFileContent,
[string] $templateFilePath
)

# get all referenced modules, that offer a telemetry parameter
$referencesWithTelemetry = $templateFileContent.resources.Values | Where-Object {
$_.type -eq 'Microsoft.Resources/deployments' -and
$_.properties.template.parameters.Keys -contains 'enableTelemetry'
}

if ($referencesWithTelemetry.Count -eq 0) {
Set-ItResult -Skipped -Because 'no modules with dedicated telemetry are deployed.'
return
}

# telemetry should be disabled for the referenced module
$incorrectCrossReferences = [System.Collections.ArrayList]@()
foreach ($referencedModule in $referencesWithTelemetry) {
if ($referencedModule.properties.parameters.Keys -notcontains 'enableTelemetry' -or
$referencedModule.properties.parameters.enableTelemetry.value -ne "[variables('enableReferencedModulesTelemetry')]") {
# remember the names (e.g. 'virtualNetwork_subnets') to provide a better error message
$incorrectCrossReferences.Add($referencedModule.identifier)
}
}

$incorrectCrossReferences | Should -BeNullOrEmpty -Because ('cross reference modules must be referenced with the enableTelemetry parameter set to the "enableReferencedModulesTelemetry" variable. Found incorrect items: [{0}].' -f ($incorrectCrossReferences -join ', '))
}
}

Context 'Output' {
Expand Down