The observability map
Each hop on a shopper's path has its own record. Click a signal to see where it sits, what it can answer, and what it cannot:
Can answer
- Every request: URL, status, latency
- Who answered (statusDetails)
- Which Cloud Armor rule matched
Cannot answer
- What happened inside kade-api
- Requests Cloudflare stopped at the edge
On by default? off: turn on per backend service. Volume: 1 entry per request (sample to reduce).
Load balancer logs: one line per request
Each request through the load balancer can produce one log entry, written by Google's front end. It records what the shopper asked, what came back, how long it took, and who produced the answer (chapter 12 section 10). Logging is set per backend service, with a sample rate between 0 and 1.
Each tab is one real kind of entry, with its important fields picked out:
{ one load balancer log entry, simplified
- httpRequest.requestMethod: "POST"
- httpRequest.requestUrl: "https://api.kade.lk/v1/orders"
- httpRequest.status: 200
- ← what came back
- httpRequest.latency: "0.184s"
- ← total time at the LB
- httpRequest.remoteIp: "104.23.211.40"
- ← a Cloudflare edge, not the shopper
- jsonPayload.statusDetails: "response_sent_by_backend"
- ← kade-api answered
- jsonPayload.enforcedSecurityPolicy.outcome: "ACCEPT"
- jsonPayload.enforcedSecurityPolicy.priority: 2147483647
- ← default rule allowed it
- resource.labels.backend_service_name: "kade-api-backend"
A normal request: the backend answered (response_sent_by_backend) in 184 ms, and Cloud Armor's default rule allowed it. Note remoteIp is a Cloudflare address; the shopper's IP is in the app's own log.
| # | Field | What it tells you |
|---|---|---|
| 1 | httpRequest.status, requestUrl, requestMethod | What was asked and what came back |
| 2 | httpRequest.latency | Total time at the load balancer, from first byte in to last byte out |
| 3 | httpRequest.remoteIp | The client Google saw. Behind Cloudflare, that is a Cloudflare address (chapter 13) |
| 4 | jsonPayload.statusDetails | Who answered: the backend, the cache, Cloud Armor, or nobody (no healthy backend, timeout) |
| 5 | jsonPayload.enforcedSecurityPolicy | Which Cloud Armor rule matched, its priority and outcome. previewSecurityPolicy shows rules in preview mode |
| 6 | resource.labels.backend_service_name | Which backend service the URL map chose |
Cloud Run logs: the request log and the app's own lines
Cloud Run writes two kinds of entry for kade-api, both under resource.type="cloud_run_revision":
| # | Log | Written by | Contains |
|---|---|---|---|
| 1 | Request log (run.googleapis.com/requests) | Cloud Run itself, for every request | Status, latency, instance, URL. Like the load balancer log, but from Cloud Run's side, so it also catches cold starts and container crashes |
| 2 | App log (stdout and stderr) | kade-api's own code | Whatever the app prints. Printed as JSON, fields like severity and a trace ID become searchable |
VPC Flow Logs: connections inside the VPC
Flow logs are switched on per subnet. They record a sample of connections to and from addresses in that subnet: who talked to whom, on which ports, how many bytes and packets, and for TCP, the round-trip time. They never contain the content.
| # | Setting | What it means | Kadé's value |
|---|---|---|---|
| 1 | Aggregation interval | Records are summed over this window before being written | 5 s (default) for sn-run and sn-app; longer windows mean fewer, coarser records |
| 2 | Flow sampling | The share of connections recorded (0 to 1) | 0.5 (default). Enough to see patterns; not every connection |
| 3 | Metadata | Extra details: VM names, regions, countries for internet addresses | All metadata; it is what makes records readable |
| 4 | Filter | A condition that drops records before they are written | None yet; useful later to keep only traffic to PayGate or the office |
Firewall rule logs and Firewall Insights
Logging is a setting on each firewall rule (chapter 5.1 used --enable-logging). When on, every connection the rule allows or denies is recorded with the rule's name, which answers "which rule let this in?" and "which rule blocked this?".
| # | Fact | What it means |
|---|---|---|
| 1 | Only TCP and UDP connections are logged | Ping (ICMP) never appears |
| 2 | The implied rules cannot be logged | Traffic dropped by the implied deny ingress leaves no trace. To see what is being denied, add an explicit "deny all" ingress rule at priority 65534 with logging on |
| 3 | One record per connection, not per packet | Volume follows connection count, which is far lower than packet count |
| 4 | Firewall Insights | Uses the hit counts to point out rules that are shadowed, never used, or allow far more than the traffic needs (chapter 5.2) |
NAT, DNS, Cloud SQL, and Cloudflare
| # | Signal | Turn on | Answers | Chapter |
|---|---|---|---|---|
| 1 | Cloud NAT logs | Errors only | "Are PayGate calls being dropped?" allocation_status: DROPPED means ports ran out | 7 |
| 2 | Cloud DNS query logs | A server policy on kade-vpc with logging | "What names does this VM look up?" Useful to spot a compromised VM, or a typo in a hostname | 8 |
| 3 | Cloud SQL logs | On by default (PostgreSQL log), plus flags such as log_connections | "Are connections being refused? Is a query slow?" | 9 |
| 4 | Cloudflare analytics and logs | Dashboard analytics on every plan; Logpush on higher plans | Requests stopped at the edge never reach GCP, so only Cloudflare knows about them. Join with GCP by CF-Ray | 13 |
| 5 | Ops Agent (VMs only) | Installed on the VM, ideally baked into the image | Memory and disk usage, and the VM's system and app log files. Without it, Google only sees CPU, network and disk throughput from outside the VM | 12.2 |
| 6 | Audit logs | Admin Activity always on; Data Access off by default | "Who deleted that firewall rule?" Admin Activity records every configuration change, free | 17 |
Cost, retention and where logs go
Logs are billed by volume, and volume grows with users. A setting that is harmless at 1,000 requests a day can be a real bill at 1,000,000. Estimate before you turn things on:
- Load balancer, API (100%)17.2 GiB
- Load balancer, images (10%, 200s excluded)0.2 GiB
- Cloud Run request logs (API)11.4 GiB
- App logs (≈2 lines per API request)13.7 GiB
- VPC Flow Logs (sampling 0.5)5.1 GiB
- Firewall rule logs1.4 GiB
≈ 49.1 GiB per month with Kadé's settings. Everything at 100% with no exclusions: ≈ 139.9 GiB. Compare with the free monthly allotment and price per GiB on the Cloud Logging pricing page.
Assumed entry sizes: load balancer 1.5 KB, Cloud Run request 1 KB, app line 0.6 KB, flow record 1.2 KB, firewall 1 KB. Measure yours after a day: Logs Storage in the console shows volume per log.
| # | Tool | What it does | Use for |
|---|---|---|---|
| 1 | Sample rate | Records only a share of requests or connections | Load balancer logs on very busy paths, flow logs |
| 2 | Exclusion filter | Drops matching entries before they are stored (and billed) | Health check noise, successful requests for static images |
| 3 | Log bucket retention | How long entries are kept. The default bucket keeps 30 days | Longer only where needed (security, payments) |
| 4 | Sink to Cloud Storage or BigQuery | Copies entries out for cheap long-term storage or SQL analysis | Keeping a year of load balancer logs for audits |
| 5 | Log Analytics | Run SQL directly on a log bucket | "Top 20 IPs hitting /api/login this week" in one query |
Query cookbook
Ready-to-paste Logs Explorer queries, organized by the question you are asking. Each shows what it finds and what to look for:
resource.type="http_load_balancer" httpRequest.status>=500
- What it shows: Every 5xx at the front door.
- What to look for: Group mentally by jsonPayload.statusDetails: backend errors, timeouts, or no backend.
Back to Kadé
Commands in this chapter
Commands 1 and 2 are read-only. Commands 3 to 7 change the project.
Is logging on for each backend service?
- What it shows: Logging on or off, and the sample rate, for every backend service.
- What to look for:
Falseor an empty value on anything public-facing.
gcloud compute backend-services list \ --format="table(name,logConfig.enable,logConfig.sampleRate)"Which subnets have flow logs, and which firewall rules log?
- What it shows: Flow log settings per subnet, then logging per firewall rule.
- What to look for: Gaps against section 09's table.
gcloud compute networks subnets list --network=kade-vpc \ --format="table(name,logConfig.enable,logConfig.flowSampling,logConfig.aggregationInterval)"gcloud compute firewall-rules list --filter="network~kade-vpc" \ --format="table(name,direction,priority,logConfig.enable)"Turn on load balancer logging (changes the project)
- What it shows: Logs every request through kade-api-backend.
- What to look for: Entries under
resource.type="http_load_balancer"within a minute.
gcloud compute backend-services update kade-api-backend --global \ --enable-logging --logging-sample-rate=1.0Turn on flow logs for a subnet (changes the project)
- What it shows: Sampled connection records for sn-run, with metadata.
- What to look for: Entries under
logName:"vpc_flows"after a few minutes of traffic.
gcloud compute networks subnets update sn-run --region=asia-southeast1 \ --enable-flow-logs --logging-flow-sampling=0.5 \ --logging-aggregation-interval=interval-5-sec --logging-metadata=include-allLog what the implied deny would drop (changes the project)
- What it shows: An explicit, logged "deny everything" ingress rule just above the implied one. It changes no behaviour, only adds the record.
- What to look for: Denied connections with
rule_details.referenceending inkade-deny-all-log.
gcloud compute firewall-rules create kade-deny-all-log --network=kade-vpc \ --direction=INGRESS --action=DENY --rules=all --source-ranges=0.0.0.0/0 \ --priority=65534 --enable-loggingExclude successful image requests from load balancer logs (changes the project)
- What it shows: An exclusion on the default sink: these entries are dropped before storage.
- What to look for: Log volume for http_load_balancer falls the next day. Errors on images are still kept.
gcloud logging sinks update _Default --add-exclusion=name=lb-image-200s,\filter='resource.type="http_load_balancer" AND httpRequest.requestUrl:"/images/" AND httpRequest.status=200'Send load balancer logs to BigQuery (changes the project)
- What it shows: A sink copying load balancer entries to a dataset for long-term SQL analysis.
- What to look for: The sink's writer identity needs BigQuery Data Editor on the dataset; the command prints it.
gcloud logging sinks create kade-lb-to-bq \ bigquery.googleapis.com/projects/kade-prod/datasets/kade_lb_logs \ --log-filter='resource.type="http_load_balancer"' --use-partitioned-tables