Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not retrieve health checks data #48

Closed
bradleypatton opened this issue Dec 21, 2018 · 24 comments
Closed

Could not retrieve health checks data #48

bradleypatton opened this issue Dec 21, 2018 · 24 comments

Comments

@bradleypatton
Copy link

Following the steps in the Scott Hanselman post and the ASP.NET 2.2 video, I've added the following to ConfigureServices

	// Register health check services
	services.AddHealthChecks()				
		.AddDbContextCheck<ApplicationDbContext>();
	services.AddHealthChecksUI();

In Configure added the following:

	// Healthcheck endpoint
	app.UseHealthChecks("/healthcheck", new HealthCheckOptions() {
		Predicate = _ => true,
		ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
	});
	app.UseHealthChecksUI(setup => { setup.ApiPath = "/healthcheck"; setup.UIPath = "/healthcheckui"; });

And in appsettings

	"HealthChecks-UI": {
		"HealthChecks": [
			{
				"Name": "HTTP-Api-Basic",
				"Uri": "http://localhost:44393/healthcheck"
			}
		],
		"Webhooks": [
			{
				"Name": "Failhook",
				"Uri": "",
				"Payload": "",
				"RestoredPayload": ""
			}
		],
		"EvaluationTimeOnSeconds": 15,
		"MinimumSecondsBetweenFailureNotifications": 60
	}

When I navigate to /healthcheck I get the following JSON

{"status":"Healthy","totalDuration":"00:00:00.0029078","entries":{"applicationDbContext":{"data":{},"duration":"00:00:00.0026669","status":"Healthy"}}}

But when I navigate to /healthcheckui I get the following message "Could not retrieve health checks data"

health check

I can see it's reading the appsettings as the Webhook name changes.

webhook

What am I doing wrong?

@unaizorrilla
Copy link
Collaborator

unaizorrilla commented Dec 21, 2018

Your configuration is wrong! Can you check the samples? The project UiAndApi contains the same you are trying to do.

@unaizorrilla
Copy link
Collaborator

With UseHealthChecks you can configure the health checks to be executed and also where the response is /healthchecks.

With UseHealthChecksUI you configure where the UI work, you don’t need setup api path or UI path, only create the app settings configuration.

Navigate to /HealthChecks-UI

Follow the samples, this can clarify the scenario

@bradleypatton
Copy link
Author

The API and UI paths are different (UI path has "ui" at the end) and this was copied from the Hanselman blog post. However, I've removed that line:

setup.ApiPath = "/healthcheck"; setup.UIPath = "/healthcheckui"; 

And updated the other lines to use "healthchecks" like:

	// Healthcheck endpoint
	app.UseHealthChecks("/healthchecks", new HealthCheckOptions() {
		Predicate = _ => true,
		ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
	});
	app.UseHealthChecksUI();

And now see this with no DB info
image

Although the JSON says the app is healthy
{"status":"Healthy","totalDuration":"00:00:00.0140658","entries":{"applicationDbContext":{"data":{},"duration":"00:00:00.0092246","status":"Healthy"}}}

@unaizorrilla
Copy link
Collaborator

Hi @bradleypatton

Any update on this issue, can you check my latest references?

@bradleypatton
Copy link
Author

Had to run out for some Xmas shopping :).

Still not good. I've stripped out the DbContext check and copied the configuration directly from the sample. The JSON endpoint looks like this::

{"status":"Healthy","totalDuration":"00:00:00.0009491","entries":{}}

But the UI still shows unhealthy.

image

	// Register health check services
	services.AddHealthChecksUI();
	services.AddHealthChecks();
	// Healthcheck endpoint
	app.UseHealthChecks("/healthz", new HealthCheckOptions() {
		Predicate = _ => true,
		ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
	})
	.UseHealthChecksUI();

@unaizorrilla
Copy link
Collaborator

Can you share your app settings or if os posible your project or simple repro?

@bradleypatton
Copy link
Author

bradleypatton commented Dec 21, 2018

Here is the appsettings. I can't share the project but will try and test out a repro tomorrow

{
	"ConnectionStrings": {
		"DefaultConnection": "SQL Server"
	},
	"Logging": {
		"IncludeScopes": false,
		"LogLevel": {
			"Default": "Trace",
			"Microsoft": "Information",
			"Microsoft.EntityFrameworkCore.Database.Command": "Information"
		}
	},
	"ApplicationInsights": {
		"InstrumentationKey": ""
	},
	"HealthChecks-UI": {
		"HealthChecks": [
			{
				"Name": "Http and UI on single project",
				"Uri": "http://localhost:44393/healthz"
			}
		],
		"Webhooks": [],
		"EvaluationTimeOnSeconds": 10,
		"MinimumSecondsBetweenFailureNotifications": 60
		//"HealthCheckDatabaseConnectionString": "Data Source=[PUT-MY-PATH-HERE]\\healthchecksdb" //-> Optional, default on WebContentRoot
	}
}

@unaizorrilla
Copy link
Collaborator

Also you don’t have any entry on healthchecks! You can try the sample and uiandapi and check if work for you?

@unaizorrilla
Copy link
Collaborator

I think is good can you add a healthcheck after UseHealthChecks and check again?

@bradleypatton
Copy link
Author

Sorry what do you mean

