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

Commit c659348

Browse files
authored
Added ability to search API logs (#24)
1 parent 7b4becb commit c659348

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,40 @@ Creating a search key that will only search over the body field.
438438
{'source_engines': ['source-engine-1', 'source-engine-2'], 'type': 'meta', 'name': 'my-meta-engine'}
439439
```
440440

441+
### Search the API logs
442+
443+
```python
444+
>>> client.get_api_logs('my-meta-engine', {
445+
"filters": {
446+
"date": {
447+
"from": "2020-03-30T00:00:00+00:00",
448+
"to": "2020-03-31T00:00:00+00:00"
449+
},
450+
"status": "429",
451+
}
452+
})
453+
{
454+
'results': [],
455+
'meta': {
456+
'query': '',
457+
'filters': {
458+
'date': {
459+
'from': '2020-03-27T00:00:00+00:00',
460+
'to': '2020-03-31T00:00:00+00:00'
461+
},
462+
'status': '429'
463+
},
464+
'sort_direction': 'asc',
465+
'page': {
466+
'current': 1,
467+
'total_pages': 0,
468+
'total_results': 0,
469+
'size': 10
470+
}
471+
}
472+
}
473+
```
474+
441475
### Get search settings
442476

443477
```python

elastic_app_search/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,15 @@ def create_signed_search_key(api_key, api_key_name, options):
349349
"""
350350
options['api_key_name'] = api_key_name
351351
return jwt.encode(options, api_key, algorithm=Client.SIGNED_SEARCH_TOKEN_JWT_ALGORITHM)
352+
353+
def get_api_logs(self, engine_name, options=None):
354+
"""
355+
Searches the API logs.
356+
357+
:param engine_name: Name of engine.
358+
:param options: Dict of search options.
359+
"""
360+
endpoint = "engines/{}/logs/api".format(engine_name)
361+
options = options or {}
362+
return self.session.request('get', endpoint, json=options)
363+

tests/test_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,18 @@ def test_delete_meta_engine_sources(self):
553553
self.engine_name, [source_engine_name])
554554
self.assertEqual(response, expected_return)
555555

556+
def test_get_api_logs(self):
557+
expected_return = {'meta': {}, 'results': []}
558+
559+
with requests_mock.Mocker() as m:
560+
url = "{}/{}".format(
561+
self.client.session.base_url,
562+
"engines/{}/logs/api".format(self.engine_name)
563+
)
564+
m.register_uri('GET', url, json=expected_return, status_code=200)
565+
response = self.client.get_api_logs(self.engine_name, options={})
566+
self.assertEqual(response, expected_return)
567+
556568
def test_get_search_settings(self):
557569
expected_return = {
558570
"search_fields": {

0 commit comments

Comments
 (0)