コード例 #1
0
def index():

    request_id = log_helper.extract_request_id(request.headers)
    if not request_id:
        return Response(f"Header {log_helper.REQUEST_ID_HEADER_NAME} not found", 400)
    type_header = request.headers.get(log_helper.TYPE_HEADER_NAME)
    if type_header is None:
        return Response(f"Header {log_helper.TYPE_HEADER_NAME} not found", 400)
    message_type = log_helper.parse_message_type(type_header)
    index_name = log_helper.build_index_name(request.headers)

    body = request.get_json(force=True)

    # max size is configurable with env var or defaults to constant
    max_payload_bytes = log_helper.get_max_payload_bytes(MAX_PAYLOAD_BYTES)

    body_length = request.headers.get(log_helper.LENGTH_HEADER_NAME)
    if body_length and int(body_length) > int(max_payload_bytes):
        too_large_message = (
            "body too large for "
            + index_name
            + "/"
            + (log_helper.DOC_TYPE_NAME if log_helper.DOC_TYPE_NAME != None else "_doc")
            + "/"
            + request_id
            + " adding "
            + message_type
        )
        print(too_large_message)
        sys.stdout.flush()
        return too_large_message

    if not type(body) is dict:
        body = json.loads(body)

    # print('RECEIVED MESSAGE.')
    # print(str(request.headers))
    # print(str(body))
    # print('----')
    # sys.stdout.flush()

    try:

        # now process and update the doc
        added_content = process_and_update_elastic_doc(
            es, message_type, body, request_id, request.headers, index_name
        )

        return jsonify(added_content)
    except Exception as ex:
        traceback.print_exc()
    sys.stdout.flush()
    return Response("problem logging request", 500)
コード例 #2
0
ファイル: default_logger.py プロジェクト: zjr1234/seldon-core
def index():

    request_id = log_helper.extract_request_id(request.headers)
    type_header = request.headers.get(log_helper.TYPE_HEADER_NAME)
    message_type = log_helper.parse_message_type(type_header)
    index_name = log_helper.build_index_name(request.headers)

    body = request.get_json(force=True)

    # max size is configurable with env var or defaults to constant
    max_payload_bytes = log_helper.get_max_payload_bytes(MAX_PAYLOAD_BYTES)

    body_length = request.headers.get(log_helper.LENGTH_HEADER_NAME)
    if body_length and int(body_length) > int(max_payload_bytes):
        too_large_message = (
            "body too large for "
            + index_name
            + "/"
            + log_helper.DOC_TYPE_NAME
            + "/"
            + request_id
            + " adding "
            + message_type
        )
        print(too_large_message)
        sys.stdout.flush()
        return too_large_message

    if not type(body) is dict:
        body = json.loads(body)

    # print('RECEIVED MESSAGE.')
    # print(str(request.headers))
    # print(str(body))
    # print('----')
    # sys.stdout.flush()

    try:

        # now process and update the doc
        doc = process_and_update_elastic_doc(
            es, message_type, body, request_id, request.headers, index_name
        )

        return str(doc)
    except Exception as ex:
        print(ex)
    sys.stdout.flush()
    return "problem logging request"