コード例 #1
0
        private SearchDiagnosticResponse ConvertAzureSearchResponse(AzureSearchDiagnosticResponse azureSearchDiagnosticResponse)
        {
            var result = new SearchDiagnosticResponse
            {
                // We will use UtcNow here since AzureSearch diagnostic endpoint doesn't currently have last reloaded information.
                // See https://github.com/NuGet/Engineering/issues/2651 for more information
                LastIndexReloadTime = DateTimeOffset.UtcNow,
                CommitUserData      = new CommitUserData
                {
                    CommitTimeStamp = azureSearchDiagnosticResponse.SearchIndex.LastCommitTimestamp.ToString()
                }
            };

            return(result);
        }
コード例 #2
0
        public async Task <SearchDiagnosticResponse> GetSearchDiagnosticResponseAsync(
            Instance instance,
            CancellationToken token)
        {
            try
            {
                using (var diagResponse = await _httpClient.GetAsync(
                           instance.DiagUrl,
                           HttpCompletionOption.ResponseContentRead,
                           token))
                {
                    if (!diagResponse.IsSuccessStatusCode)
                    {
                        throw new HttpResponseException(
                                  diagResponse.StatusCode,
                                  diagResponse.ReasonPhrase,
                                  $"The HTTP response when hitting {instance.DiagUrl} was {(int)diagResponse.StatusCode} " +
                                  $"{diagResponse.ReasonPhrase}, which is not successful.");
                    }

                    var diagContent         = diagResponse.Content;
                    var searchDiagResultRaw = await diagContent.ReadAsStringAsync();

                    SearchDiagnosticResponse response = null;
                    switch (instance.ServiceType)
                    {
                    case ServiceType.AzureSearch:
                        var tempResponse = JsonConvert.DeserializeObject <AzureSearchDiagnosticResponse>(searchDiagResultRaw);
                        response = ConvertAzureSearchResponse(tempResponse);
                        break;
                    }

                    return(response);
                }
            }
            catch (JsonException je)
            {
                _logger.LogError("Error: Failed to deserialize response from diagnostic endpoint: {Error}", je.Message);
                throw je;
            }
            catch (Exception e)
            {
                _logger.LogError("Error: Failed to get diagnostic response due to unexpected error: {Error}", e.Message);
                throw e;
            }
        }