use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class LogsIngesterTest method testWavefrontHistogram.
@Test
public void testWavefrontHistogram() throws Exception {
setup("histos.yml");
String[] lines = new String[100];
for (int i = 1; i < 101; i++) {
lines[i - 1] = "histo " + i;
}
ReportPoint reportPoint = getPoints(1, lines).get(0);
assertThat(reportPoint.getValue(), instanceOf(Histogram.class));
Histogram wavefrontHistogram = (Histogram) reportPoint.getValue();
assertThat(wavefrontHistogram.getBins(), hasSize(1));
assertThat(wavefrontHistogram.getBins(), contains(50.5));
assertThat(wavefrontHistogram.getCounts(), hasSize(1));
assertThat(wavefrontHistogram.getCounts(), contains(100));
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class LogsIngesterTest method testWavefrontHistogramMultipleCentroids.
@Test
public void testWavefrontHistogramMultipleCentroids() throws Exception {
setup("histos.yml");
String[] lines = new String[60];
for (int i = 1; i < 61; i++) {
lines[i - 1] = "histo " + i;
}
ReportPoint reportPoint = getPoints(1, 1000, this::receiveLog, lines).get(0);
assertThat(reportPoint.getValue(), instanceOf(Histogram.class));
Histogram wavefrontHistogram = (Histogram) reportPoint.getValue();
assertThat(wavefrontHistogram.getBins(), hasSize(2));
assertThat(wavefrontHistogram.getCounts(), hasSize(2));
assertThat(wavefrontHistogram.getCounts().stream().reduce(Integer::sum).get(), equalTo(60));
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class PickleProtocolDecoder method decodeReportPoints.
@Override
public void decodeReportPoints(byte[] msg, List<ReportPoint> out, String customerId) {
InputStream is = new ByteArrayInputStream(msg);
Object dataRaw;
try {
dataRaw = unpicklerThreadLocal.get().load(is);
if (!(dataRaw instanceof List)) {
throw new IllegalArgumentException(String.format("[%d] unable to unpickle data (unpickle did not return list)", port));
}
} catch (final IOException ioe) {
throw new IllegalArgumentException(String.format("[%d] unable to unpickle data", port), ioe);
}
// [(path, (timestamp, value)), ...]
List<Object[]> data = (List<Object[]>) dataRaw;
for (Object[] o : data) {
Object[] details = (Object[]) o[1];
if (details == null || details.length != 2) {
logger.warning(String.format("[%d] Unexpected pickle protocol input", port));
continue;
}
long ts;
if (details[0] == null) {
logger.warning(String.format("[%d] Unexpected pickle protocol input (timestamp is null)", port));
continue;
} else if (details[0] instanceof Double) {
ts = ((Double) details[0]).longValue() * 1000;
} else if (details[0] instanceof Long) {
ts = ((Long) details[0]).longValue() * 1000;
} else if (details[0] instanceof Integer) {
ts = ((Integer) details[0]).longValue() * 1000;
} else {
logger.warning(String.format("[%d] Unexpected pickle protocol input (details[0]: %s)", port, details[0].getClass().getName()));
continue;
}
if (details[1] == null) {
continue;
}
double value;
if (details[1] instanceof Double) {
value = ((Double) details[1]).doubleValue();
} else if (details[1] instanceof Long) {
value = ((Long) details[1]).longValue();
} else if (details[1] instanceof Integer) {
value = ((Integer) details[1]).intValue();
} else {
logger.warning(String.format("[%d] Unexpected pickle protocol input (value is null)", port));
continue;
}
ReportPoint point = new ReportPoint();
MetricMangler.MetricComponents components = this.metricMangler.extractComponents(o[0].toString());
point.setMetric(components.metric);
String host = components.source;
final Map<String, String> annotations = point.getAnnotations();
if (host == null && annotations != null) {
// iterate over the set of custom tags, breaking when one is found
for (final String tag : customSourceTags) {
host = annotations.remove(tag);
if (host != null) {
break;
}
}
if (host == null) {
host = this.defaultHostName;
}
}
point.setHost(host);
point.setTable(customerId);
point.setTimestamp(ts);
point.setValue(value);
point.setAnnotations(Collections.<String, String>emptyMap());
out.add(point);
}
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class ReportPointIngesterFormatter method drive.
@Override
public ReportPoint drive(String input, String defaultHostName, String customerId, @Nullable List<String> customSourceTags) {
Queue<Token> queue = getQueue(input);
ReportPoint point = new ReportPoint();
point.setTable(customerId);
// if the point has a timestamp, this would be overriden
point.setTimestamp(Clock.now());
AbstractWrapper wrapper = new ReportPointWrapper(point);
try {
for (FormatterElement element : elements) {
element.consume(queue, wrapper);
}
} catch (Exception ex) {
throw new RuntimeException("Could not parse: " + input, ex);
}
if (!queue.isEmpty()) {
throw new RuntimeException("Could not parse: " + input);
}
// Delta metrics cannot have negative values
if ((point.getMetric().startsWith(DELTA_PREFIX) || point.getMetric().startsWith(DELTA_PREFIX_2)) && point.getValue() instanceof Number) {
double v = ((Number) point.getValue()).doubleValue();
if (v <= 0) {
throw new RuntimeException("Delta metrics cannot be non-positive: " + input);
}
}
String host = null;
Map<String, String> annotations = point.getAnnotations();
if (annotations != null) {
host = annotations.remove("source");
if (host == null) {
host = annotations.remove("host");
} else if (annotations.containsKey("host")) {
// we have to move this elsewhere since during querying,
// host= would be interpreted as host and not a point tag
annotations.put("_host", annotations.remove("host"));
}
if (annotations.containsKey("tag")) {
annotations.put("_tag", annotations.remove("tag"));
}
if (host == null && customSourceTags != null) {
// iterate over the set of custom tags, breaking when one is found
for (String tag : customSourceTags) {
host = annotations.get(tag);
if (host != null) {
break;
}
}
}
}
if (host == null) {
host = defaultHostName;
}
point.setHost(host);
return ReportPoint.newBuilder(point).build();
}
use of wavefront.report.ReportPoint in project java by wavefrontHQ.
the class ReportPointTest method testReportPointBuilderSetters.
/**
* This captures an issue where the latest Avro vm templates does not generate overloaded settings for Avro objects
* and builders.
*/
@Test
public void testReportPointBuilderSetters() throws IOException {
// test integer to long widening conversion.
ReportPoint rp = ReportPoint.newBuilder().setValue(1).setMetric("hello").setTimestamp(12345).build();
ByteBuffer byteBuffer = rp.toByteBuffer();
byteBuffer.rewind();
assertEquals(1L, ReportPoint.fromByteBuffer(byteBuffer).getValue());
// test long (no widening conversion.
rp = ReportPoint.newBuilder().setValue(1L).setMetric("hello").setTimestamp(12345).build();
byteBuffer = rp.toByteBuffer();
byteBuffer.rewind();
assertEquals(1L, ReportPoint.fromByteBuffer(byteBuffer).getValue());
// test float to double widening conversion.
rp = ReportPoint.newBuilder().setValue(1f).setMetric("hello").setTimestamp(12345).build();
byteBuffer = rp.toByteBuffer();
byteBuffer.rewind();
assertEquals(1.0D, ReportPoint.fromByteBuffer(byteBuffer).getValue());
// test long (no widening conversion.
rp = ReportPoint.newBuilder().setValue(1.0D).setMetric("hello").setTimestamp(12345).build();
byteBuffer = rp.toByteBuffer();
byteBuffer.rewind();
assertEquals(1.0D, ReportPoint.fromByteBuffer(byteBuffer).getValue());
}
Aggregations