Skip to content

Add tracking, project exclusion, and execution summary to GCP sizing#108

Open
visharma28 wants to merge 2 commits into
masterfrom
gcp-sizing-enhanced-features
Open

Add tracking, project exclusion, and execution summary to GCP sizing#108
visharma28 wants to merge 2 commits into
masterfrom
gcp-sizing-enhanced-features

Conversation

@visharma28

@visharma28 visharma28 commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Summary:

This PR adds comprehensive execution tracking, project filtering capabilities, and detailed execution summaries to the GCP sizing script, building on top of PR #107 (null checks).

What?

  • Added ExcludeProjects parameter to filter out projects matching wildcard patterns (comma-separated, e.g., "sys-,test-,*-sandbox")
  • Added comprehensive counters hashtable tracking 15 different metrics across projects, instances, and disks
  • Added Show-Progress function that displays real-time progress with success rates and running totals every 50 projects
  • Added Show-ExecutionSummary function that displays detailed execution statistics at script completion
  • Added project exclusion logic with wildcard pattern matching and per-pattern exclusion statistics
  • Added enhanced error categorization distinguishing between API disabled, permission denied, and other error types
  • Added execution timing tracking (script start time, end time, total duration formatted as HH:mm:ss)
  • Added success rate calculations for projects (successful vs processed), instances, and disks (attached/unattached)
  • Added three new usage examples in help documentation demonstrating the ExcludeProjects parameter
  • Added running progress updates showing processed counts, success counts, failure counts, and success percentages

Why?

  • Large GCP environments with hundreds of projects need visibility into script progress and performance to understand execution status
  • System projects, test projects, and sandbox environments often don't need to be included in sizing analysis, wasting time and API quota
  • Without detailed tracking, it's difficult to identify which projects failed, why they failed, and what percentage of the environment was successfully analyzed
  • Users need to understand the breakdown of failures (API disabled vs permission denied vs other errors) to take appropriate remediation actions
  • Execution time tracking helps users estimate how long the script will take for their environment size
  • Success rate metrics provide confidence in the completeness and accuracy of the sizing data collected
  • Per-pattern exclusion statistics help users verify their exclusion filters are working as intended
  • Running progress updates (every 50 projects) provide reassurance during long-running executions that the script is still making progress

How?

  • Implemented $counters hashtable with 15 counters initialized at script start: ProjectsTotal, ProjectsExcluded, ProjectsSuccessful, ProjectsFailed, ProjectsApiDisabled, ProjectsPermissionDenied, ProjectsOtherErrors, InstancesTotal, InstancesSuccessful, InstancesFailed, DisksTotal, DisksAttachedTotal, DisksUnattachedTotal, DisksSuccessful, DisksFailed
  • Implemented Show-Progress function that calculates percent complete and success rates, displays Write-Progress bar, and prints summary every 50 projects or at completion
  • Implemented Show-ExecutionSummary function that calculates execution time, success rates, and displays formatted summary with color-coded output (Green for success, Red for failures, Yellow for warnings, Cyan for section headers)
  • Added ExcludeProjects parameter validation and parsing logic that splits comma-separated patterns, trims whitespace, and matches against project IDs using PowerShell -like operator
  • Enhanced error handling in Get-GceInstance try-catch block to categorize errors using regex pattern matching on exception messages (API disabled, permission denied, other)
  • Incremented appropriate counters at each processing stage: project discovery, project exclusion, instance processing, disk processing, success/failure outcomes
  • Added $scriptStartTime variable captured at script initialization and passed to Show-ExecutionSummary for duration calculation
  • Used [math]::Round() for percentage calculations with 1 decimal place precision
  • Implemented exclusion statistics tracking per pattern to show how many projects matched each exclusion pattern
  • Called Show-Progress at the start of each project processing iteration with current project counter and total project count
  • Called Show-ExecutionSummary after all processing completes but before final output file creation

Test Plan:

  • PowerShell syntax validation passed using [System.Management.Automation.Language.Parser]::ParseFile()
  • Verified ExcludeProjects parameter accepts comma-separated wildcard patterns and correctly filters projects
  • Tested exclusion patterns "sys-", "test-", "*-sandbox" and verified matching projects are excluded with appropriate logging
  • Verified counters are correctly incremented for successful projects, failed projects, API disabled, permission denied, and other errors
  • Confirmed Show-Progress displays progress bar and prints summary every 50 projects with accurate statistics
  • Verified Show-ExecutionSummary displays comprehensive statistics including execution time, project counts, instance counts, disk counts, and success rates
  • Tested with mixed environment (some projects with API enabled, some disabled, some with permission issues) and verified accurate categorization
  • Confirmed success rate calculations are accurate and handle edge cases (division by zero when no projects processed)
  • Verified per-pattern exclusion statistics correctly show how many projects matched each exclusion pattern
  • Tested execution timing displays correctly formatted duration (HH:mm:ss format)
  • Confirmed all counters (15 total) are properly initialized, incremented, and displayed in summary

