Logs and metrics for caching

Each Cloud CDN request is logged in Cloud Logging. For information about enabling and disabling logging, see the External Application Load Balancer and Cloud CDN logging and monitoring overview.

Logs for Cloud CDN are associated with the external Application Load Balancer that your Cloud CDN backends are attached to. Cloud CDN logs are indexed first by forwarding rule and then by URL map.

To view Cloud CDN logs, follow these steps.

Console

  1. In the Google Cloud console, go to the Logs Explorer page.

    Go to Logs Explorer

  2. In the Resource menu, select Cloud HTTP Load Balancer.
  3. View logs as follows:
    • View all logs: select the Resource menu, and then select All forwarding rules.
    • View the logs for a forwarding rule: select the forwarding rule name from the list of forwarding rules.
    • View the logs for a URL map used by a forwarding rule: select a forwarding rule, and then select a URL map.

Request served from the backend

To confirm that a request is served from a Cloud CDN-enabled backend, there are three main fields to look for, as follows:

  • httpRequest: When a request is served from a backend, you can see that the cache is filled and you can confirm the request URL.
    • cacheFillBytes: NUMBER_OF_BYTES
    • cacheLookup: True
    • requestURL: URL
  • jsonPayload: From the statusDetails field, you can confirm that the response was served by the backend.
    • statusDetails: "response_sent_by_backend"

Request served from cache

The following log entry shows a cache hit.

 {
    insertId: "1oek5rg3l3fxj7"
    jsonPayload: {
        @type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
        cacheId: "SFO-fbae48ad"
        statusDetails: "response_from_cache"
    }
    httpRequest: {
        requestMethod: "GET"
        requestUrl: "http://LOAD_BALANCER_IP_ADDRESS/static/us/three-cats.jpg"
        requestSize: "577"
        status: 304
        responseSize: "157"
        userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
        remoteIp: "CLIENT_IP_ADDRESS"
        cacheHit: true
        cacheLookup: true
    }
    resource: {
        type: "http_load_balancer"
        labels: {
            zone: "global"
            url_map_name: "URL_MAP_NAME"
            forwarding_rule_name: "FORWARDING_RULE_NAME"
            target_proxy_name: "TARGET_PROXY_NAME"
            backend_service_name: ""
            project_id: "PROJECT_ID"
        }
    }
    timestamp: "2020-06-08T23:41:30.078651Z"
    severity: "INFO"
    logName: "projects/PROJECT_ID/logs/requests"
    trace: "projects/PROJECT_ID/traces/241d69833e64b3bf83fabac8c873d992"
    receiveTimestamp: "2020-06-08T23:41:30.588272510Z"
    spanId: "7b6537d3672e08e1"
}

What is logged

In addition to general information contained in most logs, such as severity, project ID, project number, and timestamp, the external Application Load Balancer and Cloud CDN logs contain the following:

  • The HttpRequest log field, which captures the HTTP status code, bytes returned, and whether a cache lookup or cache fill was performed.

  • The jsonPayload.cacheId field, which indicates the location and cache instance that the cache response was served from. For example, a cache response served from a cache in Amsterdam would have a cacheId value of AMS-85e2bd4b, where AMS is the IATA code, and 85e2bd4b is an opaque identifier of the cache instance (because some Cloud CDN locations have multiple discrete caches).

  • The statusDetails and cacheDetail fields of the jsonPayload.

You can filter on the following fields to determine the cache hit, miss, or revalidation status of a request served by Cloud CDN:

  • Cache Hit

    jsonPayload.statusDetails=("response_from_cache" OR "byte_range_caching")

    or

    httpRequest.cacheHit=true
    httpRequest.cacheValidatedWithOriginServer!=true

  • Cache Hit Validated With Origin Server

    jsonPayload.statusDetails="response_from_cache_validated"

    or

    httpRequest.cacheHit=true
    httpRequest.cacheValidatedWithOriginServer=true