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