diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetric.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetric.java index eea3c459..1dbdae21 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetric.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetric.java @@ -33,8 +33,7 @@ public class ClusterMetric { AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); - int windowLengthInMs = intervalInMs / sampleCount; - this.metric = new ClusterMetricLeapArray(windowLengthInMs, intervalInMs); + this.metric = new ClusterMetricLeapArray(sampleCount, intervalInMs); } public void add(ClusterFlowEvent event, long count) { diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetricLeapArray.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetricLeapArray.java index 40d2d752..da76b032 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetricLeapArray.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterMetricLeapArray.java @@ -30,14 +30,8 @@ public class ClusterMetricLeapArray extends LeapArray { private final LongAdder[] occupyCounter; private boolean hasOccupied = false; - /** - * The total bucket count is: {@link #sampleCount} = intervalInMs / windowLengthInMs. - * - * @param windowLengthInMs a single window bucket's time length in milliseconds. - * @param intervalInMs the total time span of this {@link LeapArray} in milliseconds. - */ - public ClusterMetricLeapArray(int windowLengthInMs, int intervalInMs) { - super(windowLengthInMs, intervalInMs / 1000); + public ClusterMetricLeapArray(int sampleCount, int intervalInMs) { + super(sampleCount, intervalInMs); ClusterFlowEvent[] events = ClusterFlowEvent.values(); this.occupyCounter = new LongAdder[events.length]; for (ClusterFlowEvent event : events) { diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParamMetric.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParamMetric.java index 4daf7e41..1768d8ea 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParamMetric.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParamMetric.java @@ -39,8 +39,7 @@ public class ClusterParamMetric { AssertUtil.isTrue(sampleCount > 0, "sampleCount should be positive"); AssertUtil.isTrue(intervalInMs > 0, "interval should be positive"); AssertUtil.isTrue(intervalInMs % sampleCount == 0, "time span needs to be evenly divided"); - int windowLengthInMs = intervalInMs / sampleCount; - this.metric = new ClusterParameterLeapArray<>(windowLengthInMs, intervalInMs, maxCapacity); + this.metric = new ClusterParameterLeapArray<>(sampleCount, intervalInMs, maxCapacity); } public long getSum(Object value) { diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java index dbb603b4..138baa64 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java @@ -30,8 +30,8 @@ public class ClusterParameterLeapArray extends LeapArray> private final int maxCapacity; - public ClusterParameterLeapArray(int windowLengthInMs, int intervalInMs, int maxCapacity) { - super(windowLengthInMs, intervalInMs / 1000); + public ClusterParameterLeapArray(int sampleCount, int intervalInMs, int maxCapacity) { + super(sampleCount, intervalInMs); AssertUtil.isTrue(maxCapacity > 0, "maxCapacity of LRU map should be positive"); this.maxCapacity = maxCapacity; }