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

fixed issue "Remove-FinOpsHub fails when there's only one resource" #983

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

jamelachahbar
Copy link
Contributor

@jamelachahbar jamelachahbar commented Sep 14, 2024

🛠️ Description

Get-HubIdentifier.ps1:

I optimized the logic to directly extract a valid 13-character alphanumeric string and improve efficiency. The current method generates substrings unnecessarily (tested it with Verbose Output), slowing down performance and producing irrelevant results.
Regex Matching: Uses a regular expression to directly extract 13-character alphanumeric strings, removing the need for substring generation.
Excludes Special Characters: Filters out matches with hyphens or underscores to ensure a clean identifier.
Efficiency: Processes each string once, significantly improving performance for large collections.

Remove-FinOpsHub.ps1

This PR simplifies the Remove-FinOpsHub logic by replacing the .Reduce() method with a more sequential foreach loop for deleting resources. It improves error handling, ensuring each resource deletion attempt is properly logged and handled individually. The script now includes clearer verbose messages for filtered resources, deletion attempts, and success statuses. These changes provide better transparency and avoid potential issues caused by parallel deletion, making the script more predictable and easier to debug.

Fixes #
#554

📋 Checklist

🔬 How did you test this change?

  • 🤏 Lint tests
  • 🤞 PS -WhatIf / az validate
  • 👍 Manually deployed + verified
  • 💪 Unit tests
  • 🙌 Integration tests

🙋‍♀️ Do any of the following that apply?

  • 🚨 This is a breaking change.
  • 🤏 The change is less than 20 lines of code.

📑 Did you update docs/changelog.md?

  • ✅ Updated changelog (required for dev PRs)
  • ➡️ Will add log in a future PR (feature branch PRs only)
  • ❎ Log not needed (small/internal change)

📖 Did you update documentation?

  • ✅ Public docs in docs (required for dev)
  • ✅ Internal dev docs in src (required for dev)
  • ➡️ Will add docs in a future PR (feature branch PRs only)
  • ❎ Docs not needed (small/internal change)

@flanakin flanakin added this to the 2024-09 – September milestone Sep 25, 2024
Copy link
Collaborator

@flanakin flanakin left a comment

Choose a reason for hiding this comment

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

Everything looks good at a glance. My only concern would be not having tests to validate this. We're already missing tests for this command, so I'm not necessarily blocking on that. It's just part of why this wasn't caught in the first place 😕

src/powershell/Private/Get-HubIdentifier.ps1 Show resolved Hide resolved
src/powershell/Private/Get-HubIdentifier.ps1 Show resolved Hide resolved
src/powershell/Private/Get-HubIdentifier.ps1 Outdated Show resolved Hide resolved
src/powershell/Private/Get-HubIdentifier.ps1 Outdated Show resolved Hide resolved
src/powershell/Private/Get-HubIdentifier.ps1 Outdated Show resolved Hide resolved
src/powershell/Public/Remove-FinOpsHub.ps1 Outdated Show resolved Hide resolved
src/powershell/Public/Remove-FinOpsHub.ps1 Outdated Show resolved Hide resolved
src/powershell/Public/Remove-FinOpsHub.ps1 Outdated Show resolved Hide resolved
src/powershell/Public/Remove-FinOpsHub.ps1 Outdated Show resolved Hide resolved
src/powershell/Public/Remove-FinOpsHub.ps1 Outdated Show resolved Hide resolved
@flanakin flanakin requested a review from a team September 26, 2024 07:00
@jamelachahbar
Copy link
Contributor Author

@flanakin , do you want me to squash and merge this?

@flanakin flanakin merged commit 8ff2f9f into dev Sep 27, 2024
2 checks passed
@flanakin flanakin deleted the bugfix/fix-remove-finopshubs-issue-554 branch September 27, 2024 00:05
@flanakin
Copy link
Collaborator

@jamelachahbar I looked at the integration tests we have here, which weren't working before. I was able to get something working for now, so we have an automated test for this. I updated that in the branch, so we're in a good state.

Thanks for getting this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Review 👀 PR that is ready to be reviewed Tool: FinOps hubs Data pipeline solution Tool: PowerShell PowerShell scripts and automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PowerShell][Hubs] Remove-FinOpsHub fails when there's only one resource
8 participants