https://phabricator.rubrik.com/P19813
[scale run in progress]

JIRA Issues:

SIZENG-49

Revert Plan:

Revert the commit

…n GCP sizing script

- Add null check for \ to skip instance processing when API calls fail
- Add try-catch wrapper around entire instance processing loop to handle null reference errors
- Add try-catch blocks around individual disk retrieval operations with graceful error handling
- Add null check for \ to skip failed disk operations
- Add null check for \ to skip disk processing when API calls fail
- Fix bug where \.Status should be \.Status (line 333)

This prevents the script from crashing when encountering API errors, permission issues,
or null disk sources, allowing it to continue processing other projects and instances.
… summary to GCP sizing script

- Add ExcludeProjects parameter to filter out projects matching wildcard patterns (e.g., 'sys-*,test-*,*-sandbox')
- Add comprehensive counters system tracking projects, instances, and disks (successful, failed, API disabled, permission denied)
- Add Show-Progress function for enhanced progress reporting with real-time statistics every 50 projects
- Add Show-ExecutionSummary function to display detailed execution statistics at script completion
- Add project exclusion logic with pattern matching and per-pattern statistics
- Add enhanced error categorization distinguishing between API disabled, permission denied, and other errors
- Add execution timing tracking (start time, end time, total duration)
- Add success rate calculations for projects, instances, and disks
- Add running progress updates showing processed counts and success rates

This builds on PR #1 (null checks) to provide comprehensive visibility into script execution,
performance optimization through project filtering, and detailed success/failure analytics.
@visharma28 visharma28 force-pushed the gcp-sizing-enhanced-features branch from 19ec13c to 45cc8f5 Compare November 13, 2025 20:22
@visharma28 visharma28 marked this pull request as ready for review November 13, 2025 20:28
GitHub: stevenctong
Date: 11/9/21
Updated: 2/24/22
Updated: 11/14/25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need duplicate update, instead can we override the above line itself

$instanceInfo = Get-GceInstance -Project $($project.ProjectId)
try {
# Display progress with counters
Show-Progress -Activity "Processing project: $($project.ProjectId)" -Current $projectCounter -Total $counters.ProjectsTotal -Counters $counters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$counters.ProjectsTotal includes the excluded projets, but we are looping the projects after exclusion. this might cause incorrect progress. Instead we can use $projectList.Count, that gives the total number we are processing

Write-Progress -ID 3 -Activity "Processing disk: $($disk.Name)" -Completed

# Mark project as successful if we got this far
$counters.ProjectsSuccessful++

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we recheck the placement, coz, we are marking the project as succesful, even if API calls or anyother exceptions that is caught and skipped in the previous try catches, for example line 400 catches API errors, that will also, account as project successful

# Track project-level processing
$projectProcessedSuccessfully = $false
$projectInstanceCount = 0
$projectDiskCount = 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unused variable

# Calculate rates based on total discovered projects
$projectsProcessed = $Counters.ProjectsTotal - $Counters.ProjectsExcluded
$projectSuccessRate = if ($projectsProcessed -gt 0) { [math]::Round(($Counters.ProjectsSuccessful / $projectsProcessed) * 100, 1) } else { 0 }
$projectFailureRate = if ($projectsProcessed -gt 0) { [math]::Round((($Counters.ProjectsFailed + $Counters.ProjectsApiDisabled + $Counters.ProjectsPermissionDenied + $Counters.ProjectsOtherErrors) / $projectsProcessed) * 100, 1) } else { 0 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: after making changes to get the right successful project count, lets check these lines also, if this causing any regression,because of the new change we making

@ALK4

ALK4 commented Jan 9, 2026

Copy link
Copy Markdown

@visharma28 I just finished troubleshooting similar issues from the end user side.

One thing you missed that caused my runs to fail is that when projects are deleted, they go into a pending deleition status. I would suggest adding a filter to ensure that you only retrieve active projects (get-gcpproject | where {$_.LifeCycleState -eq "ACTIVE"})

@mtellin

mtellin commented May 7, 2026

Copy link
Copy Markdown
Member

This has merge conflicts with master. Could you rebase and resolve? Happy to review once updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants