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

[PIP28][PROXY] Pulsar Proxy Gateway Improvement #3915

Merged
merged 1 commit into from
May 8, 2019

Conversation

foreversunyao
Copy link
Contributor

Motivation

https://github.com/apache/pulsar/wiki/PIP-28%3A-Pulsar-Proxy-Gateway-Improvement

Modifications

added a new handler ParserProxyHandler.java to parse requests independently and output

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: don't know
  • The default values of configurations: yes
  • The wire protocol: no
  • The rest endpoints: no
  • The admin cli options: no
  • Anything that affects deployment: performance

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? need a doc
    Still working on this feature, will make a document after it's almost done

@foreversunyao
Copy link
Contributor Author

Work in progress I am still working on this feature, no need to review currently.

@foreversunyao foreversunyao force-pushed the pip28-v2 branch 3 times, most recently from 547e23c to 9fe61ce Compare March 28, 2019 14:25
@sijie sijie changed the title [PIP28][PROXY] Pulsar Proxy Gateway Improvement (WIP) [PIP28][PROXY] Pulsar Proxy Gateway Improvement Mar 29, 2019
@sijie
Copy link
Member

sijie commented Mar 29, 2019

@foreversunyao I prepended (WIP) in the caption. feel free to remove it when it is ready for reviews.

@foreversunyao
Copy link
Contributor Author

@foreversunyao I prepended (WIP) in the caption. feel free to remove it when it is ready for reviews.

sure, still testing if it can cover all scenarios

@foreversunyao foreversunyao force-pushed the pip28-v2 branch 2 times, most recently from 2e65a09 to e562a50 Compare April 8, 2019 12:27
@foreversunyao
Copy link
Contributor Author

run cpp tests

@foreversunyao foreversunyao force-pushed the pip28-v2 branch 2 times, most recently from cb6e924 to 67aff21 Compare April 9, 2019 13:24
@foreversunyao foreversunyao changed the title (WIP) [PIP28][PROXY] Pulsar Proxy Gateway Improvement [PIP28][PROXY] Pulsar Proxy Gateway Improvement Apr 9, 2019
@foreversunyao foreversunyao force-pushed the pip28-v2 branch 4 times, most recently from 53a0c06 to 345fc3a Compare April 9, 2019 14:44
@foreversunyao
Copy link
Contributor Author

@sijie , should be ready to review, though there are two minor differences with original PIP-28.

  • frameDecoder: when enable full parsing feature, code will keep frameDecoder handler in pipeline(could not be as fast as tcp direct proxy and parsing buffer separately)
  • lag: it was time cost of proxy processing, but after second thought showing lag(producer lag could be latency and consumer lag) could be more reasonable for pub-sub system

@foreversunyao
Copy link
Contributor Author

run java8 tests

2 similar comments
@foreversunyao
Copy link
Contributor Author

run java8 tests

@foreversunyao
Copy link
Contributor Author

run java8 tests

@foreversunyao
Copy link
Contributor Author

foreversunyao commented Apr 11, 2019

tested it locally, and passed

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.pulsar.proxy.server.ProxyLookupThrottlingTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.585 s - in org.apache.pulsar.proxy.server.ProxyLookupThrottlingTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

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

overall looks good. left some comments, most of them are around coding styles (i.e. spaces).

also it would be good to have some unit tests or integration tests for this feature. or at least make sure the proxy is working well when proxyLogLevel > 0 as when proxyLogLevel == 0.


private Channel channel;
//inbound
protected static final String frontendConn = "frontendconn";
Copy link
Member

Choose a reason for hiding this comment

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

nit: use upper case for CONSTANTS.

Suggested change
protected static final String frontendConn = "frontendconn";
protected static final String FRONTEND_CONN = "frontendconn";

//inbound
protected static final String frontendConn = "frontendconn";
//outbound
protected static final String backendConn = "backendconn";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
protected static final String backendConn = "backendconn";
protected static final String BACKEND_CONN = "backendconn";

@@ -148,6 +148,15 @@
doc = "Path for the file used to determine the rotation status for the proxy instance"
+ " when responding to service discovery health checks"
)
private Integer proxyLogLevel = 0;

@FieldContext(
Copy link
Member

Choose a reason for hiding this comment

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

I think the @FieldContext was added to the wrong place. it should be for proxyLogLevel, and the one for proxyLogLevel should be for statusFilePath.

this.connType=type;
}

