Skip to content

Commit

Permalink
Add log_level parameter to get_log_entries.
Browse files Browse the repository at this point in the history
Issue #170

Setting log_level should help to limit the amount of memory used in
Elasticsearch while retrieving logs.
The cause of the circuit_breaker_exception is that amount of memory
used is getting too close to the maximum limit allowed.
  • Loading branch information
JohanKJSchreurs committed Mar 30, 2023
1 parent 1d98c88 commit 5adc43b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion openeo_driver/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,13 @@ def get_results(self, job_id: str, user_id: str) -> Dict[str, dict]:
# TODO: eliminate this method in favor of `get_result_assets`
raise NotImplementedError

def get_log_entries(self, job_id: str, user_id: str, offset: Optional[str] = None) -> Iterable[dict]:
def get_log_entries(
self,
job_id: str,
user_id: str,
offset: Optional[str] = None,
log_level: Optional[str] = None,
) -> Iterable[dict]:
"""
https://openeo.org/documentation/1.0/developers/api/reference.html#operation/debug-job
"""
Expand Down
13 changes: 12 additions & 1 deletion openeo_driver/dummy/dummy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from shapely.geometry.base import BaseGeometry, BaseMultipartGeometry
from shapely.geometry.collection import GeometryCollection

from openeo.api.logs import normalize_log_level
from openeo.internal.process_graph_visitor import ProcessGraphVisitor
from openeo.metadata import CollectionMetadata, Band
from openeo_driver.ProcessGraphDeserializer import ConcreteProcessing
Expand Down Expand Up @@ -731,11 +732,21 @@ def get_result_assets(self, job_id: str, user_id: str) -> Dict[str, dict]:
}
}

def get_log_entries(self, job_id: str, user_id: str, offset: Optional[str] = None) -> Iterable[dict]:
def get_log_entries(
self,
job_id: str,
user_id: str,
offset: Optional[str] = None,
log_level: Optional[str] = None,
) -> Iterable[dict]:
self._get_job_info(job_id=job_id, user_id=user_id)
default_logs = [{"id": "1", "level": "info", "message": "hello world"}]
for log in self._custom_job_logs.get(job_id, default_logs):
if isinstance(log, dict):
actual_level = normalize_log_level(log.get("log_level"))
requested_level = normalize_log_level(log_level)
if actual_level < requested_level:
continue
yield log
elif isinstance(log, Exception):
raise log
Expand Down
7 changes: 5 additions & 2 deletions openeo_driver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,9 +1258,12 @@ def download_job_result_signed(job_id, user_base64, secure_key, filename):
@blueprint.route('/jobs/<job_id>/logs', methods=['GET'])
@auth_handler.requires_bearer_auth
def get_job_logs(job_id, user: User):
offset = request.args.get('offset')
offset = request.args.get("offset")
log_level = request.args.get("log_level")
# TODO: implement paging support: `limit`, next/prev/first/last `links`, ...
logs = backend_implementation.batch_jobs.get_log_entries(job_id=job_id, user_id=user.user_id, offset=offset)
logs = backend_implementation.batch_jobs.get_log_entries(
job_id=job_id, user_id=user.user_id, offset=offset, log_level=log_level
)

def generate():
yield """{"logs":["""
Expand Down

0 comments on commit 5adc43b

Please sign in to comment.