Search in sources :

Example 16 with Metric

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

the class DoubleCumulativeImplTest method getOrCreateTimeSeries_IgnoreNegativePointValues.

@Test
public void getOrCreateTimeSeries_IgnoreNegativePointValues() {
    DoublePoint point = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(-100);
    point.add(25);
    point.add(-33);
    testClock.advanceTime(ONE_MINUTE);
    Metric metric = doubleCumulativeMetric.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(25));
}
Also used : DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 17 with Metric

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

the class DoubleCumulativeImplTest method getDefaultTimeSeries.

@Test
public void getDefaultTimeSeries() {
    DoublePoint point = doubleCumulativeMetric.getDefaultTimeSeries();
    point.add(100);
    DoublePoint point1 = doubleCumulativeMetric.getDefaultTimeSeries();
    point1.add(-100);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    Metric metric = doubleCumulativeMetric.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), endTime), START_TIME)));
    assertThat(point).isSameInstanceAs(point1);
}
Also used : DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 18 with Metric

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

the class DoubleCumulativeImplTest method getOrCreateTimeSeries.

@Test
public void getOrCreateTimeSeries() {
    DoublePoint point = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(100);
    DoublePoint point1 = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point1.add(500);
    assertThat(point).isSameInstanceAs(point1);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    Metric metric = doubleCumulativeMetric.getMetric(testClock);
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(600), endTime), START_TIME)));
}
Also used : DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 19 with Metric

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

the class DerivedDoubleCumulativeImplTest method removeTimeSeries.

@Test
public void removeTimeSeries() {
    derivedDoubleCumulative.createTimeSeries(LABEL_VALUES, null, doubleFunction);
    Metric metric = derivedDoubleCumulative.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
    derivedDoubleCumulative.removeTimeSeries(LABEL_VALUES);
    assertThat(derivedDoubleCumulative.getMetric(testClock)).isNull();
}
Also used : Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 20 with Metric

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

the class DerivedDoubleGaugeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, doubleFunction);
    derivedDoubleGauge.createTimeSeries(LABEL_VALUES_1, new QueueManager(), queueManagerFunction);
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(5.5), TEST_TIME), null));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES_1, Point.create(Value.doubleValue(2.5), TEST_TIME), null));
    Metric metric = derivedDoubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
    assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
    assertThat(metric.getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(0)).isEqualTo(LabelValue.create("value"));
    assertThat(metric.getTimeSeriesList().get(1).getLabelValues().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(1).getLabelValues().get(0)).isEqualTo(LabelValue.create("value1"));
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Aggregations

Metric (io.opencensus.metrics.export.Metric)73 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)26 Timestamp (io.opencensus.common.Timestamp)19 TimeSeries (io.opencensus.metrics.export.TimeSeries)16 LabelKey (io.opencensus.metrics.LabelKey)15 LabelValue (io.opencensus.metrics.LabelValue)9 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)9 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)8 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)8 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)6 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)6 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)4 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)3 LongGauge (io.opencensus.metrics.LongGauge)3 MetricName (io.dropwizard.metrics5.MetricName)2 DoubleGauge (io.opencensus.metrics.DoubleGauge)2 MetricProducer (io.opencensus.metrics.export.MetricProducer)2 Span (io.opencensus.trace.Span)2 Counter (com.codahale.metrics.Counter)1