Closed2
Cloud CDNでキャッシュヒット時のログを観察する
バックエンドのバケットを作り、LBを作成。バケットはEUに作ってる。
このコマンドでリクエストを送る。
for i in {1..3};do curl -s -w "%{time_total}\n" -o /dev/null http://$LB_IP_ADDRESS/cdn.png; done
結果、こう
2.299874
0.006055
0.005619
最初のリクエストに時間かかってるけど、2回目以降は早いのでCloudCDNのキャッシュヒットしたっぽいのがわかる
ログを出す。
違いは、httpRequest
のcacheLookup
, cacheHit
, jsonPayload
のstatusDetails
がresponse_sent_by_backend
とresponse_from_cache
になっていることがわかる。これをもとに、キャッシュが効いてるor効いてないを判断できる。
一回目はこっち。
{
"insertId": "973zgwf2db5o5",
"jsonPayload": {
"backendTargetProjectNumber": "projects/770540151631",
"statusDetails": "response_sent_by_backend",
"@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
"cacheDecision": [
"RESPONSE_HAS_CACHE_CONTROL",
"RESPONSE_CACHE_CONTROL_PUBLIC",
"RESPONSE_HAS_ETAG",
"RESPONSE_HAS_LAST_MODIFIED",
"RESPONSE_HAS_EXPIRES",
"RESPONSE_HAS_CONTENT_TYPE",
"CACHE_MODE_CACHE_ALL_STATIC"
],
"cacheId": "TPE",
"remoteIp": "35.221.243.134"
},
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "http://34.8.204.145/cdn.png",
"requestSize": "82",
"status": 200,
"responseSize": "308310",
"userAgent": "curl/8.5.0",
"remoteIp": "35.221.243.134",
"cacheLookup": true,
"cacheFillBytes": "308310",
"serverIp": "2002:a05:66aa:349::",
"latency": "2.296103s"
},
"resource": {
"type": "http_load_balancer",
"labels": {
"url_map_name": "cdn-lb",
"project_id": "qwiklabs-gcp-04-d815591cff5f",
"backend_service_name": "",
"target_proxy_name": "cdn-lb-target-proxy",
"zone": "global",
"forwarding_rule_name": "cdn-lb-forwarding-rule"
}
},
"timestamp": "2024-11-10T02:33:53.628526Z",
"severity": "INFO",
"logName": "projects/qwiklabs-gcp-04-d815591cff5f/logs/requests",
"trace": "projects/qwiklabs-gcp-04-d815591cff5f/traces/27ee809e2dd82359bb7dea6216d09e71",
"receiveTimestamp": "2024-11-10T02:33:56.533734175Z",
"spanId": "b45d29eb6d2c4d8a"
}
二回目はこっち。
{
"insertId": "10yaxgbfaoutsi",
"jsonPayload": {
"remoteIp": "35.221.243.134",
"@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
"cacheDecision": [
"RESPONSE_HAS_CACHE_CONTROL",
"RESPONSE_CACHE_CONTROL_PUBLIC",
"RESPONSE_HAS_ETAG",
"RESPONSE_HAS_LAST_MODIFIED",
"RESPONSE_HAS_EXPIRES",
"RESPONSE_HAS_CONTENT_TYPE",
"CACHE_MODE_CACHE_ALL_STATIC"
],
"statusDetails": "response_from_cache",
"backendTargetProjectNumber": "projects/770540151631",
"cacheId": "TPE"
},
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "http://34.8.204.145/cdn.png",
"requestSize": "82",
"status": 200,
"responseSize": "308318",
"userAgent": "curl/8.5.0",
"remoteIp": "35.221.243.134",
"cacheHit": true,
"cacheLookup": true,
"latency": "0.004081s"
},
"resource": {
"type": "http_load_balancer",
"labels": {
"target_proxy_name": "cdn-lb-target-proxy",
"backend_service_name": "",
"zone": "global",
"url_map_name": "cdn-lb",
"forwarding_rule_name": "cdn-lb-forwarding-rule",
"project_id": "qwiklabs-gcp-04-d815591cff5f"
}
},
"timestamp": "2024-11-10T02:33:55.935335Z",
"severity": "INFO",
"logName": "projects/qwiklabs-gcp-04-d815591cff5f/logs/requests",
"trace": "projects/qwiklabs-gcp-04-d815591cff5f/traces/79b3ae5b1f06327dbe9398c7c152990d",
"receiveTimestamp": "2024-11-10T02:33:59.199281030Z",
"spanId": "8c20fdb741895b08"
}
このスクラップは16日前にクローズされました