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

Duplicate logging ID and name in health checks #46099

Open
1 task done
JamesNK opened this issue Jan 14, 2023 · 6 comments
Open
1 task done

Duplicate logging ID and name in health checks #46099

JamesNK opened this issue Jan 14, 2023 · 6 comments
Labels
area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo)

Comments

@JamesNK
Copy link
Member

JamesNK commented Jan 14, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Health checks reuses a logging ID and name for end events at different log levels. We don't do this anywhere else in ASP.NET Core.

#pragma warning disable SYSLIB1006
[LoggerMessage(EventIds.HealthCheckEndId, LogLevel.Debug, HealthCheckEndText, EventName = EventIds.HealthCheckEndName)]
private static partial void HealthCheckEndHealthy(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription);
[LoggerMessage(EventIds.HealthCheckEndId, LogLevel.Warning, HealthCheckEndText, EventName = EventIds.HealthCheckEndName)]
private static partial void HealthCheckEndDegraded(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription, Exception? exception);
[LoggerMessage(EventIds.HealthCheckEndId, LogLevel.Error, HealthCheckEndText, EventName = EventIds.HealthCheckEndName)]
private static partial void HealthCheckEndUnhealthy(ILogger logger, string HealthCheckName, HealthStatus HealthStatus, double ElapsedMilliseconds, string? HealthCheckDescription, Exception? exception);
#pragma warning restore SYSLIB1006

Expected Behavior

I think we should have different log messages for different events to be consistent with the rest of the logging.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@JamesNK JamesNK added the area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo) label Jan 14, 2023
@BrennanConroy
Copy link
Member

Similar to #46072

@JamesNK
Copy link
Member Author

JamesNK commented Jan 14, 2023

Ah, I hadn't seen that.

The difference is those duplicates look like accidents. Health checks look like it was intentionally designed with duplicates.

@eerhardt
Copy link
Member

Also note that there are duplicate Ids for HealthCheckPublisherError and HealthCheckPublisherTimeout.

public const int HealthCheckPublisherErrorId = 104;
public const int HealthCheckPublisherTimeoutId = 104;

#pragma warning disable SYSLIB1006
[LoggerMessage(EventIds.HealthCheckPublisherErrorId, LogLevel.Error, "Health check {HealthCheckPublisher} threw an unhandled exception after {ElapsedMilliseconds}ms", EventName = EventIds.HealthCheckPublisherErrorName)]
private static partial void HealthCheckPublisherError(ILogger logger, IHealthCheckPublisher HealthCheckPublisher, double ElapsedMilliseconds, Exception exception);
public static void HealthCheckPublisherTimeout(ILogger logger, IHealthCheckPublisher publisher, TimeSpan duration) =>
HealthCheckPublisherTimeout(logger, publisher, duration.TotalMilliseconds);
[LoggerMessage(EventIds.HealthCheckPublisherTimeoutId, LogLevel.Error, "Health check {HealthCheckPublisher} was canceled after {ElapsedMilliseconds}ms", EventName = EventIds.HealthCheckPublisherTimeoutName)]
private static partial void HealthCheckPublisherTimeout(ILogger logger, IHealthCheckPublisher HealthCheckPublisher, double ElapsedMilliseconds);
#pragma warning restore SYSLIB1006

@mitchdenny
Copy link
Member

What would be the possible reason for deliberately duplicating the event IDs here? I think it would be good to fix this but I have two thoughts:

  1. Why was it done like this in the first place (Chesterton's fence)?
  2. What level of concern do we have about changing these event ids being a breaking change?

@BrennanConroy
Copy link
Member

This was likely done because the logs are basically for the same thing, an error occurred during PublishAsync. You can even see in the code that the logs are used right next to each other, just for different exception types:

catch (OperationCanceledException)
{
Logger.HealthCheckPublisherTimeout(_logger, publisher, duration.GetElapsedTime());
throw;
}
catch (Exception ex)
{
Logger.HealthCheckPublisherError(_logger, publisher, duration.GetElapsedTime(), ex);

@mitchdenny
Copy link
Member

mitchdenny commented Mar 28, 2023

They are semantically different though. A timeout (notified via a cancellation exception) is very different to an exception that you also happen to record an elapsed time for.

(not doubting your reasoning though ;P)

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo)
Projects
None yet
Development

No branches or pull requests

5 participants