An application deployed on Google Cloud outputs structured JSON logs to Cloud Logging. An Operations SRE must configure an automated real-time notification whenever the system generates more than 50 HTTP 500 error responses within a 5-minute rolling window. Which approach follows Google Cloud recommended practices to achieve this objective?
- Create a custom log-based counter metric in Cloud Logging using a filter for HTTP status code 500, and then create a Cloud Monitoring alerting policy based on that metric.Answer
- BDeploy the legacy Stackdriver Logging agent to parse raw container logs into standard system metrics, and attach a built-in threshold alert.
- CGrant the primitive Owner role to the Cloud Logging service account in the project IAM settings so it can automatically dispatch alert notifications.
- DEnable the Cloud Logging API at the organization level and revoke the Logs Viewer role at the project level to force alert triggers.
Answer
The correct approach is to create a custom log-based counter metric in Cloud Logging filtered for HTTP status code 500, and configure a Cloud Monitoring alerting policy conditioned on this metric.
Log-based metrics bridge Cloud Logging and Cloud Monitoring by turning log data matching a specific query filter (such as HTTP status code 500) into numerical metric time series. SREs can then attach standard Cloud Monitoring alerting policies to these metrics to trigger notifications when thresholds are breached.
Step-by-Step Solution
Key Concept
Custom Log-based Metrics and Alerting Policies
Estimated Time:2m 0s