Chapters

Observability 2: monitoring, alerting and troubleshooting

Logs (chapter 16.1) tell you what happened to one request. Running a platform also needs the opposite view: is everything healthy right now, will someone be told when it is not, and once told, where do they look first? This chapter covers the few metrics worth watching, uptime checks, alerts people do not learn to ignore, Google's network troubleshooting tools, and a routine for the incidents Kadé is most likely to have.

Running it · chapter 23 of 26 · 7 min read

The few metrics that matter

Logs are records of events; metrics are numbers sampled over time, cheap to keep and fast to chart. GCP collects most of them automatically, at no charge for Google's own services. For a web platform, four "golden signals" measured at the front door cover most of what users feel:

#Golden signalQuestionMetric (Cloud Monitoring)
1TrafficHow busy are we?loadbalancing.googleapis.com/https/request_count
2ErrorsWhat share of requests fail?The same, split by response_code_class (5xx divided by all)
3LatencyHow slow are the slow requests?https/total_latencies, at the 95th and 99th percentile, not the average
4SaturationHow close to a limit are we?Cloud Run container/instance_count against max instances, Cloud SQL connections, NAT ports
Measure at the load balancer, because that is what shoppers experience. The backend's own numbers miss requests that never reached it.

Below the front door, a handful of metrics catch the network failures from this course before users report them:

#MetricCatchesChapter
1router.googleapis.com/nat/dropped_sent_packets_count (reason OUT_OF_RESOURCES)PayGate calls failing because NAT ports ran out7
2cloudsql.googleapis.com/database/postgresql/num_backendsConnections approaching the database's limit9
3run.googleapis.com/container/instance_countkade-api pinned at max instances, so requests queue10
4loadbalancing.googleapis.com/https/backend_latenciesSlowness inside kade-api rather than on the way to it12
5compute.googleapis.com/instance_group/size against the target sizeA managed instance group stuck below its size: a boot loop or a quota (chapter 12.2)12.2
6agent.googleapis.com/memory/percent_used (needs the Ops Agent)VMs running out of memory before they crash16.1
7vpn.googleapis.com/tunnel_establishedA VPN tunnel down (the other carries on, so nobody notices)15

One dashboard: "is the platform healthy?"

One page, read top-left to bottom-right, that answers the question in ten seconds. Each panel is one metric from section 01:

Requests per secondnormal: busy, steady13:0014:205xx error ratio (%)rises at 14:0013:0014:20p95 latency (ms)normal13:0014:20Cloud Run instances / maxplenty of room13:0014:20NAT drops (OUT_OF_RESOURCES)rises at 14:0013:0014:20Cloud SQL connections / maxnormal13:0014:20

Top row: what shoppers feel. Bottom row: how close to a limit. Dashed red: the alert threshold. Dotted: 14:00.

Uptime checks: is the shop reachable from outside?

An uptime check calls a URL from several places around the world every minute or few, and records whether the right answer came back. It is the closest thing to a shopper trying the site, and it works even when no shopper is online. It can also warn before the certificate expires.

Kadé's front door now has Cloudflare and an origin lock (chapter 13), and both will treat a robot from Google's data centres with suspicion. Pick what to check, and see what blocks it:

What if
Uptime checker3 regions,every minuteCloudflarepasses it on,adds headerLB + Cloud Armororigin lockpassesCloud Run/v1/health→ 200 ok1 request2 to origin3 to app

Check passes: the whole front door works

The checker calls https://api.kade.lk/v1/health exactly like a shopper: Cloudflare, the load balancer, Cloud Armor (the request carries Kadé's secret header because it came through Kadé's zone), then Cloud Run. If any hop fails, the check fails. That is what you want: it tests the whole front door.

Show as config
URL: https://api.kade.lk/v1/health
Regions: asia-pacific, europe, usa-oregon
Expect: HTTP 200, body contains "ok"
Also: alert if the certificate expires within 14 days

Alerts that people do not learn to ignore

An alert that fires for nothing teaches you to ignore alerts. Three habits keep them meaningful:

