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

O11Y-5250: Add retry #194

Merged
merged 6 commits into from
Oct 31, 2024
Merged

O11Y-5250: Add retry #194

merged 6 commits into from
Oct 31, 2024

Conversation

changliu-wk
Copy link
Contributor

@changliu-wk changliu-wk commented Oct 17, 2024

Which problem is this PR solving?

When call client.post collector_exporter didn't check if the response is succeeded or not, this PR would like to add retry effort when the response is retryable.

Short description of the change

How Has This Been Tested?

Please describe the tests that you ran to verify your change. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • Unit tests have been added
  • Documentation has been updated

@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@changliu-wk changliu-wk marked this pull request as ready for review October 21, 2024 20:03
} catch (e) {
_log.warning('Failed to export ${spans.length} spans. $e');
}
await Future.delayed(Duration(seconds: retries));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use exponential backoff. We should probably add jitter too, though there's implicit disagreement in the spec:

Both say exponential backoff, only one says jitter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added jitter in.

}

Duration calculateJitteredDelay(int retries, Duration baseDelay) {
final random = Random();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this a class member variable?

Comment on lines 87 to 89
final jitter = random.nextDouble() * baseDelay.inMilliseconds;
return Duration(
milliseconds: baseDelay.inMilliseconds + jitter.toInt() * retries);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use exponential delay, something like this:

Suggested change
final jitter = random.nextDouble() * baseDelay.inMilliseconds;
return Duration(
milliseconds: baseDelay.inMilliseconds + jitter.toInt() * retries);
final delay = baseDelay.inMilliseconds * pow(2, retries)
final jitter = random.nextDouble() * delay;
return Duration(milliseconds: (delay + jitter).toInt());

Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes the first retry will have "retries" set to zero, not one

return;
}
// Exponential backoff with jitter
final delay = calculateJitteredDelay(retries, Duration(seconds: 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's reasonable to start with something smaller like 100 milliseconds

@changliu-wk
Copy link
Contributor Author

@Workiva/release-management-p

@changliu-wk
Copy link
Contributor Author

QA +1

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole7-wk rmconsole7-wk merged commit 6236568 into master Oct 31, 2024
3 checks passed
@rmconsole7-wk rmconsole7-wk deleted the O11Y-5250 branch October 31, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants