Skip to content

Commit

Permalink
feat: add get_logs operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Nov 28, 2024
1 parent 46a6111 commit 4209217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions diracx-db/src/diracx/db/os/pilot_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class PilotLogsDB(BaseOSDB):
fields = {
"PilotStamp": {"type": "keyword"},
"PilotID": {"type": "long"},
"LineNumber": {"type": "long"},
"Message": {"type": "text"},
"VO": {"type": "keyword"},
Expand Down
20 changes: 19 additions & 1 deletion diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,28 @@ async def send_message(
docs.append(

Check warning on line 51 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L49-L51

Added lines #L49 - L51 were not covered by tests
{
"PilotStamp": data.pilot_stamp,
"PilotID": pilot_id,
"VO": data.vo,
"LineNumber": line.line_no,
"Message": line.line,
}
)
await pilot_logs_db.bulk_insert(pilot_logs_db.index_name(pilot_id), docs)
return data
return pilot_id

Check warning on line 61 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L60-L61

Added lines #L60 - L61 were not covered by tests


@router.get("/logs")
async def get_logs(
pilot_id: int,
db: PilotLogsDB,
check_permissions: CheckPilotLogsPolicyCallable,
):
logger.warning(f"Retrieving message for pilot ID '{pilot_id}'")
await check_permissions(action=ActionType.QUERY, pilot_db=db)

Check warning on line 71 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L70-L71

Added lines #L70 - L71 were not covered by tests

result = await db.search(

Check warning on line 73 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L73

Added line #L73 was not covered by tests
["Message"],
[{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}],
[{"parameter": "LineNumber", "direction": "asc"}],
)
return result

Check warning on line 78 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L78

Added line #L78 was not covered by tests

0 comments on commit 4209217

Please sign in to comment.