#HabitWhy
1Alert on symptoms users feel"5% of requests fail" is something to act on. "CPU at 80%" often is not
2Use ratios, not counts50 errors in a minute is a disaster at 100 requests and nothing at 100,000. The error ratio stays meaningful as traffic grows
3Require a duration"Above the threshold for 5 minutes" ignores single spikes. The chart below shows the difference
What if
threshold 2%0 min10 min20 min30 min40 min0%2%4%6%spike: fires, clearsreal problem: fires

The one-minute spike at 10 minutes (a deploy, a single bad client) fires an alert, then clears by itself. The real problem at 24 minutes fires too. Get a few of the first kind a week and you start ignoring both.

Show as config
Condition: loadbalancing.googleapis.com/https/request_count, 5xx / all
Threshold: > 2%
Duration: 5 minutes (the "for" window)

Kadé's alert set. Few enough that each one gets attention:

#AlertConditionSends to
1Shop unreachableUptime check failing from 2 or more regions for 2 minutesphone
2Errors highLoad balancer 5xx above 2% of requests for 5 minutesphone
3Slowp95 total latency above 1.5 s for 10 minutesphone
4Payments at riskNAT drops with OUT_OF_RESOURCES above 0 for 5 minutesphone
5Database near its limitConnections above 80% of max for 10 minutesemail / chat
6VPN tunnel downEither tunnel not established for 5 minutesemail / chat
7Certificate expiringUptime check: certificate expires within 14 daysemail / chat
8Attack in progressCloud Armor denies 10 times above normal for 15 minutes (log-based metric)email / chat
"Phone" alerts mean shoppers are affected now. "Email / chat" alerts mean something needs attention today. A budget alert on the billing account belongs in the second group too.

Network Intelligence Center

Google's network troubleshooting tools, in one place in the console. They work from configuration and Google's own measurements, so most need no logs:

#ToolAnswersWhen to use it
1Connectivity Tests"Can A reach B on this port, and if not, which rule or route stops it?"Before and after every firewall or route change, and first in any "can't connect" incident
2Network TopologyA live map of networks, subnets, load balancers and the traffic between themUnderstanding an unfamiliar project
3Network AnalyzerProblems it finds by itself: unused reserved IPs, subnets running out of addresses, risky configurationsA weekly glance
4Firewall InsightsShadowed, unused and overly broad firewall rulesMonthly clean-up (chapter 5.2)
5Performance DashboardPacket loss and latency between zones and regions, and to the internet, measured by Google"Is it us or is it Google?"
6Flow AnalyzerQueries over VPC Flow Logs without writing SQL"Top talkers" from a subnet

A Connectivity Test traces a pretend packet through every check this course covered, using the real configuration, without sending anything. Two tests from Kadé:

  1. StartVM kade-worker 10.10.1.20 in sn-app
  2. Egress firewallimplied allow egress (65535)
  3. Route10.10.32.0/20 via peering servicenetworking-googleapis-com
  4. Forwardinto Google's service network
  5. DeliverCloud SQL kade-sql 10.10.32.3:5432

Result: REACHABLE

Every check passes, and the test names the exact route it used. Saved, it becomes a one-click check after any change to routes, peering or firewall.

Troubleshooting routines

For each common symptom, the order of steps that finds the cause fastest. Each step has the check, what the result means, and where it leads next:

  1. 1.

    Is it only us?

    Uptime check results by region; Cloudflare status page

    What the result means: All regions failing: likely the whole front door. One region: a local internet problem, usually not yours.

    Next: If all regions fail, go to step 2.

  2. 2.

    Does Cloudflare reach the origin?

    curl -sI https://api.kade.lk/v1/health (look for a 52x code)

    What the result means: A 52x page means Cloudflare is up but the origin leg failed. Read the code with chapter 13's error decoder.

    Next: No 52x but nothing loads: check DNS (dig +short api.kade.lk) and Cloudflare. A 52x: step 3.

  3. 3.

    What does the load balancer say?

    Logs: resource.type="http_load_balancer" httpRequest.status>=500, read statusDetails

    What the result means: failed_to_pick_backend: no backend. denied_by_security_policy: Cloud Armor. Nothing logged at all: requests are not reaching the LB (origin lock, certificate, forwarding rule).

    Next: No backend: step 4.

  4. 4.

    Is kade-api serving?

    gcloud run revisions list --service=kade-api --region=asia-southeast1

    What the result means: The latest revision not ready, or failing to start, means a bad deploy.

    Next: Roll back: gcloud run services update-traffic kade-api --to-revisions=LAST_GOOD_REVISION_NAME=100

