Exemplo n.º 1
0
        /// <summary>
        /// Executes the logs query.
        /// </summary>
        /// <param name="workspaceId">The workspace to include in the query.</param>
        /// <param name="query">The query text to execute.</param>
        /// <param name="timeRange">The timespan over which to query data. Logs would be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param>
        /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
        /// <returns>Query results mapped to a type <typeparamref name="T"/>.</returns>
        public virtual async Task <Response <IReadOnlyList <T> > > QueryAsync <T>(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default)
        {
            Response <LogsQueryResult> response = await QueryAsync(workspaceId, query, timeRange, options, cancellationToken).ConfigureAwait(false);

            return(Response.FromValue(_rowBinder.BindResults <T>(response), response.GetRawResponse()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the logs query.
        /// </summary>
        /// <param name="workspaceId">The workspace to include in the query.</param>
        /// <param name="query">The query text to execute.</param>
        /// <param name="timeRange">The timespan over which to query data. Logs would be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param>
        /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
        /// <returns>Query results mapped to a type <typeparamref name="T"/>.</returns>
        public virtual Response <IReadOnlyList <T> > Query <T>(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default)
        {
            Response <LogsQueryResult> response = Query(workspaceId, query, timeRange, options, cancellationToken);

            return(Response.FromValue(_rowBinder.BindResults <T>(response), response.GetRawResponse()));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Executes the logs query.
 /// </summary>
 /// <param name="workspaceId">The workspace to include in the query.</param>
 /// <param name="query">The query text to execute.</param>
 /// <param name="timeRange">The timespan over which to query data. Logs would be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param>
 /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
 /// <returns>The <see cref="LogsQueryResult"/> with the query results.</returns>
 public virtual async Task <Response <LogsQueryResult> > QueryAsync(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsClient)}.{nameof(Query)}");
     scope.Start();
     try
     {
         return(await ExecuteAsync(workspaceId, query, timeRange, options, true, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Exemplo n.º 4
0
        private async Task <Response <LogsQueryResult> > ExecuteAsync(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options, bool async, CancellationToken cancellationToken = default)
        {
            if (workspaceId == null)
            {
                throw new ArgumentNullException(nameof(workspaceId));
            }

            QueryBody queryBody = CreateQueryBody(query, timeRange, options, out string prefer);

            using var message = _queryClient.CreateExecuteRequest(workspaceId, queryBody, prefer);

            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            // if (options?.Timeout != null)
            // {
            //     message.NetworkTimeout = options.Timeout;
            // }

            if (async)
            {
                await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                _pipeline.Send(message, cancellationToken);
            }

            switch (message.Response.Status)
            {
            case 200:
            {
                using var document = async ?
                                     await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false) :
                                     JsonDocument.Parse(message.Response.ContentStream, default);

                LogsQueryResult value = LogsQueryResult.DeserializeLogsQueryResult(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }

            default:
            {
                if (async)
                {
                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
                }
                else
                {
                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
                }
            }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Executes the logs query.
 /// </summary>
 /// <param name="workspaceId">The workspace id to include in the query (<c>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</c>).</param>
 /// <param name="query">The query text to execute.</param>
 /// <param name="timeRange">The timespan over which to query data. Logs will be filtered to include entries produced starting at <c>Now - timeSpan</c>. </param>
 /// <param name="options">The <see cref="LogsQueryOptions"/> to configure the query.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
 /// <returns>The <see cref="LogsQueryResult"/> containing the query results.</returns>
 public virtual Response <LogsQueryResult> Query(string workspaceId, string query, DateTimeRange timeRange, LogsQueryOptions options = null, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(Query)}");
     scope.Start();
     try
     {
         return(ExecuteAsync(workspaceId, query, timeRange, options, false, cancellationToken).EnsureCompleted());
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }