Skip to content

Optimize PowerShell script and restructure README - #8

Merged
marcelloformica merged 2 commits into
mainfrom
dev
Mar 24, 2026
Merged

marcelloformica merged 2 commits into
mainfrom
dev

Conversation

@marcelloformica

Copy link
Copy Markdown
Contributor

Summary

Performance optimizations for the PowerShell script and a full README restructure to eliminate redundancies.

PowerShell script changes

Performance

  • Compiled MetricProcessor via Add-Type (C#): the ~44K-datapoint-per-resource JSON processing loop runs at native .NET speed instead of interpreted PowerShell
  • Compiled GapProcessor via Add-Type (C#): ExpandToTickSet and ClassifyGaps replace interpreted loops for gap investigation
  • Shared HttpClient with connection pooling for per-resource metrics and gap investigation (replaces per-call Invoke-WebRequest TCP/TLS overhead)
  • HashSet-based O(1) interval containment for suspect-minute classification
  • TryGetProperty hash lookup instead of EnumerateObject linear scan

Bug fixes

  • Per-resource ARM metric URL now includes metricnamespace parameter (fixes SQL databases showing 0 0 N/A)
  • Case-insensitive metric name comparisons in compiled C# (matching PowerShell -eq behavior)
  • Idempotent Add-Type guards: two independently guarded blocks so the script can be re-run within the same PowerShell session

Code quality

  • Added/improved comments on complex code blocks (classification logic, interval merging, gap counting, result assembly)
  • Updated section headers for consistency

README changes

Restructured from 7 scattered sections into 3 clean sections:

  1. Introduction — what it does, two implementations, key questions
  2. Usage — prerequisites, parameters, examples, output
  3. How it works — inventory, metrics, gap investigation, result assembly, worked example, implementation notes

Removed redundancies:

  • Suspect = Faults + Excused + Unresolved invariant (was stated 3 times)
  • Health History retention (mentioned 4+ times)
  • 90-day lookback constraint (intro, parameters, architecture notes)
  • Storage zero-tx handling (Step 2, Step 4, separate subsection, architecture notes)
  • Customer-initiated detection fields, conservative-on-failure, batch API details, Native AOT, pipeline output (each duplicated)

… comments

Performance:
- Compiled MetricProcessor via Add-Type (C#): ~44K-datapoint JSON loop
  runs at native .NET speed instead of interpreted PowerShell
- Compiled GapProcessor via Add-Type (C#): ExpandToTickSet and ClassifyGaps
  replace interpreted loops for gap investigation
- Shared HttpClient with connection pooling for per-resource metrics and
  gap investigation (replaces Invoke-WebRequest per-call overhead)
- HashSet-based O(1) interval containment for suspect-minute classification
- TryGetProperty hash lookup instead of EnumerateObject linear scan

Bug fixes:
- Per-resource ARM metric URL now includes metricnamespace parameter
  (fixes SQL databases showing 0 0 N/A)
- Case-insensitive metric name comparisons in compiled C# (matching
  PowerShell -eq behavior)
- Idempotent Add-Type guards: two independently guarded blocks so script
  can be re-run in the same session without 'type already exists' errors

Code quality:
- Added/improved comments on complex code blocks (classification logic,
  interval merging, gap counting, Step 7 assembly)
- Updated section headers for consistency
- README: added architecture notes for compiled GapProcessor, idempotent
  Add-Type guards, HttpClient coverage for gap investigation
Reorganized from 7 scattered sections into 3 clean sections:
  1. Introduction (what it does, two implementations, key questions)
  2. Usage (prerequisites, parameters, examples, output)
  3. How it works (inventory, metrics, gap investigation, result assembly,
     worked example, implementation notes)

Removed redundancies:
- Suspect=Faults+Excused+Unresolved invariant (was stated 3 times)
- Health History retention (was mentioned 4+ times)
- 90-day lookback constraint (intro, parameters, architecture notes)
- Storage zero-tx handling (Step 2, Step 4, separate subsection, arch notes)
- Customer-initiated detection fields (Step 3 + architecture notes)
- Conservative-on-failure (Step 3 + architecture notes)
- Batch API details (Step 2 + architecture notes)
- Native AOT, pipeline output (each mentioned twice)

Merged 'How it works' steps and 'Architecture notes' into a single
coherent technical section. Consolidated Parameters, Prerequisites,
Usage, and Output under a single 'Usage' heading. Trimmed duplicate
C#/PowerShell examples to representative subset.
@marcelloformica
marcelloformica merged commit 9230464 into main Mar 24, 2026
1 check passed
@marcelloformica
marcelloformica deleted the dev branch March 24, 2026 10:03
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.

1 participant