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));
}
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);
}
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)));
}
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();
}
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"));
}
Aggregations