Search in sources :

Example 11 with Histogram

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);
}
Also used : Histogram(wavefront.report.Histogram) ArrayList(java.util.ArrayList) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 12 with Histogram

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);
}
Also used : Histogram(wavefront.report.Histogram) ArrayList(java.util.ArrayList) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 13 with Histogram

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;
        }
    }
}
Also used : Histogram(wavefront.report.Histogram) PointHandlerImpl.pointToString(com.wavefront.agent.PointHandlerImpl.pointToString) Map(java.util.Map)

Example 14 with Histogram

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();
}
Also used : Histogram(wavefront.report.Histogram) Before(org.junit.Before)

Aggregations

Histogram (wavefront.report.Histogram)14 Test (org.junit.Test)10 ReportPoint (wavefront.report.ReportPoint)10 ArrayList (java.util.ArrayList)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 ObjectQueue (com.squareup.tape.ObjectQueue)1 AgentDigest (com.tdunning.math.stats.AgentDigest)1 PointHandler (com.wavefront.agent.PointHandler)1 PointHandlerImpl.pointToString (com.wavefront.agent.PointHandlerImpl.pointToString)1 Validation (com.wavefront.agent.Validation)1 Utils (com.wavefront.agent.histogram.Utils)1 Granularity.fromMillis (com.wavefront.agent.histogram.Utils.Granularity.fromMillis)1 Decoder (com.wavefront.ingester.Decoder)1 Metrics (com.yammer.metrics.Metrics)1 Counter (com.yammer.metrics.core.Counter)1 MetricName (com.yammer.metrics.core.MetricName)1 System.nanoTime (java.lang.System.nanoTime)1 List (java.util.List)1