Duende.IdentityServer.Admin icon indicating copy to clipboard operation
Duende.IdentityServer.Admin copied to clipboard

Fix duplicated healthchecks - #135

Open holytshirt opened this issue 2 years ago • 5 comments

  • AddDbContextCheck by default checks to see if it can connect to the database .CanConnectAsync() you can also run a custom query against the context
  • No longer need healthchecks per db provider
  • Name is not required by default it does nameof on the type now making it refactor friendly
-- IdentityServerConfigurationDbContext  context.Clients.AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [Clients] AS [c]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END
-- IdentityServerPersistedGrantDbContext context.Keys.AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [Keys] AS [k]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END
-- AdminIdentityDbContext context.Set<TUser>().AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [Users] AS [u]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END
-- AdminLogDbContext context.Logs.AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [Log] AS [l]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END
-- AdminAuditLogDbContext context.AuditLog.AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [AuditLog] AS [a]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END
-- IdentityServerDataProtectionDbContext context.DataProtectionKeys.AnyAsync(token)
SELECT CASE
    WHEN EXISTS (
        SELECT 1
        FROM [DataProtectionKeys] AS [d]) THEN CAST(1 AS bit)
    ELSE CAST(0 AS bit)
END

holytshirt avatar Feb 07 '23 16:02 holytshirt

@skoruba
Using a query also means if there is no data in a table the healthcheck fails. Personally I would not have the queries and just make sure you can connect.

  1. You probably want to double check the queries, that you are happy with the tables they are querying.
  2. Check you are happy with me removing the name and moving it to nameof(dbcontext)
  3. Happy with using tags and the tag names, struggle with identityserver http check

holytshirt avatar Feb 07 '23 16:02 holytshirt

Neat, that does look a lot tidier.

colin-freemarketfx avatar Feb 07 '23 16:02 colin-freemarketfx

@aiscrim - what do you think? thanks

skoruba avatar Feb 07 '23 20:02 skoruba

Did this ever come to anything? I have the same issue that this PR attempted to address. A few releases have been put out since this Pr was created but these changes were never included. Can the PR at least be closed to signify we should give up on it?

reydelleon-skuvault avatar Jul 02 '24 19:07 reydelleon-skuvault

Thank you for letting me know. I am going to revisit this PR.

skoruba avatar Jul 07 '24 10:07 skoruba