mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Added filter logic to exclude comments in MonitorClient. Added error handling in KustoClient to handle ErrorResponseExceptions. (#1226)
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Kusto.Language;
|
||||||
|
using Kusto.Language.Editor;
|
||||||
using Microsoft.Azure.OperationalInsights;
|
using Microsoft.Azure.OperationalInsights;
|
||||||
using Microsoft.Azure.OperationalInsights.Models;
|
using Microsoft.Azure.OperationalInsights.Models;
|
||||||
using Microsoft.Kusto.ServiceLayer.DataSource.Monitor.Responses;
|
using Microsoft.Kusto.ServiceLayer.DataSource.Monitor.Responses;
|
||||||
@@ -61,12 +64,36 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Monitor
|
|||||||
|
|
||||||
public async Task<QueryResults> QueryAsync(string query, CancellationToken cancellationToken)
|
public async Task<QueryResults> QueryAsync(string query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await _queryClient.QueryAsync(query, cancellationToken: cancellationToken);
|
try
|
||||||
|
{
|
||||||
|
var minimizedQuery = MinimizeQuery(query);
|
||||||
|
return await _queryClient.QueryAsync(minimizedQuery, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
catch (ErrorResponseException ex)
|
||||||
|
{
|
||||||
|
var message = $"{ex.Body.Error.Innererror.Message} {ex.Body.Error.Innererror?.Innererror?.Message}";
|
||||||
|
throw new Exception(message, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryResults Query(string query)
|
public QueryResults Query(string query)
|
||||||
{
|
{
|
||||||
return _queryClient.Query(query);
|
try
|
||||||
|
{
|
||||||
|
var minimizedQuery = MinimizeQuery(query);
|
||||||
|
return _queryClient.Query(minimizedQuery);
|
||||||
|
}
|
||||||
|
catch (ErrorResponseException ex)
|
||||||
|
{
|
||||||
|
var message = $"{ex.Body.Error.Innererror.Message} {ex.Body.Error.Innererror?.Innererror?.Message}";
|
||||||
|
throw new Exception(message, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string MinimizeQuery(string query)
|
||||||
|
{
|
||||||
|
var script = CodeScript.From(query, GlobalState.Default);
|
||||||
|
return script.Blocks[0].Service.GetMinimalText(MinimalTextKind.RemoveLeadingWhitespaceAndComments);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MonitorClient()
|
~MonitorClient()
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Monitor
|
|||||||
|
|
||||||
public override async Task<IDataReader> ExecuteQueryAsync(string query, CancellationToken cancellationToken, string databaseName = null)
|
public override async Task<IDataReader> ExecuteQueryAsync(string query, CancellationToken cancellationToken, string databaseName = null)
|
||||||
{
|
{
|
||||||
var results = await _monitorClient.QueryAsync(query, cancellationToken);
|
var results = await _monitorClient.QueryAsync(query, cancellationToken);
|
||||||
return results.ToDataReader();
|
return results.ToDataReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user