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(client): replace jersey with okhttp in hugegraph-client (Draft PR) #508

Closed
wants to merge 0 commits into from

Conversation

zhenyuT
Copy link
Contributor

@zhenyuT zhenyuT commented Aug 14, 2023

1、直接修改hugegraph-client代码,覆盖common中的类
2、对于https自定义证书的实现暂时缺失
3、运行ci失败,且耗时较久(30min),部分单测执行出现connection timeout的异常。推测可能okhttp client的close存在问题,多次创建client实例导致内存/连接泄漏,导致存在性能问题

麻烦先看下代码,如果大体方向没问题的话,我再继续进行代码优化 (以及调整 hugegrpah-common 中的依赖, 目前是直接在 client 调整)

@github-actions github-actions bot added the client hugegraph-client label Aug 14, 2023
@imbajin
Copy link
Member

imbajin commented Aug 15, 2023

thanks and some todos:

  • seems also need handle https test in ci(loader/hubble..)?
  • fix dependencies check as the contribution doc example in website

Copy link
Member

@simon824 simon824 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, but we need fix ci first and improve codestyle refer to https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-style.xml

@imbajin imbajin requested review from z7658329 and javeme August 16, 2023 17:32
@zhenyuT
Copy link
Contributor Author

zhenyuT commented Aug 16, 2023

Overall looks good, but we need fix ci first and improve codestyle refer to https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-style.xml

I've done my best to fix the issues mentioned on,but there is one more problem. When I add the licence header in the file "hugegraph-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker",the unit test will run error.

@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Merging #508 (d3d3daf) into master (d9f234a) will increase coverage by 0.18%.
The diff coverage is 77.36%.

@@             Coverage Diff              @@
##             master     #508      +/-   ##
============================================
+ Coverage     62.42%   62.60%   +0.18%     
- Complexity      895     1937    +1042     
============================================
  Files            91      265     +174     
  Lines          4404     9689    +5285     
  Branches        519      900     +381     
============================================
+ Hits           2749     6066    +3317     
- Misses         1450     3228    +1778     
- Partials        205      395     +190     
Files Changed Coverage Δ
...va/org/apache/hugegraph/api/gremlin/CypherAPI.java 50.00% <0.00%> (ø)
...n/java/org/apache/hugegraph/driver/HugeClient.java 82.08% <0.00%> (ø)
.../apache/hugegraph/rest/OkhttpTokenInterceptor.java 0.00% <0.00%> (ø)
...ava/org/apache/hugegraph/api/graphs/GraphsAPI.java 67.39% <66.66%> (ø)
...va/org/apache/hugegraph/rest/OkhttpRestResult.java 67.64% <67.64%> (ø)
...pache/hugegraph/rest/OkhttpAbstractRestClient.java 68.68% <68.68%> (ø)
...java/org/apache/hugegraph/api/graph/VertexAPI.java 77.35% <81.81%> (ø)
...n/java/org/apache/hugegraph/rest/OkhttpConfig.java 90.90% <90.90%> (ø)
.../java/org/apache/hugegraph/api/auth/AccessAPI.java 100.00% <100.00%> (ø)
.../java/org/apache/hugegraph/api/auth/BelongAPI.java 100.00% <100.00%> (ø)
... and 45 more

... and 119 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@imbajin
Copy link
Member

imbajin commented Aug 16, 2023

Overall looks good, but we need fix ci first and improve codestyle refer to apache/incubator-hugegraph@master/hugegraph-style.xml

I've done my best to fix the issues mentioned on,but there is one more problem. When I add the licence header in the file "hugegraph-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker",the unit test will run error.

if u point this, exclude it in plugin settings if we really don't need or can't add license header in it (also check maven-rat in pom.xml)

image

@@ -0,0 +1 @@
mock-maker-inline
Copy link
Member

@imbajin imbajin Aug 16, 2023

Choose a reason for hiding this comment

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

