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

Add warning level log for failover to new endpoint #431

Merged
merged 22 commits into from
Aug 11, 2023

Conversation

amerjusupovic
Copy link
Member

No description provided.

@amerjusupovic amerjusupovic marked this pull request as draft June 20, 2023 22:03
@@ -827,6 +829,13 @@ private async Task<T> ExecuteWithFailOverPolicyAsync<T>(IEnumerable<Configuratio
T result = await funcToExecute(currentClient).ConfigureAwait(false);
success = true;

Uri currentEndpoint = _configClientManager.GetEndpointForClient(currentClient);

if (failureOccurred && originalEndpoint != currentEndpoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would log only when (if) there is a successful operation. We should be logging all endpoints in the same order that they were tried in.

@amerjusupovic amerjusupovic linked an issue Jun 23, 2023 that may be closed by this pull request
@amerjusupovic amerjusupovic requested a review from avanigupta June 23, 2023 19:07
@amerjusupovic amerjusupovic marked this pull request as ready for review July 11, 2023 20:51
@amerjusupovic amerjusupovic requested a review from jimmyca15 August 2, 2023 17:35

public static string BuildFailoverToDifferentEndpointMessage(string originalEndpoint, string currentEndpoint)
{
return $"{LoggingConstants.RefreshFailedToGetSettingsFromEndpoint} '{originalEndpoint.TrimEnd('/')}'. {LoggingConstants.RefreshTryingToReadFromEndpoint} '{currentEndpoint.TrimEnd('/')}'.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trim necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the pattern we followed with the original PR that added logging, since the endpoints always have a '/' at the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Parameters need validation for null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! We need it throughout this helper class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just for the endpoint parameters because we call TrimEnd right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Without parameter validation it's a possible null-ref.

Comment on lines 844 to 847
if (previousEndpoint != currentEndpoint)
{
_logger.LogWarning(LogHelper.BuildFailoverToDifferentEndpointMessage(previousEndpoint.ToString(), currentEndpoint.ToString()));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be after the finally block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree from how it looks, but then it seems like I need to either make an extra call to GetEndpointforClient or update currentEndpoint at the bottom of the while loop and I wasn't sure which made more sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about the happy path. The call to GetEndpointForClient is actually unnecessary.

What we need to know is the client we use to make the attempt. We can get the endpoint later if we need to log.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I got it, thanks

@@ -74,5 +74,15 @@ public static string BuildPushNotificationUnregisteredEndpointMessage(string res
{
return $"{LoggingConstants.PushNotificationUnregisteredEndpoint} '{resourceUri}'.";
}

public static string BuildFailoverToDifferentEndpointMessage(string originalEndpoint, string currentEndpoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just BuildFailoverMessage?

@@ -74,5 +74,15 @@ public static string BuildPushNotificationUnregisteredEndpointMessage(string res
{
return $"{LoggingConstants.PushNotificationUnregisteredEndpoint} '{resourceUri}'.";
}

public static string BuildFailoverToDifferentEndpointMessage(string originalEndpoint, string currentEndpoint)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the message it looks like it's currently

"Failed to get configuration settings from endpoint '{old endpoint}'. Trying to read from endpoint '{new endpoint}'."

I'm thinking to make the fall back clear:

"Failed to get configuration settings from endpoint '{old endpoint}'. Falling back to endpoint '{new endpoint}'."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, can we use "failover" instead of "fallback" though? That's the term we use in public docs too.

"Failed to get configuration settings from endpoint '{old endpoint}'. Initiating automatic failover to endpoint '{new endpoint}'."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. "Failing over to endpoint ..."

@amerjusupovic amerjusupovic merged commit b1cbbc9 into main Aug 11, 2023
@amerjusupovic amerjusupovic deleted the ajusupovic/failover-warning-log branch September 12, 2023 19:48
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

Successfully merging this pull request may close these issues.

Monitoring of failover
3 participants