rubrikinc / rubrik-sdk-for-powershell

Rubrik Module for PowerShell
https://build.rubrik.com/sdks/powershell/
MIT License
102 stars 87 forks source link

Get-RubrikDatabase takes a long time to parse a large number( > 20,000) of databases #763

Open dewbrik opened 3 years ago

dewbrik commented 3 years ago

Is your feature request related to a problem? Please describe. When making a request to get a list of database through using Get-RubrikDatabase, the command can take a long time(~20 minutes) to complete.

Describe the solution you'd like I'd like for the cmdlet to complete faster.

Describe alternatives you've considered Replacing the cmdlet with a native cmdet and converting the output JSON proved to be faster. For example, I made the equivalent request with: $request = Invoke-WebRequest -URI "https://some_ip/api/v1/mssql/db" -method Get -header $someheaderinfo -useBasicParsing

and then convert the output with $db_list = ($request.content | Convertfrom-Json).data

This gives me the same output as: $db_list = Get-RubrikDatabase

Additional context

This is Windows PowerShell version 5.1, with the Rubrik PS module at 5.2.0. I set psdebug trace level to 2 and watched Get-RubrikDatabase execute, and if I had to guess, I think almost all of the time is being spent in Format-JSON.ps1 to parse the output as the scrolling text looked like this the entire time: `EBUG: ! CALL function 'ParseItem' (defined in file 'C:\Program Files\WindowsPowerShell\Modules\Rubrik\5.2.0\Private\Format-JSON.ps1') DEBUG: 23+ if( >>>> $jsonItem.PSObject.TypeNames -match 'Array') {

DEBUG: 25+ } elseif( >>>> $jsonItem.PSObject.TypeNames -match 'Dictionary') {

DEBUG: 28+ return >>>> $jsonItem

DEBUG: 30+ >>>> }

DEBUG: ! SET $parsedItem = 'a56467d8-471e-4a3c-935c-b091ce1d19fa'. DEBUG: 48+ >>>> $result | Add-Member -MemberType NoteProperty -Name $key -Value $parsedItem

DEBUG: 38+ foreach ( >>>> $key in $jsonObj.Keys)

DEBUG: ! SET $key = 'effectiveSlaDomainId'. DEBUG: 40+ >>>> $item = $jsonObj[$key]

DEBUG: ! SET $item = 'UNPROTECTED'. DEBUG: 42+ if ( >>>> $null -ne $item) {

DEBUG: 43+ >>>> $parsedItem = ParseItem -jsonItem $item

DEBUG: 18+ function ParseItem($jsonItem) >>>> {

DEBUG: ! CALL function 'ParseItem' (defined in file 'C:\Program Files\WindowsPowerShell\Modules\Rubrik\5.2.0\Private\Format-JSON.ps1')`

I'm not sure if this problem is reproducible in PowerShell 6 or newer.

jaapbrasser commented 2 years ago

Hey Dewbrik,

Just noticed this was still in the backlog, this is indeed fixed when using a new PowerShell version, but I've added support for two new scenarios:

The code is available in the following branch: https://github.com/rubrikinc/rubrik-sdk-for-powershell/tree/jaap-newpr