Skip to content

Retry flush metrics from ThreadStats to Datadog over RemoteDisconnected errors. #138

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

Merged

Conversation

tianchu
Copy link
Collaborator

@tianchu tianchu commented Apr 30, 2021

What does this PR do?

Retry metric flushing from ThreadStats to Datadog over RemoteDisconnected errors. The root issue https://hg.python.org/cpython/rev/eba80326ba53 has been discussed extensively for years, but from what I can tell no fix was implemented at any level. The main reason to not fix (e.g., retry at the http client level) seems to be concerns with POST requests are often not idempotent and not always safe to retry, which is generally speaking true. But according to my comprehensive tests (one submission per minute for 2 days), all the failures resulted in missing data and therefore were safe to be retried. The testing function has been running for a day and I did not see any duplicate date points.

Based on the lengthy discussion on the internet over this particular issue, I don't think we can really wait for a true/better fix in the underlying libraries. The benefits of moving forward with a retry far outweigh the potential concerns over idempotency.

Specific changes are:

  • Unmute the datadog api client to surface the ClientError to datadog-lambda, so we can catch and handle it
  • Retry once if the error is RemoteDisconnected, otherwise log the exception for debugging

Motivation

Metric data points are lost sporadically when being submitted synchronously from the Datadog Lambda library to Datadog API (i.e., without using the Forwarder Lambda or Lambda Extension). The specific error reads below:

datadog.api.exceptions.ClientError: Could not request POST https://api.datadoghq.com/api/v1/distribution_points: 
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')). 
Please check the network connection or try again later. If the problem persists, please contact [email protected]

Testing Guidelines

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@tianchu tianchu requested a review from a team as a code owner April 30, 2021 18:52
@tianchu tianchu force-pushed the tian.chu/retry-metric-submission-over-remote-disconnected branch 3 times, most recently from e2c1705 to 89839f0 Compare April 30, 2021 19:40
@tianchu tianchu force-pushed the tian.chu/retry-metric-submission-over-remote-disconnected branch from 89839f0 to 9acf741 Compare April 30, 2021 19:46
try:
lambda_stats.reporter.flush_distributions(dists)
except Exception as e:
# The nature of the root issue https://bugs.python.org/issue41345 is to be complex,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# The nature of the root issue https://bugs.python.org/issue41345 is to be complex,
# The nature of the root issue https://bugs.python.org/issue41345 is complex,

Copy link
Contributor

@hghotra hghotra left a comment

Choose a reason for hiding this comment

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

💯

@tianchu tianchu merged commit 601c5f8 into main May 3, 2021
@tianchu tianchu deleted the tian.chu/retry-metric-submission-over-remote-disconnected branch May 3, 2021 15:00
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.

2 participants