Brains4Cloud
ESEN
Practice

Topic 10 of 10

D3 · Ensuring the successful operation of a cloud solution

Diagnostics, optimization, and service health

Section 3.4 ends with diagnostics: finding bottlenecks in applications and queries, and telling whether a problem is yours or Google Cloud's with Personalized Service Health and Cloud Hub.

Which tool to use

QuestionTool
Where does a request spend its time across services?Cloud Trace
Which part of the code uses the most CPU or memory?Cloud Profiler
Which exceptions are failing, and since when?Error Reporting
Which SQL query is slow or loading the database?Query insights (Cloud SQL, Spanner)
Is it a Google Cloud incident?Personalized Service Health
How is everything doing overall?Cloud Hub

Cloud Trace

A distributed tracing system that measures end-to-end request latency and pinpoints which dependency causes delays in a microservices architecture (including generative AI applications). It runs on Compute Engine, GKE, App Engine, Cloud Run, and outside Google Cloud.

  • Automatic on Cloud Run and Cloud Run functions for incoming and outgoing HTTP requests, and on App Engine standard.
  • To instrument code, Google recommends OpenTelemetry instead of the Trace client libraries.
  • Trace Explorer shows a latency heatmap and each trace in detail. Observability Analytics lets you join traces and logs with SQL.
  • Spans are kept for 30 days in the _Trace bucket. A trace scope aggregates traces from several projects.

Cloud Profiler

A statistical, low-overhead profiler that continuously gathers CPU usage and memory allocation from applications in production and attributes it to the source code that generated it.

  • Languages: Go, Java, Node.js, and Python. Profile types depend on the language: CPU time, heap, allocated heap, contention, threads, and wall time.
  • You add a language-specific profiling agent to the application. It runs on Compute Engine, GKE, App Engine, and outside Google Cloud.
  • Overhead is under 5% during collection and usually under 0.5% on average, so you can leave it always on.

Error Reporting

Aggregates and displays errors from running services in a centralized interface so you can find new or top errors. Errors are sent by writing them to Cloud Logging with the right format or by calling the Error Reporting API. It requires the logs to be stored in log buckets. For Android and iOS apps Google recommends Firebase Crashlytics.

Query insights detects and diagnoses query performance problems: it shows database load per query, lets you identify a problematic query or tag, and examine a trace from a sample query. It traces the source by model, view, controller, route, user, and host. By default it shows completed queries; active queries are shown in real time.

gcloud sql instances patch my-instance --insights-config-query-insights-enabled
CapabilityEnterpriseEnterprise Plus
Metrics retention7 days30 days
Maximum query length4500 bytes100 KB
Query plans per minute20200
Wait events, index advisor, terminate sessions, AI assistanceNoYes

The Cloud SQL for PostgreSQL index advisor periodically analyzes your regular queries and recommends new indexes with their CREATE INDEX command, estimated size, and query impact. It requires Enterprise Plus edition with Enterprise Plus query insights; it doesn't work on read replicas. Role to view recommendations: roles/cloudsql.viewer.

In addition, Cloud SQL Enterprise Plus recommenders detect instances that would benefit from near-zero maintenance downtime or data cache.

Detects and diagnoses query and DML performance problems: it checks whether inefficient queries cause high CPU usage and identifies the responsible query or request tag. It works in regional and multi-region configurations, has no additional cost, and keeps data for up to 30 days.

Personalized Service Health

Identifies the Google Cloud service health events relevant to your projects (incidents and their status per product and location). It's the primary channel for incident information about your projects; the public Cloud Service Health dashboard is general.

AccessWhat for
Service Health dashboardActive and past incidents for your projects or organization, also on mobile
Service Health APIGet events and their details per project or organization
AlertsLog-based notifications: new incidents, updates, or incidents for specific products or locations
LogsEvents are logged in Cloud Logging and can be exported

Organization views aggregate incidents across all projects. Permission to list events: servicehealth.events.list.

Cloud Hub

A centralized view of operations data for your applications and resources, by project or by App Hub application.

PageWhat it shows
Health & troubleshootingOpen Cloud Monitoring alerts, active Google Cloud incidents, and health metrics
DeploymentsFailed Application Design Center deployments and available updates
Security & complianceCritical and high Security Command Center findings and compliance frameworks
OptimizationTotal cost and trend, most expensive resources, and expensive ones with low utilization
Quotas & reservationsQuotas above 90% usage, forecasted Compute Engine usage, and reservations
MaintenanceUpcoming, in-progress, and completed maintenance; some can be rescheduled
SupportOpen support cases and your support package

Exam scenarios

SituationAnswerWhy
Find out which microservice adds latency to a requestCloud TraceEnd-to-end latency for each hop.
Discover which function in the code uses the most CPU in productionCloud ProfilerContinuous, low-overhead profiling.
See an app's new and most frequent errors, groupedError ReportingAggregates errors from running services.
Find the query that overloads a Cloud SQL for PostgreSQL instanceQuery insightsDatabase load per query, tag, and plan.
Get index recommendations for Cloud SQL for PostgreSQLIndex advisorRequires Enterprise Plus and Enterprise Plus query insights.
Know whether a Google Cloud incident affects your projects and get alertsPersonalized Service HealthDashboard, API, alerts, and event logs.
See alerts, incidents, near-exhausted quotas, and maintenance on one pageCloud HubCentralized operations view.
Find out whether inefficient queries cause high CPU in SpannerSpanner query insightsNo extra cost; 30 days of data.

Common exam traps

❓ Cloud Trace or Cloud Profiler to see which service delays a request?

Cloud Trace. Profiler measures CPU and memory consumption inside a service's code.

❓ Is Cloud Profiler only for test environments?

No. It's designed for production: its overhead is usually under 0.5%.

❓ Is index advisor available in Cloud SQL Enterprise edition?

No. It requires Enterprise Plus with Enterprise Plus query insights, and it doesn't work on read replicas.

❓ Do you need to instrument Cloud Run to see HTTP request latency in Trace?

Not for the basics: Cloud Run and Cloud Run functions send HTTP request latency automatically.

❓ Does the public Cloud Service Health dashboard tell you which incidents affect your projects?

Not in the same way. Personalized Service Health shows events relevant to your projects and supports alerts.

❓ How long does Cloud Trace keep spans?

30 days in the _Trace bucket.

Did you get this topic?

Test what you just learned

Users notice that checkout in a microservices app on GKE takes 4 seconds. You need to know which of the six services involved in the request causes the delay. What do you use?

Ready to test "Diagnostics, optimization, and service health"?

Original questions, each with a full explanation.

Start a mock exam