-
Notifications
You must be signed in to change notification settings - Fork 17
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
Revamp Filters, Support for HTTP Filters, AccessLog Filters #71
Changes from 9 commits
8952324
0f99aca
60c54a2
bf39538
df8105b
40d375e
68c472e
30da9b9
1f686fd
845bb19
e7e5fc7
0fb3927
c3f72e0
09b8a45
a8f033e
f5303c8
91ff9ad
b293189
0072103
bf4c094
8305794
9b90533
0d3f242
fab2122
3bf1922
af09b38
a1c1c48
1fe6d27
401f0a0
5f6e76e
c40e70d
eb157b2
a5ab4dd
cd9439f
01602ba
02c8946
f6ce472
bb985c2
8cb8ac1
7122c2e
f29d4a3
0372965
f5a71dc
c6b69df
d181572
b965c83
8801ca8
a0f93cf
3ef92b3
44a11d2
d12fe01
56fdef2
cf26e64
38a2b4a
87ed452
497c035
07abf21
ed035f0
1f62b1f
1e5d26e
50d5f76
888fab5
1c9601c
04c6d6d
8a91c93
c18d63b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.flipkart.gjex.core.filter; | ||
|
||
import com.flipkart.gjex.core.logging.Logging; | ||
import com.google.protobuf.GeneratedMessageV3; | ||
import io.grpc.Metadata; | ||
|
||
/** | ||
* Filter for logging grpc access log requests | ||
* @author ajay.jalgaonkar | ||
* | ||
*/ | ||
public class GrpcAccessLogFilter <R extends GeneratedMessageV3, | ||
S extends GeneratedMessageV3> implements Filter<R, S>, Logging { | ||
private long startTime = 0; | ||
private ServerRequestParams serverRequestParams; | ||
@Override | ||
public Filter<R,S> getInstance(){ | ||
return new GrpcAccessLogFilter<>(); | ||
} | ||
|
||
@Override | ||
public void doProcessRequest(R request) { | ||
this.startTime = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void doFilterRequest(ServerRequestParams serverRequestParams, Metadata headers) { | ||
this.serverRequestParams = serverRequestParams; | ||
} | ||
|
||
@Override | ||
public void doProcessResponseHeaders(Metadata responseHeaders) {} | ||
|
||
@Override | ||
public void doProcessResponse(S response) { | ||
String size = null; | ||
if (response != null){ | ||
size = String.valueOf(response.getSerializedSize()); | ||
} | ||
StringBuilder sb = new StringBuilder() | ||
.append(serverRequestParams.getClientIp()).append(" ") | ||
.append(serverRequestParams.getMethodName()).append(" ") | ||
.append(size).append(" ") | ||
.append(System.currentTimeMillis()-startTime); | ||
error(sb.toString()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.flipkart.gjex.core.web.filter; | ||
|
||
import com.flipkart.gjex.core.logging.Logging; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Filter for logging http access log requests | ||
* @author ajay.jalgaonkar | ||
* | ||
*/ | ||
|
||
@Singleton | ||
@Named("HttpAccessLogFilter") | ||
public class HttpAccessLogFilter implements Filter, Logging { | ||
private long startTime; | ||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException {} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change the signature to match how the grpc filter has
and
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
startTime = System.currentTimeMillis(); | ||
chain.doFilter(request, response); | ||
StringBuilder sb = new StringBuilder(); | ||
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse){ | ||
HttpServletRequest httpServletRequest= (HttpServletRequest) request; | ||
HttpServletResponse httpServletResponse = (HttpServletResponse) response; | ||
sb.append(httpServletRequest.getHeader("x-forwarded-for")).append(" ") | ||
.append(httpServletRequest.getRequestURI()).append(" ") | ||
.append(httpServletResponse.getStatus()).append(" ") | ||
.append(httpServletResponse.getHeader("Content-Length")).append(" "); | ||
} else { | ||
sb.append("Did not get HTTP request").append(" "); | ||
} | ||
sb.append(request.getRemoteAddr()).append(" "); | ||
sb.append(System.currentTimeMillis()-startTime); | ||
error(sb.toString()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why error? here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added access-log separately and made it info