Rollout plan

For a platform that has none of this today, in order of value for effort. Each stage is useful on its own, so stopping early still leaves you better off:

  1. 1.Day 1

    about an hour

    • Load balancer logging on (100% API, 10% images)
    • Uptime check on the health URL, through Cloudflare
    • Alert: shop unreachable, to your phone
    • Budget alert on the billing account
  2. 2.Week 1

    a few hours

    • Dashboard: the six panels from section 02
    • Alerts: error ratio, p95 latency, NAT drops
    • App logs as JSON with trace ID and CF-Ray
    • Cloud NAT error logs on
  3. 3.Month 1

    spread out

    • Flow logs on the subnets that carry database and PayGate traffic
    • Firewall rule logging + the deny-all-log rule
    • Connectivity Tests saved for the key paths
    • Exclusion filters and a BigQuery sink, after a week of measuring volume
  4. 4.Later

    when the basics are quiet

    • An SLO with burn-rate alerts instead of fixed thresholds
    • Log Analytics queries for weekly security review
    • Cloudflare Logpush joined to GCP logs by CF-Ray

Back to Kadé

Commands in this chapter

Commands 1 to 3 are read-only. Commands 4 to 6 change the project.

Find the IP ranges uptime checks come from

  • What it shows: The source addresses of Google's uptime checkers, by region.
  • What to look for: Only needed if you check the origin directly and must allow them (section 03).
gcloud monitoring uptime list-ips

Run a Connectivity Test and read the result

  • What it shows: Whether kade-worker can reach Cloud SQL on 5432, and the step that decides it.
  • What to look for: REACHABLE, or the step where it says DROPPED and why.
gcloud network-management connectivity-tests create worker-to-sql \  --source-instance=projects/kade-prod/zones/asia-southeast1-a/instances/kade-worker \  --destination-ip-address=10.10.32.3 --destination-port=5432 --protocol=TCPgcloud network-management connectivity-tests describe worker-to-sql \  --format="yaml(reachabilityDetails.result,reachabilityDetails.traces[0].steps)"

List alert policies

  • What it shows: Every alert policy and whether it is enabled.
  • What to look for: The eight from section 04, all enabled, each with a notification channel.
gcloud alpha monitoring policies list --format="table(displayName,enabled,notificationChannels.len())"

Create an uptime check (changes the project)

  • What it shows: An HTTPS check of the health URL, every minute, from three regions, expecting a 200.
  • What to look for: Results in the console under Monitoring → Uptime checks within a few minutes.
gcloud monitoring uptime create kade-api-health \  --resource-type=uptime-url --resource-labels=host=api.kade.lk,project_id=kade-prod \  --protocol=https --path=/v1/health --period=1 \  --regions=asia-pacific,europe,usa-oregon --status-codes=200

Count Cloud Armor denies as a metric (changes the project)

  • What it shows: A log-based metric that counts denied requests, which alert 8 can watch.
  • What to look for: The metric logging.googleapis.com/user/kade_armor_denies in Metrics Explorer after some traffic.
gcloud logging metrics create kade_armor_denies \  --description="Requests denied by Cloud Armor" \  --log-filter='resource.type="http_load_balancer" AND jsonPayload.enforcedSecurityPolicy.outcome="DENY"'

Create a notification channel (changes the project)

  • What it shows: An email channel for "email / chat" alerts. Phone and chat apps are added the same way, or in the console.
  • What to look for: The channel's ID in the output, used when creating alert policies.
gcloud beta monitoring channels create --display-name="Kadé platform email" \  --type=email --channel-labels=email_address=platform@kade.lk

Spotted a mistake, or something unclear? Suggest an edit on GitHub