hardMultiple ChoiceObjective-mapped
Creating MQL Ratio Alert: Error Rate Exceeding 5% per Endpoint
A company uses Cloud Monitoring with custom metrics. They have a custom metric called 'requests_total' with labels 'endpoint', 'status_code'. They want to create an alert that fires if the error rate (status_code >=500) for any endpoint exceeds 5% over a 5-minute window. Which MQL query should they use?
Quick Answer
The correct MQL query is: fetch custom::requests_total | { filter status_code >= 500 ; group_by [endpoint], sum() } / { group_by [endpoint], sum() } | condition gt 0.05. This works because it first isolates error responses by filtering for status codes of 500 or higher, then uses a ratio join—the curly-brace syntax—to divide the error count per endpoint by the total request count per endpoint, yielding a precise error rate for each endpoint over the 5-minute window. On the Google Professional Cloud Developer exam, this question tests your ability to construct MQL ratio alerts with label-based grouping, a common scenario for monitoring microservice health. A frequent trap is forgetting that both the numerator and denominator must use the same group_by clause to maintain per-endpoint alignment; using a single group_by on the entire pipeline would compute a global rate instead. Memory tip: think of the curly braces as two separate “buckets” that you divide—errors on top, total on bottom—with group_by ensuring each endpoint stays in its own lane.
⚠ Common exam trap
The PCD exam often tests the distinction between `ratio` (which operates on the number of time series) and explicit division with group_by (which operates on metric values per label), leading candidates to incorrectly choose a `ratio`-based query that ignores per-endpoint grouping.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
fetch custom::requests_total | { filter status_code >= 500 ; group_by [endpoint], sum() } / { group_by [endpoint], sum() } | condition gt 0.05
It first filters for error responses (status_code >= 500), then groups by endpoint and sums the error count, and divides that by the total count per endpoint (also grouped and summed). This computes the error rate per endpoint, and the condition fires when that rate exceeds 0.05 (5%) over the 5-minute window. The use of two separate group_by operations within a join (the `{ ... } / { ... }` syntax) is the correct MQL pattern for calculating a ratio per label.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
fetch custom::requests_total | { filter status_code >= 500 ; group_by [endpoint], sum() } / { group_by [endpoint], sum() } | condition gt 0.05
Why this is correct
Correct: groups errors and total by endpoint, divides, and applies condition.
- ✗
fetch custom::requests_total | filter status_code < 500 | ratio | condition gt 0.05
Why it's wrong here
Filters for success codes, not errors.
- ✗
fetch custom::requests_total | group_by [endpoint], sum() | filter status_code >= 500 | ratio | condition gt 0.05
Why it's wrong here
Sums all counts first, then filters; invalid order.
- ✗
fetch custom::requests_total | filter status_code >= 500 | ratio | condition gt 0.05
Why it's wrong here
Missing group_by; would compute a global ratio, not per endpoint.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCD question from scratch — 964 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCD
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A company has a Cloud Run service that uses Cloud SQL. They notice that the number of database connections is increasing over time, causing connection pool exhaustion. They have enabled Cloud Monitoring and see a custom metric for active DB connections. To proactively alert when the connection count exceeds 80% of the maximum pool size (which is 100), which alerting approach is most efficient?
hard- A.Create a metric threshold alert on the custom metric with condition > 80.
- B.Create a forecast alert to predict when connections will exceed 80.
- C.Create an alert on the Cloud SQL system metric for 'cloudsql.googleapis.com/database/connections/num_failed_reserved'.
- ✓ D.Create a ratio alert using an MQL query that divides the active connections by the max connections and alerts when > 0.8.
Why D: It creates a ratio alert using MQL to divide the active connections by the maximum pool size (100), triggering when the ratio exceeds 0.8 (80%). This directly measures the utilization of the connection pool, which is the most efficient way to alert on impending exhaustion. It avoids hardcoding a static threshold that would break if the pool size changes, and it uses the custom metric already being monitored.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCD practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCD exam.