azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

azure-mgmt-advisor

Open rominoff opened this issue 7 years ago • 17 comments

Up until last week I could correctly iterate list() from Advisor Management Client: client.recommendation.list(). Now it acts like a while loop, i have no way to stop it other than control-c. One of my coworkers confirmed the same behavior on her laptop. Not sure what's going on, other clients (subscription, for instance) are iterating correctly with expected behavior.

from azure.common.credentials import get_azure_cli_credentials from azure.mgmt.advisor import AdvisorManagementClient from azure.mgmt.subscription import SubscriptionClient

creds, subscriptionID = get_azure_cli_credentials() sClient = SubscriptionClient(creds)

aClient = AdvisorManagementClient(creds, "my subscription id")

for recommendation in aClient.recommendations.list(): print(recommendation.impacted_value)

rominoff avatar Feb 05 '19 23:02 rominoff

It hangs from the cli list command--used to work too:

az account set --subscription mysubscription az advisor recommendation list

rominoff avatar Feb 05 '19 23:02 rominoff

Hi @rominoff Could you post a few logs from the CLI in --debug mode? I guess if you have an infinite loop you will see the same call done again and again. I would be curious to see if this is something like "page X" in loop, or "page X to page X+1 to page X to page X+1" etc. (two pages in cycle).

@Prasanna-Padmanabhan for advice.

lmazuel avatar Feb 05 '19 23:02 lmazuel

Yes, please, logs will help. I am not aware of any such issue nor have there been any updates to the client, so I would be very interested to dig into this.

Prasanna-Padmanabhan avatar Feb 05 '19 23:02 Prasanna-Padmanabhan

Hi!

ok, changed the code a little bit to capture the end of the list and rolling over to the beginning of the list, here's the guts of the code:

From the debug code i could see there were 47 entries so i started capturing on 46--to save iteration cycles. The first entry returned was: recommendation.impacted_value: Standard_DS1_v2 virtual machines in eastus, the second time through it was again in the code.

for recommendation in aClient.recommendations.list(raw=True): reccount += 1 print(str(reccount)) if reccount == 46: pdb.set_trace()

print(recommendation.impacted_value)

-> print(recommendation.impacted_value) (Pdb) s defender1

/Users/bbell/testrecommendation.py(33)() -> for recommendation in aClient.recommendations.list(raw=True): (Pdb) s --Call-- /usr/local/lib/python3.7/site-packages/msrest/paging.py(133)next() -> def next(self): (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(138)next() -> if self.current_page and self._current_page_iter_index < len(self.current_page): (Pdb) p self._current_page_iter_index 46 (Pdb) p len(self.current_page) 47 (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(139)next() -> response = self.current_page[self._current_page_iter_index] (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(140)next() -> self._current_page_iter_index += 1 (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(141)next() -> return response (Pdb) n --Return-- /usr/local/lib/python3.7/site-packages/msrest/paging.py(141)next()-><azure.mgmt.a...t 0x108315e48> -> return response (Pdb) n /Users/bbell/testrecommendation.py(34)() -> reccount += 1 (Pdb) n /Users/bbell/testrecommendation.py(35)() -> print(str(reccount)) (Pdb) n 47 /Users/bbell/testrecommendation.py(36)() -> if reccount == 46: (Pdb) n /Users/bbell/testrecommendation.py(39)() -> print(recommendation.impacted_value) (Pdb) s 7f16c69f-410d-4463-b131-912e2572c245 /Users/bbell/testrecommendation.py(33)() -> for recommendation in aClient.recommendations.list(raw=True): (Pdb) s --Call-- /usr/local/lib/python3.7/site-packages/msrest/paging.py(133)next() -> def next(self): (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(138)next() -> if self.current_page and self._current_page_iter_index < len(self.current_page): (Pdb) p self._current_page_iter_index 47 (Pdb) p len(self.current_page) 47 (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(143)next() -> self.advance_page() (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(144)next() -> return self.next() (Pdb) n --Return-- /usr/local/lib/python3.7/site-packages/msrest/paging.py(144)next()-><azure.mgmt.a...t 0x1083367b8> -> return self.next() (Pdb) n /Users/bbell/testrecommendation.py(34)() -> reccount += 1 (Pdb) n /Users/bbell/testrecommendation.py(35)() -> print(str(reccount)) (Pdb) n 48 /Users/bbell/testrecommendation.py(36)() -> if reccount == 46: (Pdb) n /Users/bbell/testrecommendation.py(39)() -> print(recommendation.impacted_value) (Pdb) s Standard_DS1_v2 virtual machines in eastus /Users/bbell/testrecommendation.py(33)() -> for recommendation in aClient.recommendations.list(raw=True): (Pdb) s --Call-- /usr/local/lib/python3.7/site-packages/msrest/paging.py(133)next() -> def next(self): (Pdb) n /usr/local/lib/python3.7/site-packages/msrest/paging.py(138)next() -> if self.current_page and self._current_page_iter_index < len(self.current_page): (Pdb) p self._current_page_iter_index 1 (Pdb) p len(self.current_page) 47 (Pdb)

rominoff avatar Feb 09 '19 00:02 rominoff

Thanks for providing the details and apologies for the delay in responding. @mojayara is looking into this.

Prasanna-Padmanabhan avatar Feb 15 '19 19:02 Prasanna-Padmanabhan

@lmazuel @iscai-msft Can you guys look into this issue?

praries880 avatar Feb 19 '19 21:02 praries880

Hi we've been looking into this issue and we've found that for recommendations paging, the next link the server returns is an empty string when it's done instead of a null string. In all other cases, the server returns a null string. Since it's not returning null, we keep paging leading to the infinite loop. Nothing in the Python side has changed, this change originated on the server side, @mojayara can you change it back to returning null? Thanks!

iscai-msft avatar Feb 20 '19 19:02 iscai-msft

Please let me know once it is changed back, thanks for tracking this down

rominoff avatar Feb 22 '19 13:02 rominoff

A fix is coming from the python team for this issue.

mojayara avatar Feb 22 '19 15:02 mojayara

Great!

rominoff avatar Feb 22 '19 15:02 rominoff

Update, a regression was introduced in our system which added this infinite looping. We have a fix rolled out this week.

mojayara avatar Feb 26 '19 22:02 mojayara

Thanks @mojayara !

lmazuel avatar Feb 27 '19 16:02 lmazuel

Thank you!!!

rominoff avatar Feb 28 '19 18:02 rominoff

A fix is coming from the python team for this issue.

Hi @mojayara I'm running into the same issue, how can I fix it

ghost avatar Mar 01 '19 18:03 ghost

Update, a regression was introduced in our system which added this infinite looping. We have a fix rolled out this week.

Has the fix rolled out @mojayara

ghost avatar Mar 01 '19 18:03 ghost

Yes, the roll-out for the fix is in progress this week.

mojayara avatar Mar 01 '19 18:03 mojayara

Yes, the roll-out for the fix is in progress for this week.

Yeah, I think its worked for me now, I was using the old version of azure-mgmt-advisor (1.0.1) I've upgrade the package to 2.0.1, and this time it worked, no looping :)

Thanks @mojayara

ghost avatar Mar 01 '19 18:03 ghost