Search in sources :

Example 11 with LabelKey

use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.

the class DropWizardMetricsTest method collect_Timer.

@Test
public void collect_Timer() throws InterruptedException {
    Timer timer = metricRegistry.timer("requests");
    Timer.Context context = timer.time();
    Thread.sleep(1L);
    context.stop();
    ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_requests_timer", "Collected from codahale (metric=requests, " + "type=com.codahale.metrics.Timer)", NS_UNIT, Type.SUMMARY, Collections.<LabelKey>emptyList()));
    assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.summaryValue(Summary.create(1L, 0.0, Snapshot.create(1L, 0.0, Arrays.asList(ValueAtPercentile.create(50.0, timer.getSnapshot().getMedian()), ValueAtPercentile.create(75.0, timer.getSnapshot().get75thPercentile()), ValueAtPercentile.create(98.0, timer.getSnapshot().get98thPercentile()), ValueAtPercentile.create(99.0, timer.getSnapshot().get99thPercentile()), ValueAtPercentile.create(99.9, timer.getSnapshot().get999thPercentile()))))));
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
Also used : Timer(com.codahale.metrics.Timer) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 12 with LabelKey

use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.

the class DropWizardMetricsTest method collect_Meter.

@Test
public void collect_Meter() {
    Meter getRequests = metricRegistry.meter("get_requests");
    getRequests.mark();
    getRequests.mark();
    ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_get_requests_meter", "Collected from codahale (metric=get_requests, " + "type=com.codahale.metrics.Meter)", DEFAULT_UNIT, Type.CUMULATIVE_INT64, Collections.<LabelKey>emptyList()));
    assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(2));
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
Also used : Meter(com.codahale.metrics.Meter) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 13 with LabelKey

use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.

the class DerivedLongCumulativeImplTest method withConstantLabels.

@Test
public void withConstantLabels() {
    List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
    List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
    LabelKey constantKey = LabelKey.create("constant_key", "desc");
    LabelValue constantValue = LabelValue.create("constant_value");
    Map<LabelKey, LabelValue> constantLabels = Collections.<LabelKey, LabelValue>singletonMap(constantKey, constantValue);
    DerivedLongCumulativeImpl derivedLongCumulative2 = new DerivedLongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
    derivedLongCumulative2.createTimeSeries(labelValues, new QueueManager(), queueManagerFunction);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    List<LabelKey> allKeys = new ArrayList<>(labelKeys);
    allKeys.add(constantKey);
    MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.CUMULATIVE_INT64, allKeys);
    List<LabelValue> allValues = new ArrayList<>(labelValues);
    allValues.add(constantValue);
    TimeSeries expectedTimeSeries = TimeSeries.createWithOnePoint(allValues, Point.create(Value.longValue(3), endTime), START_TIME);
    Metric metric = derivedLongCumulative2.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
    assertThat(metric.getTimeSeriesList()).containsExactly(expectedTimeSeries);
    derivedLongCumulative2.removeTimeSeries(labelValues);
    Metric metric2 = derivedLongCumulative2.getMetric(testClock);
    assertThat(metric2).isNull();
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) LabelValue(io.opencensus.metrics.LabelValue) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 14 with LabelKey

use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.

the class DoubleCumulativeImplTest method withConstantLabels.

@Test
public void withConstantLabels() {
    List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
    List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
    LabelKey constantKey = LabelKey.create("constant_key", "desc");
    LabelValue constantValue = LabelValue.create("constant_value");
    Map<LabelKey, LabelValue> constantLabels = Collections.<LabelKey, LabelValue>singletonMap(constantKey, constantValue);
    DoubleCumulativeImpl doubleCumulative = new DoubleCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
    DoublePoint doublePoint = doubleCumulative.getOrCreateTimeSeries(labelValues);
    doublePoint.add(1);
    doublePoint.add(2);
    DoublePoint defaultPoint = doubleCumulative.getDefaultTimeSeries();
    defaultPoint.add(100);
    List<LabelKey> allKeys = new ArrayList<>(labelKeys);
    allKeys.add(constantKey);
    MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.CUMULATIVE_DOUBLE, allKeys);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    List<LabelValue> allValues = new ArrayList<>(labelValues);
    allValues.add(constantValue);
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    TimeSeries defaultTimeSeries = TimeSeries.createWithOnePoint(Arrays.asList(UNSET_VALUE, UNSET_VALUE, constantValue), Point.create(Value.doubleValue(100), endTime), START_TIME);
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.doubleValue(3), endTime), START_TIME));
    expectedTimeSeriesList.add(defaultTimeSeries);
    Metric metric = doubleCumulative.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
    assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
    doubleCumulative.removeTimeSeries(labelValues);
    Metric metric2 = doubleCumulative.getMetric(testClock);
    assertThat(metric2).isNotNull();
    assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) LabelValue(io.opencensus.metrics.LabelValue) ArrayList(java.util.ArrayList) Timestamp(io.opencensus.common.Timestamp) MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 15 with LabelKey

use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.

the class LongCumulativeImplTest method testEquals.

@Test
public void testEquals() {
    List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
    List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
    LongCumulativeImpl longCumulative = new LongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS, START_TIME);
    LongPoint defaultPoint1 = longCumulative.getDefaultTimeSeries();
    LongPoint defaultPoint2 = longCumulative.getDefaultTimeSeries();
    LongPoint longPoint1 = longCumulative.getOrCreateTimeSeries(labelValues);
    LongPoint longPoint2 = longCumulative.getOrCreateTimeSeries(labelValues);
    new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
    longCumulative.clear();
    LongPoint newDefaultPointAfterClear = longCumulative.getDefaultTimeSeries();
    LongPoint newLongPointAfterClear = longCumulative.getOrCreateTimeSeries(labelValues);
    longCumulative.removeTimeSeries(labelValues);
    LongPoint newLongPointAfterRemove = longCumulative.getOrCreateTimeSeries(labelValues);
    new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newLongPointAfterClear).addEqualityGroup(newLongPointAfterRemove).testEquals();
}
Also used : LabelValue(io.opencensus.metrics.LabelValue) EqualsTester(com.google.common.testing.EqualsTester) LabelKey(io.opencensus.metrics.LabelKey) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Test(org.junit.Test)

Aggregations

LabelKey (io.opencensus.metrics.LabelKey)25 Test (org.junit.Test)22 LabelValue (io.opencensus.metrics.LabelValue)17 ArrayList (java.util.ArrayList)16 Metric (io.opencensus.metrics.export.Metric)15 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)8 TimeSeries (io.opencensus.metrics.export.TimeSeries)8 EqualsTester (com.google.common.testing.EqualsTester)4 Timestamp (io.opencensus.common.Timestamp)4 Metric (com.google.api.Metric)3 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)3 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)3 MetricDescriptor (com.google.api.MetricDescriptor)2 TimeSeries (com.google.monitoring.v3.TimeSeries)2 ByteString (com.google.protobuf.ByteString)2 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)2 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)2 Map (java.util.Map)2 Counter (com.codahale.metrics.Counter)1 Histogram (com.codahale.metrics.Histogram)1