maybe we could try to add license header for it first if (it's) necessary

Suggested change
mock-maker-inline
# license header with `#` comment
# ....
# end license
mock-maker-inline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we could try to add license header for it first if (it's) necessary

This just works fine, thank you.

Copy link
Contributor

@javeme javeme left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution

return UriComponent.encode(raw, Type.QUERY_PARAM_SPACE_ENCODED);
}
// public static String encode(String raw) {
// return UriComponent.encode(raw, Type.QUERY_PARAM_SPACE_ENCODED);
Copy link
Contributor

Choose a reason for hiding this comment

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

any alternative plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any alternative plan?

看原来代码的意图,是要对url中的参数进行编码。但是okhttp中使用HttpUrl.Builder构建url,其实会自动进行编码的,所以感觉没必要由使用方对参数编码后再传参

@@ -55,7 +56,7 @@

public class RestResultTest extends BaseUnitTest {

private jakarta.ws.rs.core.Response mockResponse;
private okhttp3.Response mockResponse;
Copy link
Contributor

Choose a reason for hiding this comment

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

just import the Response class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里之前用的jakartar包中的Response,现在实现改为okhttp,因此对应mock的对象也修改为okhttp包中的Response。这样做是存在什么问题?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I mean we can try to import okhttp3.Response

@javeme
Copy link
Contributor

javeme commented Aug 17, 2023

麻烦先看下代码,如果大体方向没问题的话,我再继续进行代码优化 (以及调整 hugegrpah-common 中的依赖, 目前是直接在 client 调整)

整体方案没问题的。
CI失败,看了下是超时问题SocketTimeoutException,请确保各类超时时间设置正确了:

MultiNodeShortestPathApiTest Time elapsed: 10.038 s  <<< ERROR!
java.net.SocketTimeoutException: timeout

@zhenyuT
Copy link
Contributor Author

zhenyuT commented Aug 17, 2023

麻烦先看下代码,如果大体方向没问题的话,我再继续进行代码优化 (以及调整 hugegrpah-common 中的依赖, 目前是直接在 client 调整)

整体方案没问题的。 CI失败,看了下是超时问题SocketTimeoutException,请确保各类超时时间设置正确了:

MultiNodeShortestPathApiTest Time elapsed: 10.038 s  <<< ERROR!
java.net.SocketTimeoutException: timeout

有点奇怪,我fork到自己仓库,执行是成功的,没有遇到超时的问题。两边执行是有什么区别吗?

@github-actions github-actions bot added the hubble hugegraph-hubble label Aug 17, 2023
@z7658329
Copy link
Member

seems good, do you have test introducing the new hugegrap-client dependency in a spring boot project and ensured that it starts up correctly? and you need to cover two scenarios: jdk8/jdk11 + springboot2.X and jdk17 + springboot3, you can refer 495 @zhenyuT

@zhenyuT
Copy link
Contributor Author

zhenyuT commented Aug 27, 2023

seems good, do you have test introducing the new hugegrap-client dependency in a spring boot project and ensured that it starts up correctly? and you need to cover two scenarios: jdk8/jdk11 + springboot2.X and jdk17 + springboot3, you can refer 495 @zhenyuT

I've test with springboot2.X and springboot3,but just simple test.

@@ -37,28 +37,73 @@
</description>

<properties>
<lombok.version>1.18.8</lombok.version>
<okhttp.version>4.10.0</okhttp.version>
Copy link
Member

Choose a reason for hiding this comment

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

shoule extract dependency version to root pom.xml, sub module just import?

Copy link
Member

Choose a reason for hiding this comment

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

shoule extract dependency version to root pom.xml, sub module just import?

seems no need, only extract dependencies that multiple modules need to use (leave single usage alone?)

@simon824
Copy link
Member

simon824 commented Sep 5, 2023

LGTM, @zhenyuT please resolve conflicts when you are free.

return result.readObject(User.class);
}

public UserRole getUserRole(Object id) {
String idEncoded = RestClient.encode(formatEntityId(id));
// String idEncoded = RestClient.encode(formatEntityId(id));
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove the unused code

MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

headers.putSingle("Content-Encoding", BATCH_ENCODING);
RestResult result = this.client.put(this.batchPath(), null,
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

RestResult result = this.client.put(this.batchPath(), null,
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Headers headers = new Headers.Builder().add("Content-Encoding", BATCH_ENCODING).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

define a const?

MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-Encoding", BATCH_ENCODING);
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
// headers.putSingle("Content-Encoding", BATCH_ENCODING);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@Builder
@Getter
@Setter
public class OkhttpConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

expect a blank line after the class define


import java.util.Map;

public interface OkhttpRestClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to Okhttp prefix, we expect to keep the same interface name

import java.util.ArrayList;
import java.util.List;

public class OkhttpRestResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to Okhttp prefix

@@ -55,7 +56,7 @@

public class RestResultTest extends BaseUnitTest {

private jakarta.ws.rs.core.Response mockResponse;
private okhttp3.Response mockResponse;
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I mean we can try to import okhttp3.Response

pom.xml Outdated
<!-- <version>${jersey.version}</version>-->
<!-- <type>pom</type>-->
<!-- <scope>import</scope>-->
<!-- </dependency>-->
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove all the unused code

@javeme
Copy link
Contributor

javeme commented Sep 10, 2023

implemented by apache/incubator-hugegraph-commons#133

@github-actions
Copy link

Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client hugegraph-client hubble hugegraph-hubble inactive
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants