Question

Difficulty: MediumQuery and Analyze Application Insights Telemetry

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?

  1. requests
    | where timestamp > ago(24h)
    | summarize SuccessRate = countif(success == true) * 100.0 / count()
    Answer
  2. B
    requests
    | summarize SuccessRate = countif(success == true) * 100.0 / count()
    | where timestamp > ago(24h)
  3. requests
    | where timestamp > ago(24h)
    | summarize SuccessCount = countif(success), TotalCount = count()
    | project SuccessRate = (todouble(SuccessCount) * 100.0) / TotalCount
    Answer
  4. D
    requests
    | 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

1
Apply a time-range filter directly to the requests table.
Limits the scope of scanned telemetry data to only the last 24 hours, optimizing performance.
Omitting or delaying the time filter forces Azure Monitor to scan the entire data retention window.
2
Aggregate the total count and the count of successful requests.
Calculates the successful request count (using countif(success)) and overall request count.
Allows calculation of the percentage metric.
3
Compute the final success percentage.
Produces the success rate as a percentage of total requests.
Fulfills the business requirement of calculating the success rate.

Key Concept

Optimizing KQL queries in Azure Application Insights by placing time-range filters early in the query pipeline.
Rate this question