Skip to content

Commit c2b88b0

Browse files
apetencheaaMahanna
andauthored
New API methods (#378)
* Adding aql-queries endpoint * Adding api-calls endpoint * bumped driver version * bumped driver version --------- Co-authored-by: Anthony Mahanna <[email protected]>
1 parent 8bd2d11 commit c2b88b0

File tree

7 files changed

+65
-4
lines changed

7 files changed

+65
-4
lines changed

arango/aql.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
AQLQueryClearError,
1818
AQLQueryExecuteError,
1919
AQLQueryExplainError,
20+
AQLQueryHistoryError,
2021
AQLQueryKillError,
2122
AQLQueryListError,
2223
AQLQueryRulesGetError,
@@ -627,6 +628,23 @@ def response_handler(resp: Response) -> Json:
627628

628629
return self._execute(request, response_handler)
629630

631+
def history(self) -> Result[Json]:
632+
"""Return recently executed AQL queries (admin only).
633+
634+
:return: AQL query history.
635+
:rtype: dict
636+
:raise arango.exceptions.AQLQueryHistoryError: If retrieval fails.
637+
"""
638+
request = Request(method="get", endpoint="/_admin/server/aql-queries")
639+
640+
def response_handler(resp: Response) -> Json:
641+
if not resp.is_success:
642+
raise AQLQueryHistoryError(resp, request)
643+
res: Json = resp.body["result"]
644+
return res
645+
646+
return self._execute(request, response_handler)
647+
630648
def functions(self) -> Result[Jsons]:
631649
"""List the AQL functions defined in the database.
632650

arango/database.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
PermissionListError,
4545
PermissionResetError,
4646
PermissionUpdateError,
47+
ServerAPICallsError,
4748
ServerAvailableOptionsGetError,
4849
ServerCheckAvailabilityError,
4950
ServerCurrentOptionsGetError,
@@ -463,6 +464,26 @@ def response_handler(resp: Response) -> Json:
463464

464465
return self._execute(request, response_handler)
465466

467+
def api_calls(self) -> Result[Json]:
468+
"""Return recent API calls (admin only).
469+
470+
:return: API calls history.
471+
:rtype: dict
472+
:raise arango.exceptions.ServerAPICallsError: If retrieval fails.
473+
"""
474+
request = Request(
475+
method="get",
476+
endpoint="/_admin/server/api-calls",
477+
)
478+
479+
def response_handler(resp: Response) -> Json:
480+
if not resp.is_success:
481+
raise ServerAPICallsError(resp, request)
482+
res: Json = resp.body["result"]
483+
return res
484+
485+
return self._execute(request, response_handler)
486+
466487
def status(self) -> Result[Json]:
467488
"""Return ArangoDB server status.
468489

arango/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class AQLQueryTrackingGetError(ArangoServerError):
121121
"""Failed to retrieve AQL tracking properties."""
122122

123123

124+
class AQLQueryHistoryError(ArangoServerError):
125+
"""Failed to retrieve recent AQL queries."""
126+
127+
124128
class AQLQueryTrackingSetError(ArangoServerError):
125129
"""Failed to configure AQL tracking properties."""
126130

@@ -638,6 +642,10 @@ class ServerDetailsError(ArangoServerError):
638642
"""Failed to retrieve server details."""
639643

640644

645+
class ServerAPICallsError(ArangoServerError):
646+
"""Failed to retrieve recent API calls."""
647+
648+
641649
class ServerLicenseGetError(ArangoServerError):
642650
"""Failed to retrieve server license."""
643651

arango/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def normalize_headers(
1212
if driver_flags is not None:
1313
for flag in driver_flags:
1414
flags = flags + flag + ";"
15-
driver_version = "8.2.2"
15+
driver_version = "8.2.3"
1616
driver_header = "python-arango/" + driver_version + " (" + flags + ")"
1717
normalized_headers: Headers = {
1818
"charset": "utf-8",

starter.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Example:
99
# ./starter.sh cluster enterprise 3.12.5
1010

11-
setup="${1:-single}"
12-
license="${2:-community}"
11+
setup="${1:-cluster}"
12+
license="${2:-enterprise}"
1313
version="${3:-latest}"
1414

1515
extra_ports=""

tests/test_aql.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AQLQueryClearError,
1414
AQLQueryExecuteError,
1515
AQLQueryExplainError,
16+
AQLQueryHistoryError,
1617
AQLQueryKillError,
1718
AQLQueryListError,
1819
AQLQueryTrackingGetError,
@@ -30,7 +31,7 @@ def test_aql_attributes(db, username):
3031
assert repr(db.aql.cache) == f"<AQLQueryCache in {db.name}>"
3132

3233

33-
def test_aql_query_management(db_version, db, bad_db, col, docs):
34+
def test_aql_query_management(db_version, db, sys_db, bad_db, col, docs):
3435
explain_fields = [
3536
"estimatedNrItems",
3637
"estimatedCost",
@@ -192,6 +193,12 @@ def test_aql_query_management(db_version, db, bad_db, col, docs):
192193
db.begin_async_execution().aql.execute("RETURN SLEEP(100)")
193194
db.begin_async_execution().aql.execute("RETURN SLEEP(50)")
194195

196+
# Test query history
197+
with assert_raises(AQLQueryHistoryError):
198+
bad_db.aql.history()
199+
history = sys_db.aql.history()
200+
assert isinstance(history, dict)
201+
195202
# Test list queries
196203
queries = db.aql.queries()
197204
for query in queries:

tests/test_database.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
DatabaseListError,
2121
DatabasePropertiesError,
2222
DatabaseSupportInfoError,
23+
ServerAPICallsError,
2324
ServerCheckAvailabilityError,
2425
ServerDetailsError,
2526
ServerEchoError,
@@ -314,6 +315,12 @@ def test_database_misc_methods(client, sys_db, db, bad_db, cluster, secret, db_v
314315
with assert_raises(ServerLogLevelResetError):
315316
bad_db.reset_log_levels()
316317

318+
# Test api calls history
319+
with assert_raises(ServerAPICallsError):
320+
bad_db.api_calls()
321+
history = sys_db.api_calls()
322+
assert isinstance(history, dict)
323+
317324
# Test get storage engine
318325
engine = db.engine()
319326
assert engine["name"] in ["rocksdb"]

0 commit comments

Comments
 (0)