Updated on 2024-05-27 GMT+08:00

Collecting Logs from API Gateway

LTS can collect logs from APIG.

Prerequisites

You have purchased and used an API gateway of Huawei Cloud.

Procedure

Perform the following operations to configure APIG log ingestion:

  1. Log in to the LTS console.
  2. In the left navigation pane, choose Log Ingestion. On the displayed page, click APIG (API Gateway).
  3. Select a log stream.

    1. Select a log group from the Log Group drop-down list. If there are no desired log groups, click Create Log Group to create one.
    2. Select a log stream from the Log Stream drop-down list. If there are no desired log streams, click Create Log Stream to create one.
    3. Click Next: Configure APIG.

  4. Configure APIG.

    Click Configure APIG.
    1. On the APIG console, choose Monitoring & Analysis > Log Analysis.
    2. Click Configure Log Collection.
    3. Enable log collection, and select a log group and stream.

      For details about the operations in APIG, see Log Analysis.

  5. Click Next: Configure Log Stream.

    Table 1 Log stream parameters

    Parameter

    Description

    Auto Structure and Index

    If is enabled, the log stream is automatically structured and indexed. The structuring is based on the APIG template, and the indexing enables quick analysis for all parsed APIG fields. Enabling structuring and indexing is required for SQL analysis of APIG logs with visual charts.

    Auto Add Tag log_type=apig_layer_access

    If this option is enabled, the tag log_type=apig_layer_access is automatically added to the log stream, and the APIG dashboard template can then match this log stream.

    Auto Create Dashboard

    If this option is enabled, an APIG dashboard is automatically created for the log stream.

  6. Click Submit.

Structuring Template Details

  • Structuring template example
    Table 2 Structuring template example

    Template Name

    Example Log

    APIG

    100.125.7.59 f57f6523b675504a23887d0f5c1c8ef3 f5ea2360a2fa443cac236b76f4052ad6 - - [27/Jan/2022:15:56:44 +0800] 0.113 GET http://c965898968af48248ec7fac4ec0666f4.apic.cn-north-4.huaweicloudapis.com /api/echo HTTP/1.1 200 1443 408 "APIGatewayDebugClient/1.0" "-" "100.125.2.39:443" /v2/x/fgs/functions/urn:fss:cn-north-4:106506b9a92342df9a5025fc12351cfc:function:default:apigDemo_1640743997661:latest/invocations "200" "0.010" "0.083" "0.083" cn-north-4 0.083 0 - - - 0.03000020980835 - - "-" 486 HttpEchoDemo - - - "-" "-" "-" "-" "-" "-" "-" "-" "-" "-" "remote" "0.52" "http" "id" "-" "urn:fss:cn-north-7:6650ff66e4524699bea4c96ff2f268fe:function:default:test123hxy"
  • Structuring field details

    Table 3 Structuring fields

    Field

    Example

    Description

    Type

    my_remote_addr

    100.125.7.59

    IP address of the user client.

    string

    request_id

    f57f6523b675504a23887d0f5c1c8ef3

    Request ID.

    string

    api_id

    f5ea2360a2fa443cac236b76f4052ad6

    API ID.

    string

    user_id

    -

    Username.

    string

    app_id

    -

    App ID provided by a requester for app authentication.

    string

    time_local

    27/Jan/2022:15:56:44

    Time when a request is received.

    string

    request_time

    0.113

    Request latency.

    float

    request_method

    GET

    HTTP request method.

    string

    scheme

    http

    Request method.

    string

    host

    c965898968af48248ec7fac4ec0666f4.apic.cn-north-4.huaweicloudapis.com

    Domain name.

    string

    router_uri

    /api/echo

    Request URI.

    string

    server_protocol

    HTTP/1.1

    Request protocol.

    string

    status

    200

    Response status code.

    long

    bytes_sent

    1443

    Response size in bytes, including the status line, header, and body.

    long

    request_length

    408

    Request length in bytes, including the start line, header, and body.

    long

    http_user_agent

    APIGatewayDebugClient/1.0

    User agent ID.

    string

    http_x_forwarded_for

    -

    X-Forwarded-For header field.

    string

    upstream_addr

    100.125.2.39:443

    Backend address.

    string

    upstream_uri

    /v2/x/fgs/functions/urn:fss:cn-north-4:106506b9a92342df9a5025fc12351cfc:function:default:apigDemo_1640743997661:latest/invocations

    Backend URI.

    string

    upstream_status

    200

    Backend response code.

    long

    upstream_connect_time

    0.01

    Time taken to establish a connection with the backend.

    float

    upstream_header_time

    0.083

    Duration from the start of a connection to the first byte received from the backend.

    float

    upstream_response_time

    0.083

    Duration from the start of a connection to the last byte received from the backend.

    float

    region_id

    cn-north-4

    Region ID.

    string

    all_upstream_response_time

    0.083

    Duration from the start of a connection to the last byte received from the backend, in seconds. When a retry occurs, the value is the total time taken.

    float

    errorType

    0

    API request error type. Options:

    • 0: non-throttling error
    • 1: throttling error

    long

    auth_type

    -

    API authentication mode.

    string

    access_model1

    -

    Authentication mode 1.

    string

    access_model2

    -

    Authentication mode 2. Enabling two-factor authentication will use the custom authorizer ID.

    string

    inner_time

    0.03000020980835

    APIG internal processing duration, in seconds.

    float

    proxy_protocol_vni

    -

    VPC endpoint virtual network ID.

    string

    proxy_protocol_vpce_id

    -

    VPC endpoint ID.

    string

    proxy_protocol_addr

    -

    Client IP address.

    string

    body_bytes_sent

    486

    API request body size, in bytes.

    long

    api_name

    HttpEchoDemo

    API name.

    string

    app_name

    -

    Name of the app used by a requester for authentication.

    string

    provider_app_id

    -

    App ID of an API.

    string

    provider_app_name

    -

    App name of an API.

    string

    custom_data_log1

    -

    Custom log field 1.

    string

    custom_data_log2

    -

    Custom log field 2.

    string

    custom_data_log3

    -

    Custom log field 3.

    string

    custom_data_log4

    -

    Custom log field 4.

    string

    custom_data_log5

    -

    Custom log field 5.

    string

    custom_data_log6

    -

    Custom log field 6.

    string

    custom_data_log7

    -

    Custom log field 7.

    string

    custom_data_log8

    -

    Custom log field 8.

    string

    custom_data_log9

    -

    Custom log field 9.

    string

    custom_data_log10

    -

    Custom log field 10.

    string

    response_source

    remote

    Response source. Options:

    • local: APIG
    • remote: backend service

    string

    gzip_ratio

    0.52

    Ratio of the original response body size to the compressed response body size.

    float

    upstream_scheme

    http

    Backend protocol type.

    string

    group_id

    id

    Group ID.

    string

    apig_err_code

    -

    Gateway error code.

    string

    function_urn

    urn:fss:cn-north-7:6650ff66e4524699bea4c96ff2f268fe:function:default:test123hxy

    Function URN.

    string