/// <summary> /// Submits the batch query. Use the <see cref="LogsBatchQuery"/> to compose a batch query. /// <example snippet="Snippet:BatchQuery"> /// <code language="csharp"> /// string workspaceId = "<workspace_id>"; /// /// var client = new LogsQueryClient(new DefaultAzureCredential()); /// /// // Query TOP 10 resource groups by event count /// // And total event count /// var batch = new LogsBatchQuery(); /// /// string countQueryId = batch.AddWorkspaceQuery( /// workspaceId, /// "AzureActivity | count", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// string topQueryId = batch.AddWorkspaceQuery( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", /// new QueryTimeRange(TimeSpan.FromDays(1))); /// /// Response<LogsBatchQueryResultCollection> response = await client.QueryBatchAsync(batch); /// /// var count = response.Value.GetResult<int>(countQueryId).Single(); /// var topEntries = response.Value.GetResult<MyLogEntryModel>(topQueryId); /// /// Console.WriteLine($"AzureActivity has total {count} events"); /// foreach (var logEntryModel in topEntries) /// { /// Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events"); /// } /// </code> /// </example> /// </summary> /// <param name="batch">The batch of queries to send.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsBatchQueryResultCollection"/> containing the query identifier that has to be passed into <see cref="LogsBatchQueryResultCollection.GetResult"/> to get the result.</returns> public virtual Response <LogsBatchQueryResultCollection> QueryBatch(LogsBatchQuery batch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(batch, nameof(batch)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryBatch)}"); scope.Start(); try { return(ExecuteBatchAsync(batch, async: false, cancellationToken).EnsureCompleted()); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Submits the batch query. Use the <see cref="LogsBatchQuery"/> to compose a batch query. /// <code snippet="Snippet:BatchQuery" language="csharp"> /// string workspaceId = "<workspace_id>"; /// /// var client = new LogsQueryClient(new DefaultAzureCredential()); /// /// // Query TOP 10 resource groups by event count /// // And total event count /// var batch = new LogsBatchQuery(); /// /// string countQueryId = batch.AddQuery( /// workspaceId, /// "AzureActivity | count", /// new DateTimeRange(TimeSpan.FromDays(1))); /// string topQueryId = batch.AddQuery( /// workspaceId, /// "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", /// new DateTimeRange(TimeSpan.FromDays(1))); /// /// Response<LogsBatchQueryResults> response = await client.QueryBatchAsync(batch); /// /// var count = response.Value.GetResult<int>(countQueryId).Single(); /// var topEntries = response.Value.GetResult<MyLogEntryModel>(topQueryId); /// /// Console.WriteLine($"AzureActivity has total {count} events"); /// foreach (var logEntryModel in topEntries) /// { /// Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events"); /// } /// </code> /// </summary> /// <param name="batch">The batch of queries to send.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsBatchQueryResults"/> containing the query identifier that has to be passed into <see cref="LogsBatchQueryResults.GetResult"/> to get the result.</returns> public virtual Response <LogsBatchQueryResults> QueryBatch(LogsBatchQuery batch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(batch, nameof(batch)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryBatch)}"); scope.Start(); try { var response = _queryClient.Batch(new BatchRequest(batch.Requests), cancellationToken); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Submits the batch query. /// </summary> /// <param name="batch">The batch of queries to send.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsBatchQueryResult"/> that allows retrieving query results.</returns> public virtual async Task <Response <LogsBatchQueryResult> > QueryBatchAsync(LogsBatchQuery batch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(batch, nameof(batch)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryBatch)}"); scope.Start(); try { var response = await _queryClient.BatchAsync(batch.Batch, cancellationToken).ConfigureAwait(false); response.Value.RowBinder = _rowBinder; return(response); } catch (Exception e) { scope.Failed(e); throw; } }