Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions arango/aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
AQLQueryClearError,
AQLQueryExecuteError,
AQLQueryExplainError,
AQLQueryHistoryError,
AQLQueryKillError,
AQLQueryListError,
AQLQueryRulesGetError,
Expand Down Expand Up @@ -627,6 +628,23 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def history(self) -> Result[Json]:
"""Return recently executed AQL queries (admin only).

:return: AQL query history.
:rtype: dict
:raise arango.exceptions.AQLQueryHistoryError: If retrieval fails.
"""
request = Request(method="get", endpoint="/_admin/server/aql-queries")

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise AQLQueryHistoryError(resp, request)
res: Json = resp.body["result"]
return res

return self._execute(request, response_handler)

def functions(self) -> Result[Jsons]:
"""List the AQL functions defined in the database.

Expand Down
21 changes: 21 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
PermissionListError,
PermissionResetError,
PermissionUpdateError,
ServerAPICallsError,
ServerAvailableOptionsGetError,
ServerCheckAvailabilityError,
ServerCurrentOptionsGetError,
Expand Down Expand Up @@ -463,6 +464,26 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def api_calls(self) -> Result[Json]:
"""Return recent API calls (admin only).

:return: API calls history.
:rtype: dict
:raise arango.exceptions.ServerAPICallsError: If retrieval fails.
"""
request = Request(
method="get",
endpoint="/_admin/server/api-calls",
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise ServerAPICallsError(resp, request)
res: Json = resp.body["result"]
return res

return self._execute(request, response_handler)

def status(self) -> Result[Json]:
"""Return ArangoDB server status.

Expand Down
8 changes: 8 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class AQLQueryTrackingGetError(ArangoServerError):
"""Failed to retrieve AQL tracking properties."""


class AQLQueryHistoryError(ArangoServerError):
"""Failed to retrieve recent AQL queries."""


class AQLQueryTrackingSetError(ArangoServerError):
"""Failed to configure AQL tracking properties."""

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


class ServerAPICallsError(ArangoServerError):
"""Failed to retrieve recent API calls."""


class ServerLicenseGetError(ArangoServerError):
"""Failed to retrieve server license."""

Expand Down
2 changes: 1 addition & 1 deletion arango/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def normalize_headers(
if driver_flags is not None:
for flag in driver_flags:
flags = flags + flag + ";"
driver_version = "8.2.2"
driver_version = "8.2.3"
driver_header = "python-arango/" + driver_version + " (" + flags + ")"
normalized_headers: Headers = {
"charset": "utf-8",
Expand Down
4 changes: 2 additions & 2 deletions starter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# Example:
# ./starter.sh cluster enterprise 3.12.5

setup="${1:-single}"
license="${2:-community}"
setup="${1:-cluster}"
license="${2:-enterprise}"
version="${3:-latest}"

extra_ports=""
Expand Down
9 changes: 8 additions & 1 deletion tests/test_aql.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
AQLQueryClearError,
AQLQueryExecuteError,
AQLQueryExplainError,
AQLQueryHistoryError,
AQLQueryKillError,
AQLQueryListError,
AQLQueryTrackingGetError,
Expand All @@ -30,7 +31,7 @@ def test_aql_attributes(db, username):
assert repr(db.aql.cache) == f"<AQLQueryCache in {db.name}>"


def test_aql_query_management(db_version, db, bad_db, col, docs):
def test_aql_query_management(db_version, db, sys_db, bad_db, col, docs):
explain_fields = [
"estimatedNrItems",
"estimatedCost",
Expand Down Expand Up @@ -192,6 +193,12 @@ def test_aql_query_management(db_version, db, bad_db, col, docs):
db.begin_async_execution().aql.execute("RETURN SLEEP(100)")
db.begin_async_execution().aql.execute("RETURN SLEEP(50)")

# Test query history
with assert_raises(AQLQueryHistoryError):
bad_db.aql.history()
history = sys_db.aql.history()
assert isinstance(history, dict)

# Test list queries
queries = db.aql.queries()
for query in queries:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DatabaseListError,
DatabasePropertiesError,
DatabaseSupportInfoError,
ServerAPICallsError,
ServerCheckAvailabilityError,
ServerDetailsError,
ServerEchoError,
Expand Down Expand Up @@ -314,6 +315,12 @@ def test_database_misc_methods(client, sys_db, db, bad_db, cluster, secret, db_v
with assert_raises(ServerLogLevelResetError):
bad_db.reset_log_levels()

# Test api calls history
with assert_raises(ServerAPICallsError):
bad_db.api_calls()
history = sys_db.api_calls()
assert isinstance(history, dict)

# Test get storage engine
engine = db.engine()
assert engine["name"] in ["rocksdb"]
Expand Down
Loading