-
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
feat(api&core): in oltp apis, add statistics info and support full info about vertices and edges #2262
Merged
Merged
feat(api&core): in oltp apis, add statistics info and support full info about vertices and edges #2262
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8a8f9c7
chore: improve gitignore file
DanGuge 8f3f9db
feat: add ApiMeasure to collect runtime data
DanGuge eef9da4
feat: Add ApiMeasure to JsonSerializer and Modify the Serializer inte…
DanGuge 023acf6
refactor: format code based on hugegraph-style.xml
DanGuge fc94aa3
feat: Add statistics information in all oltp restful apis response an…
DanGuge c6ab9f4
fix: numeric cast
DanGuge c7825a6
fix: Jaccard Similarity api test
DanGuge e671963
fix: adjust the code style and naming convention
DanGuge 1e33cda
Empty commit
DanGuge 262ae05
Empty commit
DanGuge 793ead8
fix:
DanGuge 5bb446a
fix: rollback change in .gitignore
DanGuge cea5db2
fix: rollback ServerOptions.java code style
DanGuge 4cc5f46
fix: rollback API.java code style and add exception in else branch
DanGuge 92ba7c8
fix: fix code style
DanGuge 559bff1
fix: name style & code style
DanGuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,41 +22,39 @@ | |
import java.util.concurrent.Callable; | ||
import java.util.function.Consumer; | ||
|
||
import jakarta.ws.rs.ForbiddenException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.apache.commons.lang.mutable.MutableLong; | ||
import org.apache.hugegraph.HugeException; | ||
import org.apache.hugegraph.HugeGraph; | ||
import org.apache.hugegraph.core.GraphManager; | ||
import org.apache.hugegraph.define.Checkable; | ||
import org.apache.hugegraph.metrics.MetricsUtil; | ||
import org.slf4j.Logger; | ||
|
||
import org.apache.hugegraph.HugeException; | ||
import org.apache.hugegraph.HugeGraph; | ||
import org.apache.hugegraph.util.E; | ||
import org.apache.hugegraph.util.InsertionOrderUtil; | ||
import org.apache.hugegraph.util.JsonUtil; | ||
import org.apache.hugegraph.util.Log; | ||
import org.slf4j.Logger; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class API { | ||
import jakarta.ws.rs.ForbiddenException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
protected static final Logger LOG = Log.logger(API.class); | ||
public class API { | ||
|
||
public static final String CHARSET = "UTF-8"; | ||
|
||
public static final String TEXT_PLAIN = MediaType.TEXT_PLAIN; | ||
public static final String APPLICATION_JSON = MediaType.APPLICATION_JSON; | ||
public static final String APPLICATION_JSON_WITH_CHARSET = | ||
APPLICATION_JSON + ";charset=" + CHARSET; | ||
public static final String JSON = MediaType.APPLICATION_JSON_TYPE | ||
.getSubtype(); | ||
|
||
public static final String ACTION_APPEND = "append"; | ||
public static final String ACTION_ELIMINATE = "eliminate"; | ||
public static final String ACTION_CLEAR = "clear"; | ||
|
||
protected static final Logger LOG = Log.logger(API.class); | ||
private static final Meter SUCCEED_METER = | ||
MetricsUtil.registerMeter(API.class, "commit-succeed"); | ||
private static final Meter ILLEGAL_ARG_ERROR_METER = | ||
|
@@ -69,8 +67,7 @@ public class API { | |
public static HugeGraph graph(GraphManager manager, String graph) { | ||
HugeGraph g = manager.graph(graph); | ||
if (g == null) { | ||
throw new NotFoundException(String.format( | ||
"Graph '%s' does not exist", graph)); | ||
throw new NotFoundException(String.format("Graph '%s' does not exist", graph)); | ||
} | ||
return g; | ||
} | ||
|
@@ -140,8 +137,7 @@ protected static void checkUpdatingBody(Checkable body) { | |
body.checkUpdate(); | ||
} | ||
|
||
protected static void checkCreatingBody( | ||
Collection<? extends Checkable> bodies) { | ||
protected static void checkCreatingBody(Collection<? extends Checkable> bodies) { | ||
E.checkArgumentNotNull(bodies, "The request body can't be empty"); | ||
for (Checkable body : bodies) { | ||
E.checkArgument(body != null, | ||
|
@@ -150,8 +146,7 @@ protected static void checkCreatingBody( | |
} | ||
} | ||
|
||
protected static void checkUpdatingBody( | ||
Collection<? extends Checkable> bodies) { | ||
protected static void checkUpdatingBody(Collection<? extends Checkable> bodies) { | ||
E.checkArgumentNotNull(bodies, "The request body can't be empty"); | ||
for (Checkable body : bodies) { | ||
E.checkArgumentNotNull(body, | ||
|
@@ -186,8 +181,58 @@ public static boolean checkAndParseAction(String action) { | |
} else if (action.equals(ACTION_ELIMINATE)) { | ||
return false; | ||
} else { | ||
throw new NotSupportedException( | ||
String.format("Not support action '%s'", action)); | ||
throw new NotSupportedException(String.format("Not support action '%s'", action)); | ||
} | ||
} | ||
|
||
public static class ApiMeasurer { | ||
|
||
public static final String EDGE_ITER = "edge_iterations"; | ||
public static final String VERTICE_ITER = "vertice_iterations"; | ||
public static final String COST = "cost(ns)"; | ||
private final long timeStart; | ||
private final Map<String, Object> measures; | ||
|
||
public ApiMeasurer() { | ||
this.timeStart = System.nanoTime(); | ||
this.measures = InsertionOrderUtil.newMap(); | ||
} | ||
|
||
public Map<String, Object> measures() { | ||
measures.put(COST, System.nanoTime() - timeStart); | ||
return measures; | ||
} | ||
|
||
public void put(String key, String value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
public void put(String key, long value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
public void put(String key, int value) { | ||
this.measures.put(key, value); | ||
} | ||
|
||
protected void addCount(String key, long value) { | ||
Object current = measures.get(key); | ||
if (current == null) { | ||
measures.put(key, new MutableLong(value)); | ||
} else if (current instanceof MutableLong) { | ||
((MutableLong) measures.computeIfAbsent(key, MutableLong::new)).add(value); | ||
} else if (current instanceof Long) { | ||
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. add else branch then throw an exception 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. fixed |
||
Long currentLong = (Long) current; | ||
measures.put(key, new MutableLong(currentLong + value)); | ||
} else { | ||
throw new NotSupportedException("addCount() method's 'value' datatype must be " + | ||
"Long or MutableLong"); | ||
} | ||
} | ||
|
||
public void addIterCount(long verticeIters, long edgeIters) { | ||
this.addCount(EDGE_ITER, edgeIters); | ||
this.addCount(VERTICE_ITER, verticeIters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
measures.computeIfAbsent(key, MutableLong.new).add(value)
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.
fixed