jerrypeng commented on a change in pull request #3050: Correcting metrics and
adding tests
URL: https://github.com/apache/pulsar/pull/3050#discussion_r236100396
##########
File path:
pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/FunctionStats.java
##########
@@ -130,35 +136,59 @@ public void addInstance(FunctionInstanceStats
functionInstanceStats) {
public FunctionStats calculateOverall() {
- lastInvocation = 0;
- instances.forEach(new Consumer<FunctionInstanceStats>() {
- @Override
- public void accept(FunctionInstanceStats functionInstanceStats) {
+ int nonNullInstances = 0;
+ int nonNullInstancesOneMin = 0;
+ for (FunctionInstanceStats functionInstanceStats : instances) {
FunctionInstanceStats.FunctionInstanceStatsData
functionInstanceStatsData = functionInstanceStats.getMetrics();
receivedTotal += functionInstanceStatsData.receivedTotal;
processedSuccessfullyTotal +=
functionInstanceStatsData.processedSuccessfullyTotal;
systemExceptionsTotal +=
functionInstanceStatsData.systemExceptionsTotal;
userExceptionsTotal +=
functionInstanceStatsData.userExceptionsTotal;
- avgProcessLatency +=
functionInstanceStatsData.avgProcessLatency;
+ if (functionInstanceStatsData.avgProcessLatency != null) {
+ if (avgProcessLatency == null) {
+ avgProcessLatency = 0.0;
+ }
+ avgProcessLatency +=
functionInstanceStatsData.avgProcessLatency;
+ nonNullInstances ++;
+ }
oneMin.receivedTotal +=
functionInstanceStatsData.oneMin.receivedTotal;
oneMin.processedSuccessfullyTotal +=
functionInstanceStatsData.oneMin.processedSuccessfullyTotal;
oneMin.systemExceptionsTotal +=
functionInstanceStatsData.oneMin.systemExceptionsTotal;
oneMin.userExceptionsTotal +=
functionInstanceStatsData.oneMin.userExceptionsTotal;
- oneMin.avgProcessLatency +=
functionInstanceStatsData.oneMin.avgProcessLatency;
-
- if (functionInstanceStatsData.lastInvocation > lastInvocation)
{
- lastInvocation = functionInstanceStatsData.lastInvocation;
+ if (functionInstanceStatsData.oneMin.avgProcessLatency !=
null) {
+ if (oneMin.avgProcessLatency == null) {
+ oneMin.avgProcessLatency = 0.0;
+ }
+ oneMin.avgProcessLatency +=
functionInstanceStatsData.oneMin.avgProcessLatency;
+ nonNullInstancesOneMin ++;
}
+ if (functionInstanceStatsData.lastInvocation != null) {
+ if (lastInvocation == null ||
functionInstanceStatsData.lastInvocation > lastInvocation) {
+ lastInvocation =
functionInstanceStatsData.lastInvocation;
+ }
+ }
}
- });
+
// calculate average from sum
- avgProcessLatency = avgProcessLatency / instances.size();
+ if (nonNullInstances > 0) {
+ avgProcessLatency = avgProcessLatency / nonNullInstances;
+ } else {
+ avgProcessLatency = null;
+ }
// calculate 1min average from sum
- oneMin.avgProcessLatency = oneMin.avgProcessLatency / instances.size();
+ if (nonNullInstancesOneMin > 0) {
+ oneMin.avgProcessLatency = oneMin.avgProcessLatency /
nonNullInstancesOneMin;
+ } else {
+ oneMin.avgProcessLatency = null;
+ }
return this;
}
+
+ public static FunctionStats decode (String json) throws IOException {
+ return new ObjectMapper().readValue(json, FunctionStats.class);
Review comment:
This method is really only for the integrations tests since I don't what to
have to use the shaded version of ObjectMapper in the integrations tests, but I
will change it
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services