Conversation
b781075 to
2cd0e39
Compare
2cd0e39 to
bf07265
Compare
Session hijacking is a design mistake. Without it Proxy has full ownership of the connections. This also simplifies the overall workflow and makes code less error-prone. Fixes #497
Modifiers are changed to return errors.
Unify error handling for all callers of writeResponse().
Reduce the scope of writeResponse() and unify proxyConn and proxyHandler response writing API.
Unify error logging in proxyConn and proxyHandler.
Remove Session as it has no purpose beyond hijacking. Move secure connection detection to newProxyConn(), thanks to that we no longer call locking ConnectionState() on every request.
ErrorStatus enables communication between martian packages and ErrorResponse() implementations. ErrorStatus can be returned as a request or response modification error and instructs ErrorResponse() what is the desired status code.
As we handle RequestModifier errors now it makes sense to fail fast. The RequestModifier responsibility has been moved to martian.ErrorStatus, and will be handled in Forwarder.
The use RT skipping is limited to testing only, as on RequestModifier error the RT is automatically skipped. Replace RT skipping per context with global Proxy.TestingSkipRoundTrip for testing purposes.
Add traceID type responsible for the request trace ID generation. The traceID is attached to request context on read. Remove Context struct as it serves no purpose.
Remove all logic from logger the package just map calls from package level function to the provided Logger impl. Add context to the Logger interface, this allows to add custom logger wrappers using the context information.
Move trace ID logging logic close to traceID. Use logger stacking to add features to logs. This is only temporary and traceID should be moved to the toplevel log package. To make it work we would need to change the main Logger interface, see #544.
bf07265 to
500ced2
Compare
Choraden
reviewed
Feb 9, 2024
log/martianlog/martianlog.go
Outdated
|
|
||
| var _ martianlog.Logger = contextLogger{} | ||
|
|
||
| func (l contextLogger) Errorf(_ context.Context, format string, args ...interface{}) { |
Contributor
There was a problem hiding this comment.
Let's use any instead of interface{}.
BTW the linter should have caught it.
Contributor
|
I'm afraid, this does not fully fix #498 as it still reports denied requests as errors in metrics. Let's open another one or do not resolve it here. |
Contributor
|
While trying new via loop detection mechanism, I found #688. This PR did not introduce this. It exists in the old approach as well. |
Treat label "-" as ignore indicator, and do not record deny errors in errors metric. Fixes #498
4e19492 to
9872032
Compare
Choraden
reviewed
Feb 12, 2024
| } | ||
|
|
||
| hp.metrics.error(label) | ||
| if label != "-" { |
Contributor
There was a problem hiding this comment.
A constant would fit better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patchset is a significant refactoring of the martian core.
It's a continuation of work initiated in #444.
The
RequestModifierandResponseModifiererrors are handled and appropriate error response is generated based onErrorResponse(). Subsequently the connection hijacking functionality is removed.Proxy connection
proxyConnis introduced, and proxy code is restructured to more files focused around specific topics. TheproxyConnandproxyHandlerhave similar structure for easier navigation and compatibility. The Proxy remains for configuration and generic shared items. This has been done in #673 but we expand on it here.A
TraceIDis added and it takes the responsibility of request ID generation and duration tracking. The custom Context and Session structs are removed resulting in streamlined function interfaces. TraceID is attached to request context on creation.Logging is streamlined, single responsibility principle is applied allowing for logger stacking. Each logger has its domain.
Fixes #525
Fixes #523
Fixes #497
Fixes #498