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

feat: generic HttpLoggingInterceptor #5037

Merged
merged 9 commits into from
Apr 27, 2023

Conversation

manusa
Copy link
Member

@manusa manusa commented Apr 6, 2023

Description

Relates to (should fix):

PoC to replace the OkHttp-specific HttpLoggingInterceptor with a Fabric8-specific implementation that works across all of our HttpClients.

The HttpLoggingInterceptor implementation is following a deferred approach. This means that the messages are only logged once the server responds and the response is completely processed by the client. This allows to log the request (and its body), the response, and the response body in a neat and grouped way. Other alternatives can be considered.

The Interceptor interface after method had to be further modified (on top of changes already provided in #5025), to allow to uniquely identify the original requests. HttpClients freely copy the original request to propagate it around which prevents keeping a consistent identifier (HttpRequests are copied either to propagate them, or to start new ones)

Additional changes had to be completed in the WebSocket handling in order to allow to fully intercept and log the HTTP upgrade requests and responses. We should look into completely removing the WebSocketResponse wrapper class in the future.

Some questions/topics

  • Do we prefer the neat and sorted deferred logging, or shall we consider immediate logging instead?
  • Log format is similar to that provided by cURL, but can likely be improved
  • Does this look good in general? should we keep moving in this direction?

I'll continue by implementing tests and addressing any comments once I get some feedback about this.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@manusa manusa added the wip label Apr 6, 2023
@manusa manusa force-pushed the fix/untyped-module-inference branch 3 times, most recently from 843660d to 67e02d3 Compare April 11, 2023 15:07
@Override
public void consume(List<ByteBuffer> value, AsyncBody asyncBody) throws Exception {
// TODO: Should try to detect if the body is text or not? (HttpLoggingInterceptor.isPlainText)
value.stream().map(BufferUtil::copy).forEach(responseBody::add); // Potential leak
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes doing something like a long running log watch, an http watch, etc. would indefinitely build up here. This will need to be bounded in some way - time, size, or both.

Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa force-pushed the fix/untyped-module-inference branch from 67e02d3 to 83dbdd4 Compare April 27, 2023 09:59
@manusa
Copy link
Member Author

manusa commented Apr 27, 2023

Hi @shawkins,
I'd like to see if we can fit this into 6.6 to overcome some of the downstream issues with regards to the logging interceptor.
I'll try to address the issue with the body logging.
Regarding the rest of open questions, any opinions?
Do you think we can go forward with this approach and already replace the OkHttp logging interceptor? Or is there anything critical that should be added prior to removing the other interceptor and introducing this one?

@shawkins
Copy link
Contributor

Regarding the rest of open questions, any opinions?

Checking now. The biggest open question is over the body logging. As long as it's bounded and has the binary detection, I think we're good.

manusa added 2 commits April 27, 2023 14:29
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa force-pushed the fix/untyped-module-inference branch 2 times, most recently from 25368cf to a53ff64 Compare April 27, 2023 13:14
@shawkins
Copy link
Contributor

shawkins commented Apr 27, 2023

@manusa a concern with the current pr is that it will catch exactly 1 response in the chain - depending upon the relative position of the logging interceptor. To catch all intermediate requests, for example backwards compatibility modifications, we need more notification of after so that each can be logged. One possible way of doing this is to expand the after calls (I realize this is different than how before is handled) - https://github.com/manusa/kubernetes-client/compare/fix/untyped-module-inference...shawkins:kubernetes-client:logging?expand=1 such a change would also help cut down on the state held by the logging interceptor

manusa and others added 6 commits April 27, 2023 17:21
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa force-pushed the fix/untyped-module-inference branch from 53bbf55 to 40a9164 Compare April 27, 2023 15:37
@manusa manusa removed the wip label Apr 27, 2023
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

29.7% 29.7% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM

@manusa manusa changed the title wip: feat: generic HttpLoggingInterceptor feat: generic HttpLoggingInterceptor Apr 27, 2023
@manusa manusa added this to the 6.6.0 milestone Apr 27, 2023
@manusa manusa merged commit 8f09f4d into fabric8io:master Apr 27, 2023
manusa added a commit that referenced this pull request Apr 27, 2023
Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa deleted the fix/untyped-module-inference branch April 27, 2023 16:58
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