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

Added ability to search API logs #24

Merged
merged 5 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,27 @@ 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.search_api_logs('my-meta-engine', {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
"filters": {
"date": {
"from": "2020-03-30T00:00:00+00:00",
"to": "2020-03-31T00:00:00+00:00"
},
"status": "429",
}
})
{'results': [],
Copy link
Member

Choose a reason for hiding this comment

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

Could you update the formatting here to match the formatting of other responses in this README?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I don't recall if that was the copied/pasted output or where that formatting came from. Not be facetious at all, but I'm not sure which format you prefer. I see examples of "pretty" formatted output, one-liners, and one-liners with elided output:

Screen Shot 2020-07-29 at 9 39 18 AM

Copy link
Member

Choose a reason for hiding this comment

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

You have a great point. How about "pretty"?

'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}}}
```

## Running tests

```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 @@ -321,3 +321,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 search_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 @@ -552,3 +552,15 @@ def test_delete_meta_engine_sources(self):
response = self.client.delete_meta_engine_sources(
self.engine_name, [source_engine_name])
self.assertEqual(response, expected_return)

def test_search_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.search_api_logs(self.engine_name, options={})
self.assertEqual(response, expected_return)