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

Enhancement/normalize metric field #170

Merged
merged 3 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void testGrpcClientInterceptor() throws Exception {
ClusterNode clusterNode = ClusterBuilderSlot.getClusterNode(resourceName, EntryType.OUT);
assertNotNull(clusterNode);

assertEquals((total - threshold) / 2, clusterNode.blockedRequest());
assertEquals((total - threshold) / 2, clusterNode.blockRequest());
assertEquals(total / 2, clusterNode.totalRequest());

long totalQps = clusterNode.totalQps();
long passQps = clusterNode.passQps();
long blockedQps = clusterNode.blockedQps();
long blockQps = clusterNode.blockQps();
assertEquals(total, totalQps);
assertEquals(total - threshold, blockedQps);
assertEquals(total - threshold, blockQps);
assertEquals(threshold, passQps);

server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public void testGrpcServerInterceptor() throws Exception {
ClusterNode clusterNode = ClusterBuilderSlot.getClusterNode(resourceName, EntryType.IN);
assertNotNull(clusterNode);

assertEquals((total - threshold) / 2, clusterNode.blockedRequest());
assertEquals((total - threshold) / 2, clusterNode.blockRequest());
assertEquals(total / 2, clusterNode.totalRequest());

long totalQps = clusterNode.totalQps();
long passQps = clusterNode.passQps();
long blockedQps = clusterNode.blockedQps();
long blockQps = clusterNode.blockQps();
assertEquals(total, totalQps);
assertEquals(total - threshold, blockedQps);
assertEquals(total - threshold, blockQps);
assertEquals(threshold, passQps);

server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ public double getOriginTotalQps() {
return getOriginNode() == null ? 0 : getOriginNode().totalQps();
}

public double getOriginBlockedQps() {
return getOriginNode() == null ? 0 : getOriginNode().blockedQps();
public double getOriginBlockQps() {
return getOriginNode() == null ? 0 : getOriginNode().blockQps();
}

public double getOriginPassedReqQps() {
public double getOriginPassReqQps() {
return getOriginNode() == null ? 0 : getOriginNode().successQps();
}

public double getOriginPassedQps() {
public double getOriginPassQps() {
return getOriginNode() == null ? 0 : getOriginNode().passQps();
}

public long getOriginTotalRequest() {
return getOriginNode() == null ? 0 : getOriginNode().totalRequest();
}

public long getOriginBlockedRequest() {
return getOriginNode() == null ? 0 : getOriginNode().blockedRequest();
public long getOriginBlockRequest() {
return getOriginNode() == null ? 0 : getOriginNode().blockRequest();
}

public double getOriginAvgRt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public Set<Node> getChildList() {
}

@Override
public void increaseBlockedQps() {
super.increaseBlockedQps();
this.clusterNode.increaseBlockedQps();
public void increaseBlockQps() {
super.increaseBlockQps();
this.clusterNode.increaseBlockQps();
}

@Override
Expand Down Expand Up @@ -134,13 +134,13 @@ private void visitTree(int level, DefaultNode node) {
if (!(node instanceof EntranceNode)) {
System.out.println(
String.format("%s(thread:%s pq:%s bq:%s tq:%s rt:%s 1mp:%s 1mb:%s 1mt:%s)", node.id.getShowName(),
node.curThreadNum(), node.passQps(), node.blockedQps(), node.totalQps(), node.avgRt(),
node.totalRequest() - node.blockedRequest(), node.blockedRequest(), node.totalRequest()));
node.curThreadNum(), node.passQps(), node.blockQps(), node.totalQps(), node.avgRt(),
node.totalRequest() - node.blockRequest(), node.blockRequest(), node.totalRequest()));
} else {
System.out.println(
String.format("Entry-%s(t:%s pq:%s bq:%s tq:%s rt:%s 1mp:%s 1mb:%s 1mt:%s)", node.id.getShowName(),
node.curThreadNum(), node.passQps(), node.blockedQps(), node.totalQps(), node.avgRt(),
node.totalRequest() - node.blockedRequest(), node.blockedRequest(), node.totalRequest()));
node.curThreadNum(), node.passQps(), node.blockQps(), node.totalQps(), node.avgRt(),
node.totalRequest() - node.blockRequest(), node.blockRequest(), node.totalRequest()));
}
for (Node n : node.getChildList()) {
DefaultNode dn = (DefaultNode)n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ public long avgRt() {
}

@Override
public long blockedQps() {
public long blockQps() {
int blockQps = 0;
for (Node node : getChildList()) {
blockQps += node.blockedQps();
blockQps += node.blockQps();
}
return blockQps;
}

@Override
public long blockedRequest() {
public long blockRequest() {
long r = 0;
for (Node node : getChildList()) {
r += node.blockedRequest();
r += node.blockRequest();
}
return r;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public interface Node {

/**
* Get incoming request per minute. {@code pass + blocked}
* Get incoming request per minute. {@code pass + block}
*/
long totalRequest();

Expand All @@ -41,9 +41,9 @@ public interface Node {
long totalSuccess();

/**
* Get blocked request count per minute.
* Get block request count per minute.
*/
long blockedRequest();
long blockRequest();

/**
* Get exception count per minute.
Expand All @@ -56,12 +56,12 @@ public interface Node {
long passQps();

/**
* Get blocked request per second.
* Get block request per second.
*/
long blockedQps();
long blockQps();

/**
* Get {@link #passQps()} + {@link #blockedQps()} request per second.
* Get {@link #passQps()} + {@link #blockQps()} request per second.
*/
long totalQps();

Expand Down Expand Up @@ -90,7 +90,7 @@ public interface Node {
int curThreadNum();

/**
* Get last second blocked QPS.
* Get last second block QPS.
*/
long previousBlockQps();

Expand All @@ -110,7 +110,7 @@ public interface Node {
*/
void rt(long rt);

void increaseBlockedQps();
void increaseBlockQps();

void increaseExceptionQps();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public Map<Long, MetricNode> metrics() {
long newLastFetchTime = lastFetchTime;
for (MetricNode node : nodesOfEverySecond) {
if (node.getTimestamp() > lastFetchTime && node.getTimestamp() < currentTime) {
if (node.getPassedQps() != 0
|| node.getBlockedQps() != 0
if (node.getPassQps() != 0
|| node.getBlockQps() != 0
|| node.getSuccessQps() != 0
|| node.getException() != 0
|| node.getExceptionQps() != 0
|| node.getRt() != 0) {
metrics.put(node.getTimestamp(), node);
newLastFetchTime = Math.max(newLastFetchTime, node.getTimestamp());
Expand All @@ -80,12 +80,12 @@ public long totalRequest() {
}

@Override
public long blockedRequest() {
public long blockRequest() {
return rollingCounterInMinute.block() / 2;
}

@Override
public long blockedQps() {
public long blockQps() {
return rollingCounterInSecond.block() / IntervalProperty.INTERVAL;
}

Expand All @@ -101,7 +101,7 @@ public long previousPassQps() {

@Override
public long totalQps() {
return passQps() + blockedQps();
return passQps() + blockQps();
}

@Override
Expand Down Expand Up @@ -170,7 +170,7 @@ public void rt(long rt) {
}

@Override
public void increaseBlockedQps() {
public void increaseBlockQps() {
rollingCounterInSecond.addBlock();
rollingCounterInMinute.addBlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
public class MetricNode {

private long timestamp;
private long passedQps;
private long blockedQps;
private long passQps;
private long blockQps;
private long successQps;
private long exception;
private long exceptionQps;
private long rt;

private String resource;
Expand All @@ -46,28 +46,28 @@ public void setSuccessQps(long successQps) {
this.successQps = successQps;
}

public long getPassedQps() {
return passedQps;
public long getPassQps() {
return passQps;
}

public void setPassedQps(long passedQps) {
this.passedQps = passedQps;
public void setPassQps(long passQps) {
this.passQps = passQps;
}

public long getException() {
return exception;
public long getExceptionQps() {
return exceptionQps;
}

public void setException(long exception) {
this.exception = exception;
public void setExceptionQps(long exceptionQps) {
this.exceptionQps = exceptionQps;
}

public long getBlockedQps() {
return blockedQps;
public long getBlockQps() {
return blockQps;
}

public void setBlockedQps(long blockedQps) {
this.blockedQps = blockedQps;
public void setBlockQps(long blockQps) {
this.blockQps = blockQps;
}

public long getRt() {
Expand All @@ -90,10 +90,10 @@ public void setResource(String resource) {
public String toString() {
return "MetricNode{" +
"timestamp=" + timestamp +
", passedQps=" + passedQps +
", blockedQs=" + blockedQps +
", passQps=" + passQps +
", blockQps=" + blockQps +
", successQps=" + successQps +
", exception=" + exception +
", exceptionQps=" + exceptionQps +
", rt=" + rt +
", resource='" + resource + '\'' +
'}';
Expand All @@ -103,7 +103,7 @@ public String toString() {
* To formatting string. All "|" in {@link #resource} will be replaced with "_", format is:
* <br/>
* <code>
* timestamp|resource|passedQps|blockedQps|successQps|exception|rt
* timestamp|resource|passQps|blockQps|successQps|exceptionQps|rt
* </code>
*
* @return string format of this.
Expand All @@ -113,10 +113,10 @@ public String toThinString() {
sb.append(timestamp).append("|");
String legalName = resource.replaceAll("\\|", "_");
sb.append(legalName).append("|");
sb.append(passedQps).append("|");
sb.append(blockedQps).append("|");
sb.append(passQps).append("|");
sb.append(blockQps).append("|");
sb.append(successQps).append("|");
sb.append(exception).append("|");
sb.append(exceptionQps).append("|");
sb.append(rt);
return sb.toString();
}
Expand All @@ -132,10 +132,10 @@ public static MetricNode fromThinString(String line) {
String[] strs = line.split("\\|");
node.setTimestamp(Long.parseLong(strs[0]));
node.setResource(strs[1]);
node.setPassedQps(Long.parseLong(strs[2]));
node.setBlockedQps(Long.parseLong(strs[3]));
node.setPassQps(Long.parseLong(strs[2]));
node.setBlockQps(Long.parseLong(strs[3]));
node.setSuccessQps(Long.parseLong(strs[4]));
node.setException(Long.parseLong(strs[5]));
node.setExceptionQps(Long.parseLong(strs[5]));
node.setRt(Long.parseLong(strs[6]));
return node;
}
Expand All @@ -144,7 +144,7 @@ public static MetricNode fromThinString(String line) {
* To formatting string. All "|" in {@link MetricNode#resource} will be replaced with "_", format is:
* <br/>
* <code>
* timestamp|yyyy-MM-dd HH:mm:ss|resource|passedQps|blockedQps|successQps|exception|rt\n
* timestamp|yyyy-MM-dd HH:mm:ss|resource|passQps|blockQps|successQps|exceptionQps|rt\n
* </code>
*
* @return string format of this.
Expand All @@ -157,10 +157,10 @@ public String toFatString() {
sb.append(df.format(new Date(getTimestamp()))).append("|");
String legalName = getResource().replaceAll("\\|", "_");
sb.append(legalName).append("|");
sb.append(getPassedQps()).append("|");
sb.append(getBlockedQps()).append("|");
sb.append(getPassQps()).append("|");
sb.append(getBlockQps()).append("|");
sb.append(getSuccessQps()).append("|");
sb.append(getException()).append("|");
sb.append(getExceptionQps()).append("|");
sb.append(getRt());
sb.append('\n');
return sb.toString();
Expand All @@ -178,10 +178,10 @@ public static MetricNode fromFatString(String line) {
MetricNode node = new MetricNode();
node.setTimestamp(time);
node.setResource(strs[2]);
node.setPassedQps(Long.parseLong(strs[3]));
node.setBlockedQps(Long.parseLong(strs[4]));
node.setPassQps(Long.parseLong(strs[3]));
node.setBlockQps(Long.parseLong(strs[4]));
node.setSuccessQps(Long.parseLong(strs[5]));
node.setException(Long.parseLong(strs[6]));
node.setExceptionQps(Long.parseLong(strs[6]));
node.setRt(Long.parseLong(strs[7]));
return node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode
context.getCurEntry().setError(e);

// Add block count.
node.increaseBlockedQps();
node.increaseBlockQps();
if (context.getCurEntry().getOriginNode() != null) {
context.getCurEntry().getOriginNode().increaseBlockedQps();
context.getCurEntry().getOriginNode().increaseBlockQps();
}

if (resourceWrapper.getType() == EntryType.IN) {
Constants.ENTRY_NODE.increaseBlockedQps();
Constants.ENTRY_NODE.increaseBlockQps();
}

for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public List<MetricNode> details() {
continue;
}
MetricNode node = new MetricNode();
node.setBlockedQps(window.value().block());
node.setException(window.value().exception());
node.setPassedQps(window.value().pass());
node.setBlockQps(window.value().block());
node.setExceptionQps(window.value().exception());
node.setPassQps(window.value().pass());
long passQps = window.value().success();
node.setSuccessQps(passQps);
if (passQps != 0) {
Expand Down
Loading