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

fix: Don't call c.Error(...) inside echotrace middlewares #2609

Merged
merged 6 commits into from Apr 10, 2024

Conversation

nakkamarra
Copy link
Contributor

What does this PR do?

This PR removes the calls to c.Error(...) inside echotrace middlewares to remove duplicate calls to the registered echo.HTTPErrorHandler

Motivation

As described in the issue filed, we don't need to both invoke Error func and return the error up the chain of middlewares (as this will cause the registered error handler to execute twice), and it seems best to me to simply return the error so that the default error handler can handle this error, and as well as any custom error handle can without any hacks needed.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

Copy link

github-actions bot commented Apr 1, 2024

This PR is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Stuck for more than 1 month label Apr 1, 2024
Copy link
Contributor

@rarguelloF rarguelloF left a comment

Choose a reason for hiding this comment

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

My only concern with these changes is the possibility of breaking existing applications that rely in the existing behavior (even though they probably shouldn't...). Any thoughts? @darccio

return err
}
return nil
return next(c)
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 we should add some test to verify this behavior and ensure we don't introduce a regression in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rarguelloF Actually, if somebody was relying in the existing behaviour, they probably won't feel a difference. The existing behaviour blocked middlewares running before our own to manipulate the response, as c.Error already commited it to the client.

I think it's safe to go ahead as it is right now.

@rarguelloF rarguelloF removed the stale Stuck for more than 1 month label Apr 1, 2024
@@ -163,7 +167,6 @@ func TestError(t *testing.T) {
called = true

err := wantErr
c.Error(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rarguelloF I've updated the test to ensure that the error handler is called once, and I've removed the c.Error call here as well, since this is a test handler and from the echo docs we don't want to explicitly invoke the c.Error inside of handlers.

// Avoid using this method in handlers as no middleware will be able to effectively handle errors after that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that this change has removed this call and not broken anything in the rest of test should hopefully further highlight the fact that the expected behavior is already happening without this call, and explicitly calling it is causing as a second, unnecessary call.

@darccio
Copy link
Contributor

darccio commented Apr 4, 2024

I approve this but I'll wait to @rarguelloF final approval.

@nakkamarra
Copy link
Contributor Author

Hey, thanks for approving @darccio @rarguelloF I'm not sure that the failing unit tests are related to my changes, they are in a separate contrib directory, seems to be a flaky test.

@darccio
Copy link
Contributor

darccio commented Apr 10, 2024

@nakkamarra Yes, it is a flaky test. We opened an issue to work on it: #2641

@darccio darccio merged commit f44904a into DataDog:main Apr 10, 2024
100 checks passed
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.

None yet

3 participants