you don’t have any entry on healthchecks!

I'm copying the code directly from the sample project.

@unaizorrilla
Copy link
Collaborator

unaizorrilla commented Dec 21, 2018

The sample also include a HealthCheck for uri (AspNetCore.HealthChecks.Uris package)

            services
            .AddHealthChecksUI()
            .AddHealthChecks()
            .AddUrlGroup(new Uri("http://httpbin.org/status/200"))
            .Services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

@bradleypatton
Copy link
Author

Added that line and the package. The JSON shows the entry as healthy but the UI page still shows unhealthy. Is it an issue de-serializing the JSON? I will have to try and create a new project tomorrow and see if I can reproduce. Thanks for your help in looking into this.

{"status":"Healthy","totalDuration":"00:00:00.1979284","entries":{"uri-group":{"data":{},"duration":"00:00:00.1932845","status":"Healthy"}}}

image

@unaizorrilla
Copy link
Collaborator

Send me the project and I try to help, your scenario is the same as uiandapi sample.

@unaizorrilla
Copy link
Collaborator

Hi @bradleypatton

Any update on this issue, can you create and send me a sample project to check?

@bradleypatton
Copy link
Author

I was able to get the sample working but still having problems with my app. When I look at the trace I see a request is being made to https://localhost:44393/healthchecks-api although I've copied in your configuration of using "healthz" as the endpoint. When I navigate to "healthz" I see the JSON showing the app as healthy. When I navigate to "healthchecks-api" I see an empty array.

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/2.0 GET https://localhost:44393/healthchecks-api application/json 
Microsoft.EntityFrameworkCore.Infrastructure:Information: Entity Framework Core 2.2.0-rtm-35687 initialized 'HealthChecksDb' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: None
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "c"."Id", "c"."DiscoveryService", "c"."Name", "c"."Uri"
FROM "Configurations" AS "c"
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "le"."Id", "le"."DiscoveryService", "le"."LastExecuted", "le"."Name", "le"."OnStateFrom", "le"."Status", "le"."Uri"
FROM "Executions" AS "le"
ORDER BY "le"."Id"
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 17.9831ms 200 application/json

@unaizorrilla
Copy link
Collaborator

Hi @bradleypatton

You are confusing some terms.

Well, I try to explain, I suppose you have HealthChecks and UI in the same project like UIAndApi sample.

When you add HealthChecks and the customized response with:

app.UseHealthChecks("/healthz", new HealthCheckOptions() {
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
})

Your are configuring a customized response for your health checks.

When you navigate into /healthz you view some json that represent the current status of configured health checks, ok?

Well, next step is adding a UI for show this result more "human readable".

AddHelthchecks and AddHealthChecksUI add services and middlewares for this. By default, if you don't change anything you have different new middlewares responding on

/healthchecks-ui => This is where the UI is showed

/healthchecks-api => UI is and SPA app, this is where the javascript call to get data.

In addition to middlewares the UI create a HostedService that use the appsettings configuration to call automatically to all healthz configured endpoints, in your case the appsettings need to contain the url information of your project, the uri for your /healthz

If the sample works for you, you have some items misconfigured, I try to help but need to view your code or a repro

@bradleypatton
Copy link
Author

So is the heathcheck UI project supposed to be run as a separate app? The UIAndApi project was failing for me until I edited the app settings to use port 6001 like the browser was using for the site on launch

    "HealthChecks": [
      {
        "Name": "Http and UI on single project",
        "Uri": "http://localhost:6001/healthz"
      }

If I leave it on the default 5000 this is what I get:
image

Same for the other samples. I'm running them from Visual Studio using the default of IIExpress.

@bradleypatton
Copy link
Author

So right after I posted that last comment I changed the samples to use Kestrel and not IIExpress and they worked without changing the ports. Just did the same with my app and and the Health Checks UI worked!! Except now my login code is failing for some reason.

So the issue is with using IIExpress. Is the idea that the Health checks UI will be hosted in a separate app service than the app that is being monitored?

@unaizorrilla
Copy link
Collaborator

In your launchsettings.json (inside Properties folder in vs) you have different ports for IIS Express and Command Line Kestrel, you need to set the rignt port for each configuration on your appsettings.json.

@unaizorrilla
Copy link
Collaborator

Also, if your healchecksdb is created with invalid configuration, please delete it before launch again the project.

@bradleypatton
Copy link
Author

Thanks for all of your help. FYI you can repo the issue I was seeing in the sample app.

  1. Set HealthChecks.UIAndApi as the Startup Project
  2. Set IIExpress as the web server to launch with.
  3. Start project and wait 10 seconds.

Status is reported as unhealthy:

image

Change the web server to the project name (aka Kestrel) and it runs fine.

@unaizorrilla
Copy link
Collaborator

unaizorrilla commented Dec 29, 2018

Please, read my comments, on this sample the appsettings.json is configure to use the Kestrel configured port, not the iis configured port. If you use IIS please set valid port on appsettings.json.

AppSettings for IIS

"Uri": "http://localhost:6001/healthz"

AppSettings for Kestrel

"Uri": "http://localhost:5000/healthz"

@unaizorrilla
Copy link
Collaborator

Hi @bradleypatton I close this issue because I think all is ok and no more feedback is on the comments. If you have more information please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants