Skip to content

Conversation

@max-zilla
Copy link
Contributor

Adds a function to catch exceptions in the DB with some extra info.

@max-zilla max-zilla requested a review from a team October 21, 2022 16:03
logger.info("Successfully connected to Elasticsearch")
else:
logger.info("Can not connect to Elasticsearch")
try:
Copy link
Member

Choose a reason for hiding this comment

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

Code looks good, but I am not sure how to test it in this case. If I turn off elasticsearch, I get an error before we get to ping.

WARNING:elastic_transport.node_pool:Node <Urllib3HttpNode(http://localhost:9200)> has failed for 11 times in a row, putting on 30 second timeout
WARNING:elastic_transport.transport:Retrying request after failure (attempt 2 of 3)
Traceback (most recent call last):
  File "/Users/lmarini/.local/share/virtualenvs/clowder2-pkRZ1537/lib/python3.9/site-packages/elastic_transport/_transport.py", line 329, in perform_request
    meta, raw_data = node.perform_request(
  File "/Users/lmarini/.local/share/virtualenvs/clowder2-pkRZ1537/lib/python3.9/site-packages/elastic_transport/_node/_http_urllib3.py", line 199, in perform_request
    raise err from None
elastic_transport.ConnectionError: Connection error caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x10dce7910>: Failed to establish a new connection: [Errno 61] Connection refused)
WARNING:elastic_transport.node_pool:Node <Urllib3HttpNode(http://localhost:9200)> has failed for 12 times in a row, putting on 30 second timeout```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so this was 1) start up docker ES, 2) start up backend, 3) kill docker ES?

otherwise, we could come up with a contrived test case like "if es.ping() =.TRUE, pretend it failed" just to check the actual logging of errors even if the error is nonsense.

@ddey2 ddey2 self-requested a review October 26, 2022 16:49
else:
raise ServiceUnreachable("Elasticsearch")
except ServiceUnreachable as e:
log_error(e)
Copy link
Member

Choose a reason for hiding this comment

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

i think you are missing an await here. log_error function is async. I set an break point here and it didn't actually enter this function :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you, i added the await. we can talk today about how to test this

@lmarini lmarini merged commit 2481513 into main Nov 2, 2022
@lmarini lmarini deleted the generic-error-class branch November 2, 2022 19:41
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.

4 participants