예제 #1
0
        public virtual async Task <Response <LogsBatchQueryResult> > SubmitAsync(CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsBatchQuery)}.{nameof(Submit)}");
            scope.Start();
            try
            {
                var response = await _restClient.BatchAsync(_batch, cancellationToken).ConfigureAwait(false);

                response.Value.RowBinder = _rowBinder;
                return(response);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Submits the batch query. Use the <see cref="LogsBatchQuery"/> to compose a batch query.
        /// <code snippet="Snippet:BatchQuery" language="csharp">
        /// string workspaceId = &quot;&lt;workspace_id&gt;&quot;;
        ///
        /// 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,
        ///     &quot;AzureActivity | count&quot;,
        ///     new DateTimeRange(TimeSpan.FromDays(1)));
        /// string topQueryId = batch.AddQuery(
        ///     workspaceId,
        ///     &quot;AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count&quot;,
        ///     new DateTimeRange(TimeSpan.FromDays(1)));
        ///
        /// Response&lt;LogsBatchQueryResults&gt; response = await client.QueryBatchAsync(batch);
        ///
        /// var count = response.Value.GetResult&lt;int&gt;(countQueryId).Single();
        /// var topEntries = response.Value.GetResult&lt;MyLogEntryModel&gt;(topQueryId);
        ///
        /// Console.WriteLine($&quot;AzureActivity has total {count} events&quot;);
        /// foreach (var logEntryModel in topEntries)
        /// {
        ///     Console.WriteLine($&quot;{logEntryModel.ResourceGroup} had {logEntryModel.Count} events&quot;);
        /// }
        /// </code>
        /// </summary>
        /// <param name="batch">The batch of Kusto queries to send.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
        /// <returns>The <see cref="LogsBatchQueryResults"/> that allows retrieving query results.</returns>
        public virtual async Task <Response <LogsBatchQueryResults> > 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(new BatchRequest(batch.Requests), cancellationToken).ConfigureAwait(false);

                return(response);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }