Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Added ability to search API logs (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsma authored Jul 30, 2020
1 parent 7b4becb commit c659348
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,40 @@ Creating a search key that will only search over the body field.
{'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'}
```

### Search the API logs

```python
>>> client.get_api_logs('my-meta-engine', {
"filters": {
"date": {
"from": "2020-03-30T00:00:00+00:00",
"to": "2020-03-31T00:00:00+00:00"
},
"status": "429",
}
})
{
'results': [],
'meta': {
'query': '',
'filters': {
'date': {
'from': '2020-03-27T00:00:00+00:00',
'to': '2020-03-31T00:00:00+00:00'
},
'status': '429'
},
'sort_direction': 'asc',
'page': {
'current': 1,
'total_pages': 0,
'total_results': 0,
'size': 10
}
}
}
```

### Get search settings

```python
Expand Down
12 changes: 12 additions & 0 deletions elastic_app_search/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,15 @@ def create_signed_search_key(api_key, api_key_name, options):
"""
options['api_key_name'] = api_key_name
return jwt.encode(options, api_key, algorithm=Client.SIGNED_SEARCH_TOKEN_JWT_ALGORITHM)

def get_api_logs(self, engine_name, options=None):
"""
Searches the API logs.
:param engine_name: Name of engine.
:param options: Dict of search options.
"""
endpoint = "engines/{}/logs/api".format(engine_name)
options = options or {}
return self.session.request('get', endpoint, json=options)

12 changes: 12 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,18 @@ def test_delete_meta_engine_sources(self):
self.engine_name, [source_engine_name])
self.assertEqual(response, expected_return)

def test_get_api_logs(self):
expected_return = {'meta': {}, 'results': []}

with requests_mock.Mocker() as m:
url = "{}/{}".format(
self.client.session.base_url,
"engines/{}/logs/api".format(self.engine_name)
)
m.register_uri('GET', url, json=expected_return, status_code=200)
response = self.client.get_api_logs(self.engine_name, options={})
self.assertEqual(response, expected_return)

def test_get_search_settings(self):
expected_return = {
"search_fields": {
Expand Down

0 comments on commit c659348

Please sign in to comment.