Skip to content

Commit

Permalink
BatchJob.logs: filter on log_level client-side AND server-side.
Browse files Browse the repository at this point in the history
No need to decide based on api_version.

Open-EO/openeo-python-driver#170
  • Loading branch information
JohanKJSchreurs authored and soxofaan committed Apr 6, 2023
1 parent 4cabb19 commit fac21be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
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
23 changes: 9 additions & 14 deletions openeo/rest/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,16 @@ def logs(
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 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
)
# We should still support client-side log_level filtering because not all backends
# support the log_level option.
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 fac21be

Please sign in to comment.