Skip to content

Commit 9ec5b94

Browse files
committed
Adding aql-queries endpoint
1 parent 453f74b commit 9ec5b94

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
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/exceptions.py

Lines changed: 4 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

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:

0 commit comments

Comments
 (0)