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
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function Get-ReferenceObject {
$involvedFilePaths = Get-LocallyReferencedFileList -FilePath $ModuleTemplateFilePath -TemplateMap $TemplateMap

$resultSet = @{
resourceReferences = @()
remoteReferences = @()
localPathReferences = $involvedFilePaths | Where-Object {
resourceReferences = @()
remoteReferences = @()
localPathReferences = $involvedFilePaths | Where-Object {
$involvedFilePath = $_
# We only care about module templates
(Split-Path $involvedFilePath -Leaf) -eq 'main.bicep' -and
Expand All @@ -86,6 +86,13 @@ function Get-ReferenceObject {
(Split-Path $involvedFilePath) -match ('{0}[\/|\\].+' -f [Regex]::Escape((Split-Path $_ -Parent))) # i.e., if a path has its parent in the list, kick it out
}).count -eq 0
}
childModuleReferences = $involvedFilePaths | Where-Object {
$involvedFilePath = $_
# We only care about module templates
(Split-Path $involvedFilePath -Leaf) -eq 'main.bicep' -and
# only return child modules
(Test-Path -Path (Join-Path (Split-Path $involvedFilePath) 'version.json') -PathType Leaf)
}
}

foreach ($involvedFilePath in (@($ModuleTemplateFilePath) + @($involvedFilePaths))) {
Expand All @@ -96,9 +103,10 @@ function Get-ReferenceObject {
}

return @{
resourceReferences = $resultSet.resourceReferences | Sort-Object -Culture 'en-US' -Unique
remoteReferences = $resultSet.remoteReferences | Sort-Object -Culture 'en-US' -Unique
localPathReferences = $resultSet.localPathReferences | Sort-Object -Culture 'en-US' -Unique
resourceReferences = $resultSet.resourceReferences | Sort-Object -Culture 'en-US' -Unique
remoteReferences = $resultSet.remoteReferences | Sort-Object -Culture 'en-US' -Unique
localPathReferences = $resultSet.localPathReferences | Sort-Object -Culture 'en-US' -Unique
childModuleReferences = $resultSet.childModuleReferences | Sort-Object -Culture 'en-US' -Unique
}
}
#endregion
Expand Down
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 @@ -481,6 +482,7 @@ Describe 'Module tests' -Tag 'Module' {
# Test file setup
$moduleFolderTestCases += @{
moduleFolderName = $resourceTypeIdentifier
moduleFolderPath = Split-Path $templateFilePath
templateFileContent = $templateFileContent
templateFilePath = $templateFilePath
templateFileParameters = Resolve-ReadMeParameterList -TemplateFileContent $templateFileContent
Expand All @@ -491,6 +493,13 @@ Describe 'Module tests' -Tag 'Module' {
}
}

BeforeAll {
# Load function
. (Join-Path $repoRootPath 'utilities' 'pipelines' 'sharedScripts' 'helper' 'Get-CrossReferencedModuleList.ps1')
# load cross-references
$crossReferencedModuleList = Get-CrossReferencedModuleList
}

Context 'General' {

It '[<moduleFolderName>] The template file should not be empty.' -TestCases $moduleFolderTestCases {
Expand Down Expand Up @@ -992,6 +1001,52 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeploymentName = $telemetryDeployment.name # The AVM telemetry prefix
$telemetryDeploymentName | Should -Match "$expectedTelemetryIdentifier"
}

It '[<moduleFolderName>] Telemetry should be disabled for child modules.' -TestCases ($moduleFolderTestCases | Where-Object { $_.isTopLevelModule }) {

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

$crossReferencedModuleList = Get-CrossReferencedModuleList -Path $moduleFolderPath
$modulesWithChildReferences = $crossReferencedModuleList.Values | Where-Object {
$_.ContainsKey('childModuleReferences') -and $_['childModuleReferences'].Count -gt 0
}
if ($modulesWithChildReferences.Count -eq 0) {
Set-ItResult -Skipped -Because 'no child modules found'
return
}

$modulesWithChildReferences | ForEach-Object {
$_['childModuleReferences'] | ForEach-Object {
# 'avm/res|ptn|utl/<provider>/<resourceType>/<childResourceType>' would return 'avm', 'res|ptn|utl', '<provider>/<resourceType>/<childResourceType>'
$null, $childModuleType, $childResourceTypeIdentifier = ((Split-Path $_) -split '[\/|\\]avm[\/|\\](res|ptn|utl)[\/|\\]')
$childModuleName = (Split-Path $childResourceTypeIdentifier -Leaf)
Write-Verbose "Checking telemetry for child module [$childModuleName]" -Verbose
# find the child modules reference in the parent module
$moduleBicep = Get-Content -Path $templateFilePath
$regexPattern = "module\s+(\S+)\s+'$childModuleName/main.bicep'\s+="
$moduleName = ''
foreach ($line in $moduleBicep) {
if ($line -match $regexPattern) {
$moduleName = $matches[1]
break
}
}
# with the module name, get the resource and its properties
$childModuleParameters = $templateFileContent.resources.$moduleName.properties.parameters
$containsTelemetryParameter = $childModuleParameters.ContainsKey('enableTelemetry')
$containsTelemetryParameter | Should -Be $true -Because "the child module [$childModuleName] should be referenced with a telemetry parameter."

if ($containsTelemetryParameter) {
$isTelemetryDisabled = $childModuleParameters.enableTelemetry.value -eq $false
$isTelemetryDisabled | Should -Be $true -Because "the child module [$childModuleName] should have telemetry disabled."
}
}
}

}
}

Context 'Output' {
Expand Down