Skip to content

Commit

Permalink
Pass log_level to backend when getting BatchJob logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs authored and soxofaan committed Apr 6, 2023
1 parent b1a59ec commit 4cabb19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 1 addition & 2 deletions openeo/extra/job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ def on_job_error(self, job: BatchJob, row):
"""
# TODO: param `row` is never accessed in this method. Remove it? Is this intended for future use?

logs = job.logs()
error_logs = [l for l in logs if l.level.lower() == "error"]
error_logs = job.logs(log_level="error")
error_log_path = self.get_error_log_path(job.job_id)

if len(error_logs) > 0:
Expand Down
4 changes: 2 additions & 2 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(
self._capabilities_cache = LazyLoadCache()

# Initial API version check.
self._api_version.require_at_least(self._MINIMUM_API_VERSION)
self.api_version.require_at_least(self._MINIMUM_API_VERSION)

self._auth_config = auth_config
self._refresh_token_store = refresh_token_store
Expand Down Expand Up @@ -897,7 +897,7 @@ def validate_process_graph(self, process_graph: dict) -> List[dict]:
return self.post(path="/validation", json=request, expected_status=200).json()["errors"]

@property
def _api_version(self) -> ComparableVersion:
def api_version(self) -> ComparableVersion:
# TODO make this a public property (it's also useful outside the Connection class)
return self.capabilities().api_version_check

Expand Down
25 changes: 17 additions & 8 deletions openeo/rest/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,25 @@ def logs(
:return: A list containing the log entries for the batch job.
"""
url = f"/jobs/{self.job_id}/logs"
logs = self.connection.get(url, params={'offset': offset}, expected_status=200).json()["logs"]
logs = self.connection.get(
url, params={"offset": offset, "log_level": log_level}, expected_status=200
).json()["logs"]

#
# TODO: we should still support client-side log_level filtering when the backend
# itself doesn't support filtering. What is the best way to check that, the API version?
# https://github.com/Open-EO/openeo-python-driver/issues/170
#

# Only filter logs when specified.
if log_level is not None:
log_level = normalize_log_level(log_level)
logs = (
log
for log in logs
if normalize_log_level(log.get("level")) >= log_level
)
if self.connection.api_version.at_most("1.1.0"):
if log_level is not None:
log_level = normalize_log_level(log_level)
logs = (
log
for log in logs
if normalize_log_level(log.get("level")) >= log_level
)

entries = [LogEntry(log) for log in logs]
return VisualList("logs", data=entries)
Expand Down

0 comments on commit 4cabb19

Please sign in to comment.