private void logging (Channel conn,PulsarApi.BaseCommand.Type cmdtype,String info,List<RawMessage> messages) throws Exception{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private void logging (Channel conn,PulsarApi.BaseCommand.Type cmdtype,String info,List<RawMessage> messages) throws Exception{
private void logging(Channel conn, PulsarApi.BaseCommand.Type cmdtype, String info, List<RawMessage> messages) throws Exception {


private void logging (Channel conn,PulsarApi.BaseCommand.Type cmdtype,String info,List<RawMessage> messages) throws Exception{

if (messages !=null){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (messages !=null){
if (messages !=null) {

if (messages !=null){
// lag
for (int i=0;i <messages.size();i++){
info = info + "["+(System.currentTimeMillis() - messages.get(i).getPublishTime())+"] "+new String(ByteBufUtil.getBytes((messages.get(i)).getData()),"UTF8");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
info = info + "["+(System.currentTimeMillis() - messages.get(i).getPublishTime())+"] "+new String(ByteBufUtil.getBytes((messages.get(i)).getData()),"UTF8");
info = info + "["+ (System.currentTimeMillis() - messages.get(i).getPublishTime()) + "] " + new String(ByteBufUtil.getBytes((messages.get(i)).getData()), "UTF8");


switch (this.connType){
case ParserProxyHandler.frontendConn:
log.info("conn:{} cmd:{} msg:{}","["+ conn.remoteAddress().toString()+""+conn.localAddress()+channel.localAddress()+channel.remoteAddress()+"]",cmdtype,info);
Copy link
Member

Choose a reason for hiding this comment

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

I see conn.localAddress() is used twice in this logging statement. is that done intentionally?

Suggested change
log.info("conn:{} cmd:{} msg:{}","["+ conn.remoteAddress().toString()+""+conn.localAddress()+channel.localAddress()+channel.remoteAddress()+"]",cmdtype,info);
log.info("conn:{} cmd:{} msg:{}", "[" + conn.remoteAddress().toString() + conn.localAddress() + channel.localAddress() + channel.remoteAddress() +"]", cmdtype,info);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, actually I was trying to add the feautre(whitelist for client as well as broker side), this need get broker ip/port from inbound channel, but right now it would be in next PR. I will update this.

case ParserProxyHandler.frontendConn:
log.info("conn:{} cmd:{} msg:{}","["+ conn.remoteAddress().toString()+""+conn.localAddress()+channel.localAddress()+channel.remoteAddress()+"]",cmdtype,info);
break;
case ParserProxyHandler.backendConn:
Copy link
Member

Choose a reason for hiding this comment

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

same comments as above

ByteBuf buffer = (ByteBuf)(msg);

try {
//
Copy link
Member

Choose a reason for hiding this comment

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

remove this line


log.error("{},{},{}",e.getMessage(),e.getStackTrace(),e.getCause());

}finally {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}finally {
} finally {

@foreversunyao
Copy link
Contributor Author

@sijie , thanks for reviewing, will update soon.

@foreversunyao foreversunyao force-pushed the pip28-v2 branch 3 times, most recently from 5b8c218 to a7d2ced Compare April 15, 2019 14:13
@foreversunyao
Copy link
Contributor Author

@sijie , I updated the code according to what you mentioned, and also added a unitest ProxyParserTest.java

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

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

LGTM +1

@sijie sijie added area/proxy type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages type/feature The PR added a new feature or issue requested a new feature labels Apr 16, 2019
@sijie sijie added this to the 2.4.0 milestone Apr 16, 2019
@sijie sijie requested review from merlimat and jiazhai April 16, 2019 08:34
import java.util.Map;


public class ParserProxyHandler extends ChannelInboundHandlerAdapter {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any intention to extend the functionality for this class?
Seems currently it is mainly for proxy logging handling. How about rename this class name to make it clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for reviewing.

yes, I would add some whitelist feature on client ip/broker ip ,topic name and msg content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parsing protocol should be the first step for other future funtions

Copy link
Member

@jiazhai jiazhai left a comment

Choose a reason for hiding this comment

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

+1, thanks for the work. left a minor comments.

@sijie sijie merged commit 95f07f8 into apache:master May 8, 2019
@foreversunyao foreversunyao deleted the pip28-v2 branch May 14, 2019 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants