-
Notifications
You must be signed in to change notification settings - Fork 521
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
fix(server): fix server slow log, support loader import & client IP #2466
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2466 +/- ##
============================================
- Coverage 56.94% 49.91% -7.03%
+ Complexity 827 741 -86
============================================
Files 612 612
Lines 49672 49697 +25
Branches 6681 6685 +4
============================================
- Hits 28284 24806 -3478
- Misses 18572 22317 +3745
+ Partials 2816 2574 -242 ☔ View full report in Codecov by Sentry. |
|
||
// TODO: temporarily comment it to fix loader bug, handle it later | ||
/*// record the request json | ||
private void recordRequestJson(ContainerRequestContext context) throws IOException { |
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.
prefer collectRequestParams()
, seems 'record' means output to log
bufferedStream.mark(Integer.MAX_VALUE); | ||
|
||
context.setProperty(REQUEST_PARAMS_JSON, | ||
IOUtils.toString(bufferedStream, Charsets.toCharset(CHARSET))); |
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.
maybe it's very large for batch-write, can we cut part of the content?
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.
maybe we can cut the special length? like 512?
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.
or we will make it can be config? like 512/1024/2048 and default will be 512? @imbajin @liuxiaocs7 @VGalaxies
.getPathParameters(); | ||
requestParamsJson = pathParameters.toString(); | ||
context.setProperty(REQUEST_PARAMS_JSON, | ||
context.getUriInfo().getPathParameters().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.
can we also add all other branchs like PUT/DELETE
LOG.info("[Slow Query] ip={} execTime={}ms, body={}, method={}, path={}, query={}", | ||
getClientIP(requestContext), executeTime, | ||
requestContext.getProperty(REQUEST_PARAMS_JSON), method, path, | ||
uri.getQuery()); |
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.
are they repeated when GET: uri.getQuery() and REQUEST_PARAMS_JSON
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.
for GET , REQUEST_PARAMS_JSON will extract the id
info from /example/{id}
; uri.getQuery() will extract id=1
from http://example.com/resource?id=1
executeTime, null, method, path, uri.getQuery()); | ||
|
||
LOG.info("[Slow Query] ip={} execTime={}ms, body={}, method={}, path={}, query={}", | ||
getClientIP(requestContext), executeTime, |
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.
prefer this style: defining a local var for better readability:
for both: getClientIP and REQUEST_PARAMS_JSON.
private String getClientIP(ContainerRequestContext requestContext) { | ||
try { | ||
UriInfo uriInfo = requestContext.getUriInfo(); | ||
String host = uriInfo.getRequestUri().getHost(); |
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.
return here if host is an ip or empty?
String host = uriInfo.getRequestUri().getHost(); | ||
return InetAddress.getByName(host).getHostAddress(); | ||
} catch (UnknownHostException e) { | ||
return "unknown"; |
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.
prefer "<unknown_ip>"
.getPathParameters(); | ||
requestParamsJson = pathParameters.toString(); | ||
context.setProperty(REQUEST_PARAMS_JSON, | ||
context.getUriInfo().getPathParameters().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.
can we also add all other branchs like PUT/DELETE -- seems still missing
fix #2468
we support slow log before ,but it cause bug when loader batch import data, the feat PR see #2327
and later we downgrade it ,see pr : #2347
the bug due to:
so we ready to resolve it , use BufferedInputStream to cache the stream:
` BufferedInputStream bufferedStream = new BufferedInputStream(context.getEntityStream());
`
case:
[Slow Query] ip=127.0.0.1 execTime=22ms, body={"gremlin":"hugegraph.backendStoreFeatures() .supportsSharedStorage();","bindings":{},"language":"gremlin-groovy","aliases":{"g":"__g_hugegraph"}}, method=POST, path=/gremlin, query=null
and then i test it