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

Add the ability to configure logback (MDC) to show identity_id and X-Request-ID in logs files when available. #7461

Merged
merged 2 commits into from
Dec 4, 2017

Conversation

sunix
Copy link
Contributor

@sunix sunix commented Nov 20, 2017

What does this PR do?

Add the ability to configure logback to show identity_id and X-Request-ID in logs files when available.

  • Add X-Request-ID http header in the logs through MDC
  • Add identity_id from keycloack when available in the logs through MDC

What issues does this PR fix or reference?

redhat-developer/rh-che#312

Release Notes

Add the ability to configure logback to show identity_id and X-Request-ID in logs files when available.

Docs PR

TODO

@sunix sunix added the kind/enhancement A feature request - must adhere to the feature request template. label Nov 20, 2017
@benoitf benoitf added the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Nov 20, 2017
@skabashnyuk
Copy link
Contributor

identity_id and X-Request-ID - what is the usecase for this value?
Shall we move this filter in separate artifact and reuse it on the agent as well?

@sunix
Copy link
Contributor Author

sunix commented Nov 22, 2017

  • Identity_id : to track the user related logs in a multi-user configuration
  • request_id : to track a request that goes through multiple sub system

I'm going to move the filter for request id somewhere else

@skabashnyuk
Copy link
Contributor

skabashnyuk commented Nov 22, 2017

Identity_id - ok. What does this value X-Request-Id mean for Che?

@sunix
Copy link
Contributor Author

sunix commented Nov 22, 2017

For Che it means that wherever the cluster environnement it is installed and where routers are using X-Request-Id, Che would be able to log these request-Ids out of the box

@skabashnyuk
Copy link
Contributor

What about the separate artifact and reuse it on the agent?
I thought about adding web application name to MDC too. It would be good place to do that. WDYT?

@sunix
Copy link
Contributor Author

sunix commented Nov 22, 2017

OK I'm OK to create a separate artifact, I was looking at an existing one and https://github.com/eclipse/che/tree/master/core/commons/che-core-commons-j2ee/src/main/java/org/eclipse/che/filter was looking good by its name but it seems to be included only in assembly-ide-war. Let me know if you have a prefer place and name for this artifact.

@sunix
Copy link
Contributor Author

sunix commented Nov 22, 2017

About the web application name, I'm not sure MDC is the right place: MDC works per thread and pretty much like a threadLocal would work.

@skabashnyuk
Copy link
Contributor

what if core/commons/che-core-commons-logback ?

@sunix
Copy link
Contributor Author

sunix commented Nov 22, 2017

I've updated the PR but for some reasons i can't get into the multi-user app, will investigate tomorow

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
Copy link
Contributor

Choose a reason for hiding this comment

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

this artifact is not provided. please remove this scope.

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.MDC;

Copy link
Contributor

Choose a reason for hiding this comment

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

javadoc

Copy link
Contributor

Choose a reason for hiding this comment

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

What about test?

@@ -103,6 +106,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}
}

putIdentityIdToMDC(subject);
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 you can replace it with just MDC.put(IDENTITY_ID_MDC_KEY, subject.getUserId());

Copy link
Contributor

Choose a reason for hiding this comment

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

wait. It should not be here.
I propose to make a separate filter in core/commons/che-core-commons-logback/ that will put subject id in mdc.

Signed-off-by: Sun Tan <sutan@redhat.com>
Signed-off-by: Sun Tan <sutan@redhat.com>
@sunix
Copy link
Contributor Author

sunix commented Dec 4, 2017

@skabashnyuk I've updated this PR can you check and approve if ok ? thanks

@sunix
Copy link
Contributor Author

sunix commented Dec 4, 2017

thanks

@sunix sunix merged commit 26725e5 into eclipse-che:master Dec 4, 2017
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Dec 4, 2017
@benoitf benoitf added this to the 5.22.0 milestone Dec 4, 2017
@skabashnyuk
Copy link
Contributor

@sunix will you provide che6 pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants