Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4.11k stars 801 forks source link

AspNetCore.HealthChecks.AzureSearch error #2302

Open brett-wolf opened 1 month ago

brett-wolf commented 1 month ago

I am attempting to health check an azure search using AspNetCore.HealthChecks.AzureSearch. I have set up the healthcheck correctly, I believe :

    .AddAzureSearch(setup: az => new AzureSearchOptions()
    {
        Endpoint = locationSearchOptions.ServiceUri,
        AuthKey = locationSearchOptions.ApiKey,
        IndexName = locationSearchOptions.IndexName

    }, name: "LocationAzureSearch");

I have checked that all the values being passed in are valid and not null, but running the health check, I get the following error:

[2024-10-02T19:47:43.213Z] Function 'Health', Invocation id '5e5ad236-076c-4889-8a85-0f724dffe679': An exception was thrown by the invocation.
[2024-10-02T19:47:43.214Z] Result: Function 'Health', Invocation id '5e5ad236-076c-4889-8a85-0f724dffe679': An exception was thrown by the invocation.
Exception: System.ArgumentNullException: Value cannot be null. (Parameter 'searchOptions.Endpoint')
[2024-10-02T19:47:43.214Z]    at System.ArgumentNullException.Throw(String paramName)
[2024-10-02T19:47:43.215Z]    at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
[2024-10-02T19:47:43.216Z]    at Guard.ThrowIfNull[T](T argument, Boolean throwOnEmptyString, String paramName) in /_/src/CallerArgumentExpressionAttribute.cs:line 47
[2024-10-02T19:47:43.217Z]    at HealthChecks.AzureSearch.AzureSearchHealthCheck..ctor(AzureSearchOptions searchOptions) in /_/src/HealthChecks.AzureSearch/AzureSearchHealthCheck.cs:line 18
[2024-10-02T19:47:43.218Z]    at HealthChecks.AzureSearch.DependencyInjection.AzureSearchHealthCheckBuilderExtensions.<>c__DisplayClass1_0.<AddAzureSearch>b__0(IServiceProvider sp) in /_/src/HealthChecks.AzureSearch/DependencyInjection/AzureSearchHealthCheckBuilderExtensions.cs:line 39
[2024-10-02T19:47:43.218Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
[2024-10-02T19:47:43.219Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
[2024-10-02T19:47:43.220Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.CheckHealthAsync(Func`2 predicate, CancellationToken cancellationToken)
[2024-10-02T19:47:43.221Z]    at HubCustomerCore.Function.Functions.HealthChecks.HealthCheck.RunWithApiKeyAuth(HttpRequest req) in C:\Users\29T3\Source\Repos\HubCustomerCore\HubCustomerCore.Function\Functions\HealthChecks\HealthCheck.cs:line 67
[2024-10-02T19:47:43.222Z]    at HubCustomerCore.Function.DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in C:\Users\29T3\Source\Repos\HubCustomerCore\HubCustomerCore.Function\obj\Debug\net8.0\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 52
[2024-10-02T19:47:43.222Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2024-10-02T19:47:43.223Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48
[2024-10-02T19:47:43.224Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 91
Stack:    at System.ArgumentNullException.Throw(String paramName)
[2024-10-02T19:47:43.225Z]    at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
[2024-10-02T19:47:43.226Z]    at Guard.ThrowIfNull[T](T argument, Boolean throwOnEmptyString, String paramName) in /_/src/CallerArgumentExpressionAttribute.cs:line 47
[2024-10-02T19:47:43.227Z]    at HealthChecks.AzureSearch.AzureSearchHealthCheck..ctor(AzureSearchOptions searchOptions) in /_/src/HealthChecks.AzureSearch/AzureSearchHealthCheck.cs:line 18
[2024-10-02T19:47:43.228Z]    at HealthChecks.AzureSearch.DependencyInjection.AzureSearchHealthCheckBuilderExtensions.<>c__DisplayClass1_0.<AddAzureSearch>b__0(IServiceProvider sp) in /_/src/HealthChecks.AzureSearch/DependencyInjection/AzureSearchHealthCheckBuilderExtensions.cs:line 39
[2024-10-02T19:47:43.228Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
[2024-10-02T19:47:43.229Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
[2024-10-02T19:47:43.230Z]    at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.CheckHealthAsync(Func`2 predicate, CancellationToken cancellationToken)
[2024-10-02T19:47:43.231Z]    at HubCustomerCore.Function.Functions.HealthChecks.HealthCheck.RunWithApiKeyAuth(HttpRequest req) in C:\Users\29T3\Source\Repos\HubCustomerCore\HubCustomerCore.Function\Functions\HealthChecks\HealthCheck.cs:line 67
[2024-10-02T19:47:43.232Z]    at HubCustomerCore.Function.DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in C:\Users\29T3\Source\Repos\HubCustomerCore\HubCustomerCore.Function\obj\Debug\net8.0\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 52
[2024-10-02T19:47:43.232Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2024-10-02T19:47:43.233Z]    at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48
[2024-10-02T19:47:43.234Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 91.
brett-wolf commented 1 month ago

Resolved this. I was not passing in an Action :

     .AddAzureSearch(setup: new Action<AzureSearchOptions>(obj =>
     {
         obj.Endpoint = customerSearchOptions.ServiceUri;
         obj.AuthKey = customerSearchOptions.ApiKey;
         obj.IndexName = customerSearchOptions.IndexName;
     }), name: "CustomerAzureSearch")