Skip to content

OTLP/GRPC exporter implementation - Missing Reries on Exporter errors#677

Closed
sanketmehta28 wants to merge 38 commits into
open-telemetry:mainfrom
sanketmehta28:develop/retry_for_exporter
Closed

OTLP/GRPC exporter implementation - Missing Reries on Exporter errors#677
sanketmehta28 wants to merge 38 commits into
open-telemetry:mainfrom
sanketmehta28:develop/retry_for_exporter

Conversation

@sanketmehta28

@sanketmehta28 sanketmehta28 commented May 19, 2022

Copy link
Copy Markdown
Member

Is your feature request related to a problem? Please describe.
The OTLP exporter specification says that transient errors MUST be handled with a retry strategy, where the retriable gRPC error codes are defined in the OTLP spec.

Fixes: #328

Describe the solution you'd like
I think we should implement generic retry policy which can be utilized by all exporters

Additional context
In grpc, retry is supported out of the box using service config but in this PR I have tried to provide the generic solution which can be used by all the exporters irrespective of the transport method.

…entation - Missing retries on Exporter errors
@welcome

welcome Bot commented May 19, 2022

Copy link
Copy Markdown

Thanks for opening your first pull request! If you haven't yet signed our Contributor License Agreement (CLA), then please do so that we can accept your contribution. A link should appear shortly in this PR if you have not already signed one.

@tidal

tidal commented May 20, 2022

Copy link
Copy Markdown
Member

@sanketmehta28
Hi, thanks for your contribution and sorry for the late response.
Can you please fix the CS issues, so we can review the PR?
(The easiest way is just to call make style in the repo root dir)

@bobstrecansky

Copy link
Copy Markdown
Contributor

There are some psalm errors appearing in CI

