use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method getDefaultTimeSeries.
@Test
public void getDefaultTimeSeries() {
LongPoint point = longGaugeMetric.getDefaultTimeSeries();
point.add(100);
point.set(500);
LongPoint point1 = longGaugeMetric.getDefaultTimeSeries();
point1.add(-100);
Metric metric = longGaugeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(400), TEST_TIME), null)));
assertThat(point).isSameInstanceAs(point1);
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method multipleMetrics_GetMetric.
@Test
public void multipleMetrics_GetMetric() {
LongPoint longPoint = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.add(1);
longPoint.add(2);
LongPoint defaultPoint = longGaugeMetric.getDefaultTimeSeries();
defaultPoint.set(100);
LongPoint longPoint1 = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
longPoint1.add(-100);
longPoint1.add(-20);
List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(-120), TEST_TIME), null));
Metric metric = longGaugeMetric.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 MetricRegistryImplTest method shouldReturnSameObjectOnMultipleRegisterCall.
@Test
public void shouldReturnSameObjectOnMultipleRegisterCall() {
LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
LongPoint longPoint = longGauge.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.set(200);
LongGauge longGauge1 = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
LongPoint longPoint1 = longGauge1.getOrCreateTimeSeries(Collections.singletonList(LABEL_VALUE_2));
longPoint1.set(300);
assertThat(longGauge).isEqualTo(longGauge1);
Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
assertThat(metricCollections.size()).isEqualTo(1);
assertThat(metricCollections).containsExactly(Metric.create(LONG_METRIC_DESCRIPTOR, Arrays.asList(TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE, LABEL_VALUE_2), Point.create(Value.longValue(200), TEST_TIME), null), TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE_2, LABEL_VALUE_2), Point.create(Value.longValue(300), TEST_TIME), null))));
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class MetricRegistryImplTest method addDoubleGauge_GetMetrics.
@Test
public void addDoubleGauge_GetMetrics() {
DoubleGauge doubleGauge = metricRegistry.addDoubleGauge(NAME_2, METRIC_OPTIONS);
doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
assertThat(metricCollections.size()).isEqualTo(1);
assertThat(metricCollections).containsExactly(Metric.createWithOneTimeSeries(DOUBLE_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.doubleValue(0.0), TEST_TIME), null)));
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class MetricRegistryImplTest method addDerivedLongGauge_GetMetrics.
@Test
public void addDerivedLongGauge_GetMetrics() {
DerivedLongGauge derivedLongGauge = metricRegistry.addDerivedLongGauge(NAME_3, METRIC_OPTIONS);
derivedLongGauge.createTimeSeries(LABEL_VALUES, null, longFunction);
Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
assertThat(metricCollections.size()).isEqualTo(1);
assertThat(metricCollections).containsExactly(Metric.createWithOneTimeSeries(DERIVED_LONG_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.longValue(5), TEST_TIME), null)));
}
Aggregations