use of wavefront.report.Histogram in project java by wavefrontHQ.
the class HistogramDecoderTest method testBasicMessage.
@Test
public void testBasicMessage() {
HistogramDecoder decoder = new HistogramDecoder();
List<ReportPoint> out = new ArrayList<>();
decoder.decodeReportPoints("!M 1471988653 #3 123.237 TestMetric source=Test key=value", out, "customer");
assertThat(out).isNotEmpty();
ReportPoint p = out.get(0);
assertThat(p.getMetric()).isEqualTo("TestMetric");
// Should be converted to Millis and pinned to the beginning of the corresponding minute
assertThat(p.getTimestamp()).isEqualTo(1471988640000L);
assertThat(p.getValue()).isNotNull();
assertThat(p.getValue().getClass()).isEqualTo(Histogram.class);
assertThat(p.getHost()).isEqualTo("Test");
assertThat(p.getTable()).isEqualTo("customer");
assertThat(p.getAnnotations()).isNotNull();
assertThat(p.getAnnotations()).containsEntry("key", "value");
Histogram h = (Histogram) p.getValue();
assertThat(h.getDuration()).isEqualTo(DateUtils.MILLIS_PER_MINUTE);
assertThat(h.getBins()).isNotNull();
assertThat(h.getBins()).isNotEmpty();
assertThat(h.getBins()).containsExactly(123.237D);
assertThat(h.getCounts()).isNotNull();
assertThat(h.getCounts()).isNotEmpty();
assertThat(h.getCounts()).containsExactly(3);
}
use of wavefront.report.Histogram in project java by wavefrontHQ.
the class HistogramDecoderTest method testMissingTimestamp.
@Test
public void testMissingTimestamp() {
// Note - missingTimestamp to port 40,000 is no longer invalid - see MONIT-6430 for more details
HistogramDecoder decoder = new HistogramDecoder();
List<ReportPoint> out = new ArrayList<>();
decoder.decodeReportPoints("!M #3 123.237 TestMetric source=Test tag=value", out, "customer");
assertThat(out).isNotEmpty();
long expectedTimestamp = Clock.now();
ReportPoint p = out.get(0);
assertThat(p.getMetric()).isEqualTo("TestMetric");
assertThat(p.getValue()).isNotNull();
assertThat(p.getValue().getClass()).isEqualTo(Histogram.class);
// Should be converted to Millis and pinned to the beginning of the corresponding minute
long duration = ((Histogram) p.getValue()).getDuration();
expectedTimestamp = (expectedTimestamp / duration) * duration;
assertThat(p.getTimestamp()).isEqualTo(expectedTimestamp);
assertThat(p.getHost()).isEqualTo("Test");
assertThat(p.getTable()).isEqualTo("customer");
assertThat(p.getAnnotations()).isNotNull();
assertThat(p.getAnnotations()).containsEntry("_tag", "value");
Histogram h = (Histogram) p.getValue();
assertThat(h.getDuration()).isEqualTo(DateUtils.MILLIS_PER_MINUTE);
assertThat(h.getBins()).isNotNull();
assertThat(h.getBins()).isNotEmpty();
assertThat(h.getBins()).containsExactly(123.237D);
assertThat(h.getCounts()).isNotNull();
assertThat(h.getCounts()).isNotEmpty();
assertThat(h.getCounts()).containsExactly(3);
}
use of wavefront.report.Histogram in project java by wavefrontHQ.
the class Validation method validatePoint.
public static void validatePoint(ReportPoint point, String source, String debugLine, @Nullable Level validationLevel) {
Object pointValue = point.getValue();
if (StringUtils.isBlank(point.getHost())) {
String errorMessage = "WF-301: Source/host name is required (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
if (point.getHost().length() >= 1024) {
String errorMessage = "WF-301: Source/host name is too long: " + point.getHost() + "(" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
if (point.getMetric().length() >= 1024) {
String errorMessage = "WF-301: Metric name is too long: " + point.getMetric() + " (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
if (!charactersAreValid(point.getMetric())) {
illegalCharacterPoints.inc();
String errorMessage = "WF-400 " + source + ": Point metric has illegal character (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
if (point.getAnnotations() != null) {
if (!annotationKeysAreValid(point)) {
String errorMessage = "WF-401 " + source + ": Point annotation key has illegal character (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
// Each tag of the form "k=v" must be < 256
for (Map.Entry<String, String> tag : point.getAnnotations().entrySet()) {
if (tag.getKey().length() + tag.getValue().length() >= 255) {
String errorMessage = "Tag too long: " + tag.getKey() + "=" + tag.getValue() + " (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
}
}
if ((validationLevel != null) && (!validationLevel.equals(NO_VALIDATION))) {
// Is it the right type of point?
switch(validationLevel) {
case NUMERIC_ONLY:
if (!(pointValue instanceof Long) && !(pointValue instanceof Double) && !(pointValue instanceof Histogram)) {
String errorMessage = "WF-403 " + source + ": Was not long/double/histogram object (" + (debugLine == null ? pointToString(point) : debugLine) + ")";
throw new IllegalArgumentException(errorMessage);
}
break;
}
}
}
use of wavefront.report.Histogram in project java by wavefrontHQ.
the class PointHandlerTest method setUp.
@Before
public void setUp() {
Histogram h = Histogram.newBuilder().setType(HistogramType.TDIGEST).setBins(ImmutableList.of(10D, 20D)).setCounts(ImmutableList.of(2, 4)).setDuration((int) DateUtils.MILLIS_PER_MINUTE).build();
histogramPoint = ReportPoint.newBuilder().setTable("customer").setValue(h).setMetric("TestMetric").setHost("TestSource").setTimestamp(1469751813000L).setAnnotations(ImmutableMap.of("keyA", "valueA", "keyB", "valueB")).build();
}
Aggregations