Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions algoliasearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ def generate_secured_api_key(self, private_api_key, queryParameters,
securedKey = hmac.new(private_api_key.encode('utf-8'), queryParameters.encode('utf-8'), hashlib.sha256).hexdigest()
return str(base64.b64encode(("%s%s" % (securedKey, queryParameters)).encode('utf-8')).decode('utf-8'))

def is_alive(self):
"""
Test if the server is alive.
This performs a simple application-level ping. If up and running, the server answers with a basic message.
"""
return self._req(True, '/1/isalive', 'GET')

Choose a reason for hiding this comment

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

The is_search parameter is not super explicit it switches between APPID-1.algolia.net and APPID-dsn.algolia.net. I think in that case we don't need it.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I know, but I'd rather use it exactly for that reason:

  • If we want to test that the cluster is up, better target the dynamic DNS anyway, it doesn't hurt.
  • "Warming up" a connection is most likely to be useful for searches than for write operations.

@ercolanelli-leo Is that OK for you?

Choose a reason for hiding this comment

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

Yes, you are right, I actually missed the part about warming up the connection in your PR description.
In that case it makes sense for me, and the tests pass, let's merge it!


def _req(self, is_search, path, meth, params=None, data=None):
if len(self.api_key) > MAX_API_KEY_LENGTH:
if data is None:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def test_dns_timeout_hard(self):

self.assertLess(time.time(), now + 6)

def test_is_alive(self):
res = self.client.is_alive()
self.assertIn('message', res)




Expand Down