$delay = $this->retryPolicy->getDelay($attempt++);
if ($attempt > 0) {
self::logDebug('Waiting for ' . $delay . ' seconds before retrying export');
sleep($delay);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think sleeping here is a good idea, because it will cause the application being instrumented to wait. A better way might be to keep track of spans to retry (eg in internal storage), and check for spans to retry as a side-effect of doing something else in the exporter. We could do a final check as part of exporter shutdown to see if any pending spans need to be exported

Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php Outdated
@sanketmehta28
sanketmehta28 marked this pull request as draft May 25, 2022 09:58
@codecov

codecov Bot commented May 30, 2022

Copy link
Copy Markdown

Codecov Report

Merging #677 (2a31ed5) into main (e946dc7) will decrease coverage by 0.09%.
The diff coverage is 77.45%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #677      +/-   ##
============================================
- Coverage     79.52%   79.43%   -0.10%     
- Complexity     1405     1434      +29     
============================================
  Files           160      162       +2     
  Lines          3468     3564      +96     
============================================
+ Hits           2758     2831      +73     
- Misses          710      733      +23     
Flag Coverage Δ
7.4 79.43% <77.45%> (-0.10%) ⬇️
8.0 79.49% <77.45%> (-0.10%) ⬇️
8.1 79.49% <77.45%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/SDK/Common/Time/BlockingScheduler.php 0.00% <0.00%> (ø)
.../Common/Retry/ExponentialWithJitterRetryPolicy.php 76.66% <76.66%> (ø)
src/SDK/Trace/Behavior/SpanExporterTrait.php 87.50% <83.33%> (-12.50%) ⬇️
src/Contrib/OtlpGrpc/Exporter.php 91.30% <100.00%> (+1.14%) ⬆️
src/SDK/Trace/SpanExporter/LoggerExporter.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e946dc7...2a31ed5. Read the comment docs.

@sanketmehta28

Copy link
Copy Markdown
Member Author

Hi, Can anyone help me resolve this code coverage error?

@brettmc

brettmc commented May 31, 2022

Copy link
Copy Markdown
Contributor

Hi, Can anyone help me resolve this code coverage error?

It's complaining about a decrease in code coverage, specifically in SpanExporterTrait - you can make test-coverage locally, you will need to add/change some unit tests to ensure code coverage is not reduced by this PR.

@sanketmehta28
sanketmehta28 marked this pull request as ready for review June 22, 2022 10:29
@sanketmehta28

Copy link
Copy Markdown
Member Author

Just an explanation for not including fiber as of now:
currently we are supporting php 7.4 and 8.0 which does not support fiber out of the box. so to provide retry mechanism in those php versions we have to provide an implementation without fiber and separate implementation for php 8.1 onwards with fiber. so as of now it does not make sense to provide two separate implementation.

Also I have tried the default retry mechanism of GRPC which also blocks the exporter until retry times out or successful. .net otel module is using this same behaviour(PR) so it will not make much difference if this generic retry mechanism blocks the exporter.

Comment thread src/Contrib/OtlpGrpc/Exporter.php Outdated
@brettmc

brettmc commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

I think this needs an example of how to use and configure a retry policy, so that users can see it in action and understand how to configure (and disable/turn off)

Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php Outdated
Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php Outdated
Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php
Comment thread src/SDK/Trace/Behavior/SpanExporterTrait.php Outdated
Comment thread src/SDK/Common/Retry/RetryPolicyInterface.php Outdated
Comment thread tests/Unit/SDK/Common/Retry/ExponentialWithJitterRetryPolicyTest.php Outdated
@sanketmehta28

Copy link
Copy Markdown
Member Author

@tidal @Nevay: as you guys can see, most of the builds are getting failed because of doLog() function in LogsMessagetrait.php because doLog is also being defined in LoggerExporter.php but from loggerexporter.php it is trying to refer to doLog() function in LogsMessageTrait.php which is not right.

I believe it is a minor bug and we need to create an issue for the same.
Uploading Screenshot 2022-07-18 at 7.12.30 PM.png…

@brettmc

brettmc commented Jul 19, 2022

Copy link
Copy Markdown
Contributor

failed because of doLog() function in LogsMessagetrait.php

I understand now... By adding LogsMessagesTrait to SpanExporterTrait, our LoggerExporter ends up with two methods named doLog. In that case, it does seem reasonable to rename one of them as part of this PR (I'd nominate the one in LoggerExporter).
There have been a couple of unintended code changes in this PR so we were probably over-zealous in checking for them :)

@sanketmehta28

Copy link
Copy Markdown
Member Author

failed because of doLog() function in LogsMessagetrait.php

I understand now... By adding LogsMessagesTrait to SpanExporterTrait, our LoggerExporter ends up with two methods named doLog. In that case, it does seem reasonable to rename one of them as part of this PR (I'd nominate the one in LoggerExporter). There have been a couple of unintended code changes in this PR so we were probably over-zealous in checking for them :)

I will change in loggerExporter in this PR

Comment thread src/Contrib/OtlpGrpc/Exporter.php Outdated
Comment thread src/Contrib/OtlpGrpc/Exporter.php Outdated
Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php Outdated
Comment thread src/SDK/Trace/Behavior/SpanExporterTrait.php Outdated
Comment thread src/SDK/Common/Retry/RetryPolicyInterface.php Outdated
…uments to ExponentialRetryPolicy constructor. Resolving minor review comments
Comment thread src/SDK/Common/Retry/RetryPolicyInterface.php Outdated
@sanketmehta28
sanketmehta28 requested review from brettmc and tidal August 1, 2022 13:59
@sanketmehta28

Copy link
Copy Markdown
Member Author

@Nevay @tidal Please do review it and approve

Comment thread src/Contrib/OtlpGrpc/Exporter.php
Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php
{
public function shouldRetry(
int $attempt,
int $status

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this parameter is useful, will this ever be used for something besides checking for SpanExporterInterface::STATUS_FAILED_RETRYABLE?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For current state, it is only being used for checking if the status is STATUS_FAILED_RETRYABLE. but this can be checked against a list of retryable codes for diff retry policies and exporters.


while ($shouldRetry) {
// find the delay time before retry (it is 0 for the first attempt)
$delay = $this->retryPolicy->getDelay($attempt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the retry logic in the trait instead of the exporter complicates handling Retry-After header & co.
OTLP/HTTP Throttling

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have to put the retry logic in trait only because it is applicable to all span exporters and export() is actually implemented in that only.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Where do you suggest I should implement this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Nevay : Can you please give me an example where I can implement this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can ignore this; exporters that have to handle Retry-After should implement their own retry logic instead of using this trait.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok I will move the logic to exporter

Comment thread src/SDK/Common/Retry/ExponentialWithJitterRetryPolicy.php
) {
$this->checkArgument(
$backoff_multiplier > 1,
sprintf('Backoff multiplier must be greater than 0: "%s" value provided', $backoff_multiplier)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

must be greater than 1

@stale

stale Bot commented Oct 1, 2022

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale This issue didn't have recent activity label Oct 1, 2022
@stale

stale Bot commented Oct 16, 2022

Copy link
Copy Markdown

This issue has been automatically closed because it has not had recent activity, but it can be reopened. Thank you for your contributions.

@stale stale Bot closed this Oct 16, 2022
@bobstrecansky bobstrecansky added the pinned Will not be removed by stalebot label Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pinned Will not be removed by stalebot stale This issue didn't have recent activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTLP/GRPC exporter implementation - Missing retries on Exporter errors

5 participants