Search in sources :

Example 1 with DataPoint

use of com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint in project instrumentation-java by census-instrumentation.

the class SignalFxSessionAdaptor method adapt.

/**
 * Converts the given Metric into datapoints that can be sent to SignalFx.
 *
 * @param metric The {@link Metric} containing the timeseries of each combination of label values.
 * @return A list of datapoints for the corresponding metric timeseries of this metric.
 */
static List<DataPoint> adapt(Metric metric) {
    MetricDescriptor metricDescriptor = metric.getMetricDescriptor();
    MetricType metricType = getType(metricDescriptor.getType());
    if (metricType == null) {
        return Collections.emptyList();
    }
    DataPoint.Builder shared = DataPoint.newBuilder();
    shared.setMetric(metricDescriptor.getName());
    shared.setMetricType(metricType);
    ArrayList<DataPoint> datapoints = Lists.newArrayList();
    for (TimeSeries timeSeries : metric.getTimeSeriesList()) {
        DataPoint.Builder builder = shared.clone();
        builder.addAllDimensions(createDimensions(metricDescriptor.getLabelKeys(), timeSeries.getLabelValues()));
        List<Point> points = timeSeries.getPoints();
        datapoints.ensureCapacity(datapoints.size() + points.size());
        for (Point point : points) {
            datapoints.add(builder.setValue(createDatum(point.getValue())).build());
        }
    }
    return datapoints;
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) DataPoint(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint) MetricType(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType) Point(io.opencensus.metrics.export.Point) DataPoint(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint)

Example 2 with DataPoint

use of com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint in project instrumentation-java by census-instrumentation.

the class SignalFxSessionAdaptorTest method adaptMetricIntoDatapoints.

@Test
public void adaptMetricIntoDatapoints() {
    List<DataPoint> datapoints = SignalFxSessionAdaptor.adapt(METRIC);
    assertEquals(2, datapoints.size());
    for (DataPoint dp : datapoints) {
        assertEquals(METRIC_NAME, dp.getMetric());
        assertEquals(MetricType.CUMULATIVE_COUNTER, dp.getMetricType());
        assertEquals(1, dp.getDimensionsCount());
        assertTrue(dp.hasValue());
        assertFalse(dp.hasSource());
        Datum datum = dp.getValue();
        assertTrue(datum.hasIntValue());
        assertFalse(datum.hasDoubleValue());
        assertFalse(datum.hasStrValue());
        Dimension dimension = dp.getDimensions(0);
        assertEquals(LABEL_KEY_1.getKey(), dimension.getKey());
        switch(dimension.getValue()) {
            case "value1":
                assertEquals(2L, datum.getIntValue());
                break;
            case "value2":
                assertEquals(3L, datum.getIntValue());
                break;
            default:
                fail("unexpected dimension value");
        }
    }
}
Also used : Datum(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Datum) DataPoint(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint) Dimension(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Dimension) Test(org.junit.Test)

Example 3 with DataPoint

use of com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint in project instrumentation-java by census-instrumentation.

the class SignalFxSessionAdaptorTest method adaptMetricWithEmptyLabelValueIntoDatapoints.

@Test
public void adaptMetricWithEmptyLabelValueIntoDatapoints() {
    List<DataPoint> datapoints = SignalFxSessionAdaptor.adapt(METRIC_1);
    assertEquals(2, datapoints.size());
    for (DataPoint dp : datapoints) {
        assertEquals(METRIC_NAME, dp.getMetric());
        assertEquals(MetricType.CUMULATIVE_COUNTER, dp.getMetricType());
        assertTrue(dp.hasValue());
        assertFalse(dp.hasSource());
        Datum datum = dp.getValue();
        assertTrue(datum.hasIntValue());
        assertFalse(datum.hasDoubleValue());
        assertFalse(datum.hasStrValue());
        switch(dp.getDimensionsCount()) {
            case 0:
                assertEquals(3L, datum.getIntValue());
                break;
            case 1:
                Dimension dimension = dp.getDimensions(0);
                assertEquals(LABEL_KEY_1.getKey(), dimension.getKey());
                assertEquals(LABEL_VALUE_1.getValue(), dimension.getValue());
                assertEquals(2L, datum.getIntValue());
                break;
            default:
                fail("Unexpected number of dimensions on the created datapoint");
                break;
        }
    }
}
Also used : Datum(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Datum) DataPoint(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint) Dimension(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Dimension) Test(org.junit.Test)

Example 4 with DataPoint

use of com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint in project instrumentation-java by census-instrumentation.

the class SignalFxMetricExporterTest method setsDatapointsFromViewOnSession.

@Test
public void setsDatapointsFromViewOnSession() throws IOException {
    SignalFxMetricExporter exporter = new SignalFxMetricExporter(factory, endpoint, TEST_TOKEN);
    exporter.export(Collections.singletonList(METRIC));
    DataPoint datapoint = DataPoint.newBuilder().setMetric("metric-name").setMetricType(MetricType.GAUGE).addDimensions(Dimension.newBuilder().setKey("key1").setValue("value1").build()).setValue(Datum.newBuilder().setDoubleValue(3.15d).build()).build();
    Mockito.verify(session).setDatapoint(Mockito.eq(datapoint));
    Mockito.verify(session).close();
}
Also used : DataPoint(com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint) Test(org.junit.Test)

Aggregations

DataPoint (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint)4 Test (org.junit.Test)3 Datum (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Datum)2 Dimension (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.Dimension)2 MetricType (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1 Point (io.opencensus.metrics.export.Point)1 TimeSeries (io.opencensus.metrics.export.TimeSeries)1