GCP Associate Cloud Engineer Practice Question 58: Log Based Counter Metric

Google Cloud Associate Cloud Engineer · Test 6 · question 8 of 10

Cloud Loggingmedium

A team's application writes a specific error message to stdout whenever a downstream payment API call fails. The team wants to track how often this error occurs over time on a Cloud Monitoring dashboard and receive an alert if it happens more than 10 times in 5 minutes. The application code cannot be modified. What should they do?

Select one answer
Show answer and explanation

Answer:

  • D. In Cloud Logging, create a counter-type log-based metric using a filter that matches the error message text, then build a chart and alerting policy on that metric in Cloud Monitoring.

A counter-type log-based metric counts the number of log entries that match a given filter, with no changes to the application required since it reads from the logs the app already writes to stdout. The resulting metric appears under logging.googleapis.com/user/ and can be charted and used directly as the condition for a Cloud Monitoring alerting policy, which meets both requirements with the least effort.

A is wrong because an uptime check only tests whether an HTTP endpoint responds; it cannot detect a specific error message written to application logs. B is wrong because scheduling a BigQuery query to count errors adds unnecessary latency, cost, and operational overhead for a need that Cloud Logging already serves natively, and it does not produce a metric that Cloud Monitoring alerting policies can consume directly. C is wrong because routing logs to Pub/Sub and writing a custom Cloud Function to increment a metric duplicates functionality that a counter log-based metric already provides out of the box, adding unneeded complexity and code to maintain.

Reference: Logs-based metrics overview

Practice Test 6 ›

Study guides for Google Cloud Associate Cloud Engineer