Skip to content

Commit

Permalink
Merge pull request #1 from InscopeMetrics/master
Browse files Browse the repository at this point in the history
Merge upstream!
  • Loading branch information
orborde committed Feb 20, 2020
2 parents 8d0c4bd + 5bfaf5b commit b28dd77
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ addons:
- rpm
env:
global:
- TARGE=install
- TARGET=install
- secure: aANugu/1kR5uZl2nzd6Cm4hn6aA1eIPNrpUlQ7pI5aFZkkhPQ1g3qxR2e0z5sfKlpOV8iKbVEk+XrnnR2yJiJS3tDma6AHm/8CcvyB+2oEWZroumE/cva914uvwo15wfhNBQPPt6uAjBU8qPRpjrSmbTr/yiwSPQiwYmCYzYatpMLzCw/xjUQSnpu1Q85WJU0bcQe4yYO6xazrdpJgM2XUTvRybq4SEfEcpshm5KV/k3ux/xvwE6QBUYUgU+Cnm1p2jv2wgh3DrYJUVyokMKiwWoBvh21lmXm026T8+nHVvxpdUdXE69YJD250zLrvzLmv4C9sYYcQZGwzuBOWZa+tS4MPSu0kVcgFohC3Y8/fj0nTGmF3RKABGJwwAaq5ZsAGRL4SIBBr+zALdlRMy8dEQsVCc3O8TzQ/hmLVzQj/xmHimbP8KQgSXnFIfj4FyrLDZr/b8Yqo26UQ7n9wzjLcLZ2qPfkF+WHX7YuGSNTgtFDCMx55ukgGD/G57eqgR14052QQxAvAAWMkdJOxw0nJXEtJfRx8LBgVFH17a3FfWAB5x2/1Im4z9yMjTDIMtEP8ruqGwokcvMQXTUha+ye7xZCrLhzSI45dDRxmLcz4z0CLM9nrsJ1OqkY2JPNxhTUI74bJaTDLVGBP9nLsfbaxm8uPGZX93LmiozgXYZ1mE=
- secure: CTP8oAraFI2rW5lmeHoZcZ9pS3dDaF9/pKn6CTakkpaAdR0PAeo/NHVGbNE/VSOAyl8VCa9NkNkCO2FESckWcliwJAriposs9MKLrfeWk2MfKSTQKNgDH65BX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YIbZCXaahf4yGuskOwRKFphRYN5uflkP7ilFIuhFTu755yX7Ges2dXRQhCUBKCXICIjlikoiWlWnpIJFqnA02AQOHoeCIhkj9NL9Ffixh1g4sNfVThbQFMtOOvhgP9K3cKlaTDD/blMZqJKwN+yz9gR8kB372vAM6Du3UHv8/GY+W3RTDUUY=
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<packaging>jar</packaging>
<name>KairosDB Extensions</name>
<description>Extensions for KairosDB.</description>
<version>2.1.8-SNAPSHOT</version>
<version>2.1.10-SNAPSHOT</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public interface HistogramDataPoint extends DataPoint {
* Getter the number of data points originally contained in this HistogramDataPoint.
* @return datapoint sample count
*/
int getOriginalCount();
long getOriginalCount();

/**
* Getter for sample count contained in this HistogramDataPoint.
* @return datapoint sample count
*/
int getSampleCount();
long getSampleCount();

/**
* Getter for the sum of all samples contained in this HistogramDataPoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class HistogramDataPointImpl extends DataPointHelper implements Histogram
private final double max;
private final double mean;
private final double sum;
private final int originalCount;
private final long originalCount;

/**
* Public constructor.
Expand Down Expand Up @@ -88,7 +88,7 @@ public HistogramDataPointImpl(
final double max,
final double mean,
final double sum,
final int originalCount) {
final long originalCount) {
this(
timestamp,
DEFAULT_PRECISION,
Expand Down Expand Up @@ -151,7 +151,7 @@ public HistogramDataPointImpl(
final double max,
final double mean,
final double sum,
final int originalCount) {
final long originalCount) {
super(timestamp);
this.precision = precision;
this.map = map;
Expand Down Expand Up @@ -222,7 +222,7 @@ public double getDoubleValue() {
}

@Override
public int getOriginalCount() {
public long getOriginalCount() {
return originalCount;
}

Expand All @@ -232,7 +232,7 @@ public int getOriginalCount() {
* @return the number of samples
*/
@Override
public int getSampleCount() {
public long getSampleCount() {
int count = 0;
for (Integer binSamples : map.values()) {
count += binSamples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private final class HistogramMeanDataPointAggregator implements RangeSubAggregat

@Override
public Iterable<DataPoint> getNextDataPoints(final long returnTime, final Iterator<DataPoint> dataPointRange) {
int count = 0;
long count = 0;
while (dataPointRange.hasNext()) {
final DataPoint dp = dataPointRange.next();
if (dp instanceof HistogramDataPoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private HistogramDataPoint filterBins(final DataPoint dp) {
double max = -Double.MAX_VALUE;
double sum = 0;
long count = 0;
int originalCount = 0;
long originalCount = 0;

if (dp instanceof HistogramDataPoint) {
final HistogramDataPoint hist = (HistogramDataPoint) dp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ public void setDataPointGroup(final DataPointGroup dataPointGroup) {
}

@Override
public int getOriginalCount() {
public long getOriginalCount() {
return wrappedDataPoint.getOriginalCount();
}

@Override
public int getSampleCount() {
public long getSampleCount() {
return wrappedDataPoint.getSampleCount();
}

Expand Down
12 changes: 8 additions & 4 deletions src/test/java/io/inscopemetrics/kairosdb/Histogram.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
@SuppressFBWarnings("FE_FLOATING_POINT_EQUALITY")
public class Histogram {
private final TreeMap<Double, Integer> bins = new TreeMap<>();
private final TreeMap<Double, Long> bins = new TreeMap<>();
private double min;
private double max;
private double sum;
private int count;
private long count;

/**
* Public constructor.
Expand Down Expand Up @@ -70,7 +70,7 @@ public Histogram(final JSONObject json) throws JSONException {
final JSONObject binsJson = json.getJSONObject("bins");
for (final Iterator<String> it = (Iterator<String>) binsJson.keys(); it.hasNext();) {
final String key = it.next();
final int value = binsJson.getInt(key);
final long value = binsJson.getLong(key);
bins.put(Double.valueOf(key), value);
count += value;

Expand Down Expand Up @@ -143,7 +143,11 @@ public double getSum() {
return sum;
}

public TreeMap<Double, Integer> getBins() {
public long getCount() {
return count;
}

public TreeMap<Double, Long> getBins() {
return bins;
}
}
30 changes: 30 additions & 0 deletions src/test/java/io/inscopemetrics/kairosdb/HistogramTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.inscopemetrics.kairosdb;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;

import java.util.TreeMap;

public class HistogramTest {
@Test
public void testDecodeLargeHistogram() throws JSONException {
final JSONObject serialized = new JSONObject();
serialized.put("min", 1337d);
serialized.put("max", 1337d);
serialized.put("sum", 11484742549504d);
final JSONObject bins = new JSONObject();
bins.put("1337", 8589934592d);
serialized.put("bins", bins);

final Histogram h = new Histogram(serialized);

Assert.assertEquals(1337, (long) h.getMin());
Assert.assertEquals(1337, (long) h.getMax());
Assert.assertEquals(11484742549504L, (long) h.getSum());
Assert.assertEquals(8589934592L, h.getCount());
final TreeMap<Double, Long> actualBins = h.getBins();
Assert.assertEquals(8589934592L, actualBins.get(1337d).longValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 Dropbox Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.inscopemetrics.kairosdb.aggregators;

import com.google.common.collect.Maps;
import io.inscopemetrics.kairosdb.HistogramDataPoint;
import io.inscopemetrics.kairosdb.HistogramDataPointImpl;
import org.junit.Assert;
import org.junit.Test;
import org.kairosdb.core.datapoints.DoubleDataPoint;
import org.kairosdb.core.datapoints.DoubleDataPointFactoryImpl;
import org.kairosdb.core.datastore.DataPointGroup;
import org.kairosdb.core.exception.KairosDBException;
import org.kairosdb.testing.ListDataPointGroup;

import java.util.TreeMap;

public class HistogramCountAggregatorTest {

@Test
public void testCombineLargeValues() throws KairosDBException {
final double min = Double.MAX_VALUE;
final double max = -Double.MAX_VALUE;
final double sum = 0;
final TreeMap<Double, Integer> bins = Maps.newTreeMap();
bins.put(1337d, 2147483647);
final double mean = 1337d;

final HistogramDataPoint dp = new HistogramDataPointImpl(
1L, bins, min, max, mean, sum);
final ListDataPointGroup group = new ListDataPointGroup("testCombineLargeValues");
group.addDataPoint(dp);
group.addDataPoint(dp);
group.addDataPoint(dp);
group.addDataPoint(dp);

final HistogramCountAggregator aggregator = new HistogramCountAggregator(new DoubleDataPointFactoryImpl());
final DataPointGroup result = aggregator.aggregate(group);

Assert.assertTrue(result.hasNext());
final DoubleDataPoint resultDataPoint = (DoubleDataPoint) result.next();
Assert.assertEquals(8589934588L, resultDataPoint.getLongValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void testMergeAggregatorSingle() throws IOException, JSONException {
public void testMergeAggregatorMulti() throws IOException, JSONException {
final List<Double> numbers = Lists.newArrayList();
for (Histogram histogram : MULTI_HIST_TEST_DATA) {
for (final Map.Entry<Double, Integer> entry : histogram.getBins().entrySet()) {
for (final Map.Entry<Double, Long> entry : histogram.getBins().entrySet()) {
for (int count = 0; count < entry.getValue(); count++) {
numbers.add(entry.getKey());
}
Expand Down

0 comments on commit b28dd77

Please sign in to comment.