An organization is monitoring an API gateway using Azure Application Insights. You need to write an optimized Kusto Query Language (KQL) query that calculates the success rate (percentage of successful requests) of HTTP requests received in the last 24 hours.
Which two of the following KQL queries will achieve this requirement efficiently?
- requests
| where timestamp > ago(24h)
| summarize SuccessRate = countif(success == true) * 100.0 / count()Answer - Brequests
| summarize SuccessRate = countif(success == true) * 100.0 / count()
| where timestamp > ago(24h) - requests
| where timestamp > ago(24h)
| summarize SuccessCount = countif(success), TotalCount = count()
| project SuccessRate = (todouble(SuccessCount) * 100.0) / TotalCountAnswer - Drequests
| summarize SuccessCount = countif(success == true), TotalCount = count()
| project SuccessRate = (todouble(SuccessCount) * 100.0) / TotalCount
Answer
The correct queries filter by timestamp in the first stage of the query pipeline using the 'where timestamp > ago(24h)' clause, and then use either direct division or the project operator to calculate the percentage of successful requests.
The correct queries prioritize performance by placing the time-range filter 'where timestamp > ago(24h)' as the very first operator after the 'requests' table. They then successfully calculate the ratio of successful requests to total requests. The query with direct division computes the percentage in a single summarize block, while the query using the project operator divides the step into distinct summarize and project stages, both of which are valid and highly performant.
Step-by-Step Solution
Key Concept
Optimizing KQL queries in Azure Application Insights by placing time-range filters early in the query pipeline.