public async Task Get(string query) { if (string.IsNullOrWhiteSpace(query)) { return; } var result = await queryService.ExecuteQueryAsync(query, HttpContext.RequestAborted); QueryResultSerializationHelper.SendToClient(HttpContext, result); }
public async Task <IActionResult> Post() { var sb = new StringBuilder(); var buffer = new Memory <char>(new char[QueryExpressionBufferSize]); using (var reader = new StreamReader(Request.Body, Encoding.UTF8)) { while (true) { var count = await reader.ReadAsync(buffer, HttpContext.RequestAborted); sb.Append(buffer.Slice(0, count).Span); if (count < QueryExpressionBufferSize) { break; } if (sb.Length > QueryExpressionMaximumLength) { return(StatusCode(StatusCodes.Status413PayloadTooLarge, "The request query string is too long.")); } } } var query = sb.ToString(); if (string.IsNullOrWhiteSpace(query)) { return(StatusCode(StatusCodes.Status400BadRequest, "Missing query string.")); } var sw = new Stopwatch(); var stageName = "Query"; var metrics = new Dictionary <string, double>(); try { sw.Start(); var result = await queryService.ExecuteQueryAsync(query, HttpContext.RequestAborted); metrics["QueryMs"] = sw.ElapsedMilliseconds; stageName = "SendToClient"; sw.Restart(); QueryResultSerializationHelper.SendToClient(HttpContext, result); metrics["SendToClientMs"] = sw.ElapsedMilliseconds; telemetryClient.TrackEvent("QueryEnd", new Dictionary <string, string> { { "Query", query } }, metrics); return(new EmptyResult()); } catch (Exception ex) { // TODO we should distinguish between syntax error & query execution failure. telemetryClient.TrackException(ex, new Dictionary <string, string> { { "Query", query }, { "Stage", stageName }, { "StageMs", sw.ElapsedMilliseconds.ToString() } }, metrics); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }