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

Refactor and move backoff logic to AzureAppConfigurationProvider #508

Merged
merged 12 commits into from
Jan 17, 2024

Conversation

amerjusupovic
Copy link
Member

No description provided.

clientBackoffStatus = _configClientBackoffs[endpoint];
}

return clientBackoffStatus?.BackoffEndTime <= DateTimeOffset.UtcNow;
Copy link
Member

Choose a reason for hiding this comment

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

Regarding the null check (?). I see that we either get existing backoff status or create a new one. How could it be null?

Copy link
Member

@jimmyca15 jimmyca15 Jan 8, 2024

Choose a reason for hiding this comment

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

DateTimeOffset.UtcNow, should calculate once outside of the predicate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right it shouldn't be null, leftover from old change


if (!_configClientBackoffs.TryGetValue(endpoint, out ConfigurationClientBackoffStatus clientBackoffStatus))
{
UpdateClientBackoffStatus(endpoint, true);
Copy link
Member

Choose a reason for hiding this comment

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

There's no definition of success/fail here. I think it might be a bit better to just initialize it inline here and then add it into the dictionary.

@@ -319,12 +282,11 @@ private async Task RefreshFallbackClients(CancellationToken cancellationToken)
_lastFallbackClientRefresh = DateTime.UtcNow;
}

private bool IsFallbackClientDiscoveryDue(DateTimeOffset dateTime)
private bool IsFallbackClientDiscoveryDue(DateTimeOffset now)
Copy link
Member

Choose a reason for hiding this comment

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

Unused.

@amerjusupovic amerjusupovic marked this pull request as ready for review January 8, 2024 23:39
{
clientBackoffStatus.FailedAttempts++;

TimeSpan backoffDuration = _options.MinBackoffDuration.CalculateBackoffDuration(FailOverConstants.MaxBackoffDuration, clientBackoffStatus.FailedAttempts);
Copy link
Member

Choose a reason for hiding this comment

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

double calculatedMilliseconds = Math.Max(1, minDuration.TotalMilliseconds) * ((long)1 << Math.Min(attempts, MaxAttempts));

Here basically the backoff time = minDuration * (1<<attemps) when attempts >=2.
attemps: 1, 2, 3, 4...
backoffTime( x minDuration): 1x, 4x, 8x, 16x...

Should we change it to 1<<(attemps -1), so the backoff time becomes 1x,2x,4x,8x, ...?

Copy link
Member

Choose a reason for hiding this comment

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

That is a good idea. I think this happens because we optimized to return when attempts=1, so we never get the 2x backoff duration.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, just gonna subtract one from attempts in that code then.

/// <summary>
/// An optional timespan value to set the minimum backoff duration to a value other than the default.
/// </summary>
/// <remarks>This property is used only for unit testing.</remarks>
Copy link
Member

Choose a reason for hiding this comment

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

This property is not only used for unit testing. It's referenced in this file for backoff. It would be appropriate to say this property is internal for availability in unit tests. But even that seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, I'll remove the remarks.

@amerjusupovic amerjusupovic merged commit efe961d into preview Jan 17, 2024
2 checks passed
@amerjusupovic amerjusupovic deleted the ajusupovic/organize-backoff-logic branch January 17, 2024 19:09
amerjusupovic added a commit that referenced this pull request Feb 21, 2024
* move backoff logic to provider, can't access backoffendtime from manager for dynamic clients

* add condition before calling getclients in refreshasync, add refreshclients method

* fix logic to check if backoff ended for client

* fix indents

* check client backoff before refresh, fix tests in progress

* remove tolist

* comment changes, fix refresh tests

* reduce minimum backoff when testing

* fix tests, fix typo with failover logic

* update comments in tests

* resolve PR comments

* resolve small comments
amerjusupovic added a commit that referenced this pull request Feb 22, 2024
* Automatic http failover base on Srv Dns (#442)

* Automatic http failover base on Srv Dns

* update failover condition

* Logging messages for auto failover

* Not use generic method

* Remove useless constructor

* Failover to TCP when response is truncated

* Error handling of TCP failover

* Resolve comments and add thrid party notice

* Fix the tests

* Fix the tess

* Fix the test

* Update to use DnsClient.NET

* Remove unecessary code

* Resolve conflict

* Stop once it has been auto failovered

* Update GetAvaliableClient method

* Resolve comments

* Resolve comments

* Internalize getting dynamic client in ConfigurationClientManager

* Fix format

* Fix format

* Resolve comments

* Resolve comments

* Resolve comments

* Resolve comments

* Resolve comments

* Resolve comments

* Resolve comments

* Not await RefreshFallbackClients when startup

* Revert non-await RefreshFallbackClients

* Validate domain of Srv endpoints (#489)

* Validate domain of Srv endpoints

* Resolve comments

* Resolve comments

* Create object in using

* Add the origin host to the srv lookup result

* Validate endpoint by domain name (#499)

* Validate endpoint by domain name

* Resolve comments

* Remove *-test

* Fix formatResolve conflict

* Use await using for IAsyncDisposible

* Replace IAsyncEumerable with ValueTask<IEnumerable>

* Resolve comments

* Remove cancallation token

* Resolve comments

* Refactor and move backoff logic to AzureAppConfigurationProvider (#508)

* move backoff logic to provider, can't access backoffendtime from manager for dynamic clients

* add condition before calling getclients in refreshasync, add refreshclients method

* fix logic to check if backoff ended for client

* fix indents

* check client backoff before refresh, fix tests in progress

* remove tolist

* comment changes, fix refresh tests

* reduce minimum backoff when testing

* fix tests, fix typo with failover logic

* update comments in tests

* resolve PR comments

* resolve small comments

* fix tests backoff duration

* fix tests backoff duration

* fix error from merging main branch in

* add back fix for attempts backoff calculation

---------

Co-authored-by: Richard chen <99175581+RichardChen820@users.noreply.github.com>
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.

5 participants