is ZONE_RESOURCE_POOL_EXHAUSTED a googleapiclient.errors.httpError? - python-3.x

I am using the googleapiclient(Python) APIs like images().get(), images().insert() etc to list images, create VM instances etc
There were several ZONE_RESOURCE_POOL_EXHAUSTED errors from google cloud last month which caused the following exception in my code
Exception: {'errors': [{'code': 'ZONE_RESOURCE_POOL_EXHAUSTED', 'message': "The zone 'projects/<project-name>/zones/us-central1-b' does not have enough resources available to fulfill the request. Try a different zone, or try again later."}]}
I want to handle this error in my code by sending a unique error code from my server to the client to retry this request after sometime since the error is transient.
I am not able to reproduce this error willfully for the same reason...that its transient
I checked the googleapi code on GitHub at https://github.com/googleapis/google-api-python-client
but couldn't find ZONE_RESOURCE_POOL_EXHAUSTED
I need to verify if its an exception of type "HttpError" or some other class and then can handle it in my code
I am already handling exception of type googleapiclient.errors.HttpError in my code by printing an error message and raising it as urllib.error.HTTPError (the server sends the code e.resp['status'] for this case to the client)
except HttpError as e:
printf('Failed to create %s: %s\n', instanceName,
e._get_reason())
raise HTTPError(
None, int(e.resp['status']), e._get_reason(), "", None)

Related

Error reporting in Azure Functions vs App Insights

We call REST based APIs hosted by Azure Functions and fail to implement a consistent error handling supporting App Insights and wonder what can be done about it:
If we don't handle exceptions of the function, then App Insights
reports a 'failure', but the service returns only the the error code to the caller, but no error content:
Hence, the client receives a 500 and thats it.
If we handle the exception and log it (to AppInsights) then App Insights stops reporting a 'failure' hence monitoring on function level is broken. We can query for the exception, but they are out-of-context (i.e. we can see the exception by a custom query only) and we don't know which function is impacted actually.
How to marry up the two needs:
Let the function fail so that AppInsights reports the failure (and monitor can alert)
Return a bit more meaningful error message to the caller than 500.
Example on how it looks in AppInsights:
Exception is visible on the Exceptions tab, but the underlying operation has not failed
UPDATE:
According to Microsoft, App Insight Failures are exclusive to unhandled exceptions. Still, open whether there is a way to at least pass-through an error message.
If don't handle exceptions of the function, then App Insights reports a 'failure', returns the error code, but no error content. Hence, the client receives a 500 and thats it.
App Insights doesn't return anything, so what do you mean with returns the error code?
If we handle the exception, LOG it (to AppInsights), return simple error message in code 500, then App Insights doesn't log this as 'failure' hence monitoring is not possible.
Can you show how you do the logging? Because as soon as you log an exception using App Insights you should see it under failures.
This should work:
try
{
...
}
catch(Exception e)
{
logger.LogError(e, e.Message);
return httpRequest.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
}

Pact-python : Consumer pacts for POST calls are failing

I am trying to create consumer side pacts for a POST end point using the pact-python library. But it's failing with the error saying "Missing requests".
Here't the client code which makes the POST API call
def create_user(request):
return requests.post("http://localhost:1234/user", data=request).json()
Here's my test class which create the consumer pacts.
class TestUserConsumer(unittest.TestCase):
def test_user_creation(self):
request = {
"name": "Micky",
"age": 0
}
response = {
"id": 1232,
"name": "Micky",
"age": 0
}
pact = Consumer("user_client").has_pact_with(Provider("user_server"))
pact.start_service()
pact.with_request(
method='post',
path='/user',
body=request
).will_respond_with(status=200, body=response)
with pact:
create_user(request)
pact.verify()
pact.stop_service()
The test failed with the following error.
line 268, in verify
assert resp.status_code == 200, resp.text
AssertionError: Actual interactions do not match expected interactions for mock MockService.
Missing requests:
POST /user
The create_user(request) is getting executed, but still the interactions are not recorded on the pact mock server.
Note : The GET API pact creations are working. Only the POSTs are failing.
Appreciate the help.
I figured out the problem. I was not converting my dictionary to json before making the request. Hence the request body format was incorrectly send. This caused a failure on the mock server while verifying the pact.
I also noticed that, the logs didn't get generated initially. This was due to my assertions added before stopping the server. Since the assertions got failed, the pact mock server didn't get stopped. Hence the logs are not generated at all. Once I stopped the server, the logs got added and that helped me to identify the problem.

Dialogflow Webhook call failed. Error: [ResourceName error] Path '' does not match template

I am using Dialogflow ES and once I got the webhook setup, I haven't been having issues. But after a few months, I just started getting a random error. It seems to be inconsistent as in sometimes I get it for a specific web call and other times it works fine. This is from the Raw API response:
"webhookStatus": {
"code": 3,
"message": "Webhook call failed. Error: [ResourceName error] Path '' does not match template 'projects/{project_id=*}/locations/{location_id=*}/agent/environments/{environment_id=*}/users/{user_id=*}/sessions/{session_id=*}/contexts/{context_id=*}'.."
}
The webhook is in GCP Functions in the same project. I have a simple "ping" function in the same agent that calls the webhook. That works properly and pings the function, records some notes in the function log (so I know the function is being called), and returns a response fine, so I know the webhook is connected and working for other intents in the same agent before and after I get the error above.
Other intents in the same agent work (and this one WAS working), but I get this error now. I also tried recreating the intent and I get the same behavior.
The project is linked to a billing account and I have been getting charged for it, so I don't think it is an issue with being on a trial or otherwise. Though the Dialogflow itself is in "trial", but the linked webhook function is billed.
Where can I find what this error means or where to look to resolve it?
After looking at this with fresh eyes, I found out what was happening.
The issue was a mal-formed output context. I was returning the bad output context sometimes (which explained why sometimes it worked and sometimes it didn't). Specifically, I was returning the parameters directly into the output context without the output context 'name' or 'parameters'. Everything looked like it was working and I didn't get any other errors, but apparently, when Dialogflow receives a bad web response, it generates the unhelpful error above.

Error 500: nested exception is: psdi.util.MXSystemException: BMXAA4160E - A major exception has occurred

Uploading job plans into MAXIMO 7.6 using mxloader sheet; the next jonb plan does not go in because of ERROR 500 stating that 'BMXAA4160E - A major exception has occurred' comes up.
I have queried successful uploads from the DEMO and then used to format for mine.
I expect that all the distinct job plans upload at one run of the MXloader. This is the error message that I received
Error 500: nested exception is: psdi.util.MXSystemException:
BMXAA4160E - A major exception has occurred. Check the system log to
see if there are any companion errors logged. Report this error to your
system administrator.

Azure AD OAuth2.0 Transient Errors (AADSTS90090)

I have an Azure AD app which was working fine yesterday. But today, the response from the sign in page (the one with the code param), is returning an error and error_description params, and no code param. The values are:
error: temporarily_unavailable
error_description: AADSTS90090: A
transient error has occurred. Please try again. Trace ID: [unid]
Correlation ID: [unid] Timestamp: 2015-08-12 08:44:06Z
A few Googles says this is a temporary error, which should "go away soon", but given this is an authentication request, I would expect such transient errors to be resolved in seconds, or minutes at a maximum, and this has now been happening for hours.
Questions:
Is this something that happens regularly?
How long should it take to be resolved?
Is there anything (other than display an error message) I can do my end to handle this?
Any further information appreciated.

Resources