-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
.append(serverRequestParams.getMethodName()).append(" ") | ||
.append(size).append(" ") | ||
.append(System.currentTimeMillis()-startTime); | ||
error(sb.toString()); |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
We should change the signature to match how the grpc filter has
public void doProcessRequest(R request)
and
public void doProcessResponse(S response)
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.
done
examples/build.gradle
Outdated
@@ -88,7 +89,7 @@ task runHelloWorldServer(type: JavaExec) { | |||
classpath = sourceSets.main.runtimeClasspath | |||
mainClass = 'com.flipkart.gjex.examples.helloworld.HelloWorldApplication' | |||
args "server", "./src/main/resources/hello_world_config.yml" | |||
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' | |||
// jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' |
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.
uncheck this line.
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.
done
if (enableAccessLogs){ | ||
filtersMap.get(methodSignature).add(new GrpcAccessLogFilter()); | ||
} |
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 not do this before, and get it added in filtersForMethod
as required
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.
done
if (enableAccessLogs) { | ||
context.addFilter(new FilterHolder(accessLogFilter), "/*" , | ||
EnumSet.of(DispatcherType.REQUEST)); | ||
} |
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.
we should make extract this out to a private separate function
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.
done
@@ -150,7 +150,7 @@ public void run(T configuration, U configMap, Environment environment) { | |||
|
|||
// Add all Grpc Filters to the Grpc Server | |||
filters = getInstances(baseInjector, Filter.class); | |||
grpcServer.registerFilters(filters, bindableServices); | |||
grpcServer.registerFilters(filters, bindableServices, configuration.getGrpc().isEnableAccessLogs()); |
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.
lets not pass boolean in arguments. Arguments should be proper class or objects.
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.
done
* | ||
* @author ajay.jalgaonkar | ||
*/ | ||
public abstract class GjexFilter<Req, Res, M> implements Logging { |
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.
Remove the prefix Gjex
. Classes have aboslute names, so we don't need to prefix Gjex
since the class path itself has gjex
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.
done
* @param <Req> Proto V3 message | ||
* @param <Res> Proto V3 message | ||
*/ | ||
public abstract class GjexGrpcFilter<Req extends GeneratedMessageV3, Res extends GeneratedMessageV3> |
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.
Remove the prefix Gjex
. Classes have aboslute names, so we don't need to prefix Gjex
since the class path itself has gjex
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.
done
* @author ajay.jalgaonkar | ||
* | ||
*/ | ||
public class GrpcAccessLogGjexGrpcFilter<R extends GeneratedMessageV3, |
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.
Too much-repeated names?GrpcAccessLogFilter
should have been enough.
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.
done
* @author ajay.jalgaonkar | ||
*/ | ||
@Data | ||
public abstract class GjexHttpFilter extends GjexFilter<ServletRequest, ServletResponse, |
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.
please rename to HttpFilter
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.
done
public void doProcessRequest(RequestParams<ServletRequest, Set<String>> requestParams) { | ||
super.doProcessRequest(requestParams); | ||
} | ||
|
||
@Override | ||
public void doProcessResponseHeaders(Set<String> responseHeaders) { | ||
super.doProcessResponseHeaders(responseHeaders); | ||
} | ||
|
||
@Override | ||
public void doProcessResponse(ResponseParams<ServletResponse> responseParams) { | ||
super.doProcessResponse(responseParams); | ||
} |
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 are you defining this methods? These needs to be implemented by the implementors of this abstract class.
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.
removed
* information contained in the Request headers | ||
* | ||
* @author regu.b | ||
* | ||
*/ | ||
@Named("AuthFilter") | ||
public class AuthFilter implements Filter<HelloRequest, HelloReply>, Logging { | ||
public class AuthGjexGrpcFilter extends GjexGrpcFilter<HelloRequest, HelloReply> implements Logging { |
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.
Name correction please.
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.
done
* @author regu.b | ||
*/ | ||
@Named("LoggingFilter") | ||
public class LoggingFilter<Req extends GeneratedMessageV3, Res extends GeneratedMessageV3> implements Filter<Req, Res>, Logging { | ||
public class LoggingGjexGrpcFilter<Req extends GeneratedMessageV3, |
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.
Name correction please.
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.
done
@@ -1,6 +1,8 @@ | |||
Grpc: | |||
server.port: 50051 | |||
server.executorThreads : 4 | |||
grpcFilterConfig: |
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.
Access log can be a top level config.
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.
If there are other config params other than accesslog, then this filterconfig can be used.
did not want to keep accesslog related config separate
@@ -14,6 +16,8 @@ Api: | |||
service.selectors: 10 | |||
service.workers: 30 | |||
scheduledexecutor.threadpool.size: 1 | |||
httpFilterConfig: |
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.
Access log can be a top level config.
|
||
import java.util.Map; | ||
|
||
public class SampleApplication extends Application<SampleConfiguration, Map> { |
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 have we deleted these files?
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 back
Context previous = attachContext(contextWithHeaders); // attaching headers to gRPC context | ||
try { | ||
filters.forEach(filter -> filter.doProcessResponse((GeneratedMessageV3) response)); | ||
grpcFilters.forEach(filter -> filter.doProcessResponse(ResponseParams.builder().response(response).build())); |
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 wrap? what is the usecase?
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.
ResponseParams is a common class used for both http and grpc responses. so wrapped the grpc "response"
RequestParams requestParams = | ||
RequestParams.builder() | ||
.clientIp(call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString()) | ||
.resourcePath(call.getMethodDescriptor().getFullMethodName().toLowerCase()) | ||
.metadata(headers) | ||
.request(request) | ||
.build(); |
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 create this in loop? Can it not be outside?
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.
put it inside.
public void setScheduledExecutorThreadPoolSize(int scheduledExecutorThreadPoolSize) { | ||
this.scheduledExecutorThreadPoolSize = scheduledExecutorThreadPoolSize; | ||
} | ||
@JsonProperty("httpFilterConfig") |
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.
should be named filterConfig
since API Section itself is for HTTP
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.
Also, given that it contains a single boolean, may be we flatten it, and make accessLog as top level attribute.
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.
we should keep filterconfig as separate config for grpc and http. so it can't be top level.
in future other updates to filterconfig can come
this.executorThreads = executorThreads; | ||
} | ||
@JsonProperty("grpcFilterConfig") | ||
private GrpcFilterConfig grpcFilterConfig; |
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.
Same here, should be filterConfig
simply
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.
updated
* A Filter interface for processing Request, Request-Headers, Response and Response-Headers | ||
* around gRPC and HTTP method invocation | ||
* | ||
* @param <Req> Proto V3 message | ||
* @param <Res> Proto V3 message | ||
* @author ajay.jalgaonkar |
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.
Please dont change the original author information. Since there has been no new code 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.
reset
|
||
@Getter | ||
@Builder | ||
public class ResponseParams <S>{ |
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 is this required?
public long getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(long startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public RequestParams<R, Metadata> getRequestParams() { | ||
return requestParams; | ||
} | ||
|
||
public void setRequestParams(RequestParams<R, Metadata> requestParams) { | ||
this.requestParams = requestParams; | ||
} | ||
|
||
public StringBuilder getSb() { | ||
return sb; | ||
} | ||
|
||
public void setSb(StringBuilder sb) { | ||
this.sb = sb; | ||
} |
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 are these required, given that @Data
has been already used?
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.
removed
public long getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(long startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public StringBuilder getSb() { | ||
return sb; | ||
} | ||
|
||
public void setSb(StringBuilder sb) { | ||
this.sb = sb; | ||
} |
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.
Is this really required?
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.
removed
* @author ajay.jalgaonkar | ||
*/ | ||
|
||
@Data |
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 does this need to have Data
annotation? This is not a pojo class.
public class HttpFilterParams { | ||
private final Filter filter; | ||
private final String pathSpec; | ||
} |
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.
We already have RequestParams
which has simlar, can we merge?
@Named("AuthFilter") | ||
public class AuthFilter implements Filter<HelloRequest, HelloReply>, Logging { | ||
@Named("AuthGrpcFilter") | ||
public class AuthGrpcFilter extends GrpcFilter<HelloRequest, HelloReply> { |
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.
This can remain AuthFilter
Lets not change the grpc filter names. Gjex is major for grpc and http is provided for migration period. In long term i don't see the need for having this explicit name in filter.s
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.
done
@Named("LoggingFilter") | ||
public class LoggingFilter<Req extends GeneratedMessageV3, Res extends GeneratedMessageV3> implements Filter<Req, Res>, Logging { | ||
@Named("LoggingGrpcFilter") | ||
public class LoggingGrpcFilter<Req extends GeneratedMessageV3, |
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.
This can remain LoggingFilter
Lets not change the grpc filter names. Gjex is major for grpc and http is provided for migration period. In long term i don't see the need for having this explicit name in filter.s
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.
done
This reverts commit 38a2b4a.
* http-filters: tests Update HttpFilterInterceptor.java FilterInteceptor
No description provided.