-
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
feat(api&core): in oltp apis, add statistics info and support full info about vertices and edges #2262
Changes from 12 commits
8a8f9c7
8f3f9db
eef9da4
023acf6
fc94aa3
c6ab9f4
c7825a6
e671963
1e33cda
262ae05
793ead8
5bb446a
cea5db2
4cc5f46
92ba7c8
559bff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,55 +22,52 @@ | |
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; | ||
APPLICATION_JSON + ";charset=" + CHARSET; | ||
public static final String JSON = MediaType.APPLICATION_JSON_TYPE | ||
.getSubtype(); | ||
|
||
.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"); | ||
MetricsUtil.registerMeter(API.class, "commit-succeed"); | ||
private static final Meter ILLEGAL_ARG_ERROR_METER = | ||
MetricsUtil.registerMeter(API.class, "illegal-arg"); | ||
MetricsUtil.registerMeter(API.class, "illegal-arg"); | ||
private static final Meter EXPECTED_ERROR_METER = | ||
MetricsUtil.registerMeter(API.class, "expected-error"); | ||
MetricsUtil.registerMeter(API.class, "expected-error"); | ||
private static final Meter UNKNOWN_ERROR_METER = | ||
MetricsUtil.registerMeter(API.class, "unknown-error"); | ||
MetricsUtil.registerMeter(API.class, "unknown-error"); | ||
|
||
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,55 @@ 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. measures.computeIfAbsent(key, MutableLong.new).add(value) 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 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)); | ||
} | ||
} | ||
|
||
public void addIterCount(long verticeIters, long edgeIters) { | ||
this.addCount(EDGE_ITER, edgeIters); | ||
this.addCount(VERTICE_ITER, verticeIters); | ||
} | ||
} | ||
} |
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 keep the origin style
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