Google Professional Cloud Developer

Google Professional Cloud Developer

Get started today

Ultimate access to all questions.


To retrieve the count of all requests to endpoints matching /api/alpha/* in Stackdriver logs, what steps should you follow?

(Optional code block if applicable, corrected for syntax/typos):

# Example filter for Stackdriver Logging query  
resource.type="gae_app"  
logName="projects/[PROJECT_ID]/logs/appengine.googleapis.com%2Frequest_log"  
jsonPayload.resource LIKE "/api/alpha/%"  

What is the correct approach to achieve this?




Explanation:

To accurately count all requests to endpoints under /api/alpha/*, the most efficient method is to utilize Stackdriver's log-based metrics. This involves creating a counter metric that filters log entries based on the request path. Option A suggests using a filter for path:/api/alpha/, which is the correct approach as it will match all subpaths under /api/alpha/. This method is real-time and does not require exporting logs to external services like Cloud Storage or Cloud Pub/Sub, which are less efficient and not suitable for real-time counting. Therefore, option A is the correct answer.