Beispiel #1
0
async def collect_logs(request):
    owner = request.path_params["owner"]
    project = request.path_params["project"]
    run_uuid = request.path_params["run_uuid"]
    resource_name = get_resource_name(run_uuid=run_uuid)
    operation = get_run_instance(owner=owner,
                                 project=project,
                                 run_uuid=run_uuid)
    k8s_manager = AsyncK8SManager(
        namespace=settings.CLIENT_CONFIG.namespace,
        in_cluster=settings.CLIENT_CONFIG.in_cluster,
    )
    await k8s_manager.setup()
    k8s_operation = await get_k8s_operation(k8s_manager=k8s_manager,
                                            resource_name=resource_name)
    if not k8s_operation:
        raise HTTPException(
            detail="Run's logs was not collected, resource was not found.",
            status_code=status.HTTP_400_BAD_REQUEST,
        )
    operation_logs, _ = await get_k8s_operation_logs(operation=operation,
                                                     k8s_manager=k8s_manager,
                                                     last_time=None)
    if k8s_manager:
        await k8s_manager.close()
    if not operation_logs:
        return Response()

    logs = operation_logs
    task = BackgroundTask(upload_logs, run_uuid=run_uuid, logs=logs)
    return Response(background=task)
Beispiel #2
0
async def get_logs(request):
    owner = request.path_params["owner"]
    project = request.path_params["project"]
    run_uuid = request.path_params["run_uuid"]
    force = to_bool(request.query_params.get("force"), handle_none=True)
    resource_name = get_resource_name(run_uuid=run_uuid)
    operation = get_run_instance(owner=owner,
                                 project=project,
                                 run_uuid=run_uuid)
    last_time = QueryParams(request.url.query).get("last_time")
    if last_time:
        last_time = dt_parser.parse(last_time).astimezone()
    last_file = QueryParams(request.url.query).get("last_file")

    k8s_manager = None
    k8s_operation = None
    if not last_file:
        k8s_manager = AsyncK8SManager(
            namespace=settings.CLIENT_CONFIG.namespace,
            in_cluster=settings.CLIENT_CONFIG.in_cluster,
        )
        await k8s_manager.setup()
        k8s_operation = await get_k8s_operation(k8s_manager=k8s_manager,
                                                resource_name=resource_name)

    if not last_file and k8s_operation:
        last_file = None
        operation_logs, last_time = await get_k8s_operation_logs(
            operation=operation,
            last_time=last_time,
            k8s_manager=k8s_manager,
            stream=True,
        )
        if k8s_operation["status"].get("completionTime"):
            last_time = None
    elif last_time:  # Streaming should stop
        last_file = None
        last_time = None
        operation_logs = []
    else:
        last_time = None
        operation_logs, last_file = await get_archived_operation_logs(
            run_uuid=run_uuid, last_file=last_file, check_cache=not force)
    if k8s_manager:
        await k8s_manager.close()
    response = V1Logs(last_time=last_time,
                      last_file=last_file,
                      logs=operation_logs)
    return UJSONResponse(response.to_dict())
Beispiel #3
0
 def get_instance(self):
     return get_run_instance(owner=self.owner_name,
                             project=self.project_name,
                             run_uuid=self.run_uuid)