Search in sources :

Example 41 with Metric

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

the class LongCumulativeImplTest method getOrCreateTimeSeries.

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

Example 42 with Metric

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

the class LongCumulativeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    LongPoint longPoint = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    longPoint.add(1);
    longPoint.add(2);
    LongPoint defaultPoint = longCumulativeMetric.getDefaultTimeSeries();
    defaultPoint.add(100);
    LongPoint longPoint1 = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
    longPoint1.add(-100);
    longPoint1.add(-20);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(0), endTime), START_TIME));
    Metric metric = longCumulativeMetric.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(3);
    assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 43 with Metric

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

the class LongCumulativeImplTest method getOrCreateTimeSeries_IgnoreNegativePointValues.

@Test
public void getOrCreateTimeSeries_IgnoreNegativePointValues() {
    LongPoint point = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(-100);
    point.add(25);
    point.add(-33);
    testClock.advanceTime(ONE_MINUTE);
    Metric metric = longCumulativeMetric.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.longValue(25));
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Test(org.junit.Test)

Example 44 with Metric

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

the class DerivedDoubleGaugeImplTest method addTimeSeries_WithNullObj.

@Test
public void addTimeSeries_WithNullObj() {
    derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, negativeDoubleFunction);
    Metric metric = derivedDoubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(-200.5), TEST_TIME), null)));
}
Also used : Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 45 with Metric

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

the class DerivedLongGaugeImplTest method removeTimeSeries.

@Test
public void removeTimeSeries() {
    derivedLongGauge.createTimeSeries(LABEL_VALUES, null, longFunction);
    Metric metric = derivedLongGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
    derivedLongGauge.removeTimeSeries(LABEL_VALUES);
    assertThat(derivedLongGauge.getMetric(testClock)).isNull();
}
Also used : 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