Google Associate Cloud Engineer Question 301
Single answerGoogle Cloud PlatformAs a Google Cloud Associate Cloud Engineer, you are tasked with analyzing logs to troubleshoot an issue with a specific application running on Google Kubernetes Engine (GKE). The application logs are being collected in Google Cloud Logging. You need to filter the logs to show only the ERROR level logs for the application 'my-app'. Which of the following queries would you use in the Logs Explorer to achieve this?
- A
resource.type="gke_cluster" AND labels.k8s-pod/component="my-app" AND severity="ERROR"
- B
resource.type="gke_cluster" AND logName="projects/my-project/logs/my-app" AND severity="ERROR"
- C
resource.type="gce_instance" AND labels.app="my-app" AND severity="ERROR"
- D
resource.type="gke_cluster" AND jsonPayload.message="ERROR" AND labels.k8s-pod/component="my-app"
Show answer and explanation
Correct answer: A
Explanation
Filtering logs in Cloud Logging requires specifying the correct resource type, labels, and log level. The correct query should filter logs for the specific GKE application component by using the appropriate labels and severity level. The first option correctly uses the GKE cluster resource type, labels the application's component, and filters for the 'ERROR' severity, making it the correct choice.
- A. Correct.
This option correctly filters logs for the GKE cluster resource type, includes the component label specific to 'my-app', and filters for logs with severity 'ERROR'.
- B. Incorrect.
This option incorrectly uses the logName field, which is not specific enough to filter by log severity or application component.
- C. Incorrect.
This option is incorrect because it specifies the GCE instance resource type instead of GKE cluster, which doesn't match the context of the application running on GKE.
- D. Incorrect.
This option incorrectly uses jsonPayload.message to filter for 'ERROR'; severity should be used instead when filtering by log level.