use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class MetricRegistryImplTest method getMetrics.
@Test
public void getMetrics() {
LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
LongPoint longPoint = longGauge.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.set(200);
DoubleGauge doubleGauge = metricRegistry.addDoubleGauge(NAME_2, METRIC_OPTIONS);
DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
doublePoint.set(-300.13);
DerivedLongGauge derivedLongGauge = metricRegistry.addDerivedLongGauge(NAME_3, METRIC_OPTIONS);
derivedLongGauge.createTimeSeries(LABEL_VALUES, null, longFunction);
DerivedDoubleGauge derivedDoubleGauge = metricRegistry.addDerivedDoubleGauge(NAME_4, METRIC_OPTIONS);
derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, doubleFunction);
Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
assertThat(metricCollections.size()).isEqualTo(4);
assertThat(metricCollections).containsExactly(Metric.createWithOneTimeSeries(LONG_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.longValue(200), TEST_TIME), null)), Metric.createWithOneTimeSeries(DOUBLE_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.doubleValue(-300.13), TEST_TIME), null)), Metric.createWithOneTimeSeries(DERIVED_LONG_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.longValue(5), TEST_TIME), null)), Metric.createWithOneTimeSeries(DERIVED_DOUBLE_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.doubleValue(5.0), TEST_TIME), null)));
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method getOrCreateTimeSeries_WithNegativePointValues.
@Test
public void getOrCreateTimeSeries_WithNegativePointValues() {
DoublePoint point = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
point.add(-100);
point.add(-33);
Metric metric = doubleGauge.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(-133));
assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getTimestamp()).isEqualTo(TEST_TIME);
assertThat(metric.getTimeSeriesList().get(0).getStartTimestamp()).isNull();
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method getDefaultTimeSeries.
@Test
public void getDefaultTimeSeries() {
DoublePoint point = doubleGauge.getDefaultTimeSeries();
point.add(100);
point.set(500);
DoublePoint point1 = doubleGauge.getDefaultTimeSeries();
point1.add(-100);
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.create(METRIC_DESCRIPTOR, Collections.singletonList(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(400), TEST_TIME), null))));
assertThat(point).isSameInstanceAs(point1);
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method pointImpl_InstanceOf.
@Test
public void pointImpl_InstanceOf() {
DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
assertThat(doublePoint).isInstanceOf(DoubleGaugeImpl.PointImpl.class);
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method withConstantLabels.
@Test
public void withConstantLabels() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
LabelKey constantKey = LabelKey.create("constant_key", "desc");
LabelValue constantValue = LabelValue.create("constant_value");
Map<LabelKey, LabelValue> constantLabels = Collections.<LabelKey, LabelValue>singletonMap(constantKey, constantValue);
DoubleGaugeImpl doubleGauge = new DoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels);
DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(labelValues);
doublePoint.add(1);
doublePoint.add(2);
DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
defaultPoint.set(100);
List<LabelKey> allKeys = new ArrayList<>(labelKeys);
allKeys.add(constantKey);
MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.GAUGE_DOUBLE, allKeys);
List<LabelValue> allValues = new ArrayList<>(labelValues);
allValues.add(constantValue);
List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
TimeSeries defaultTimeSeries = TimeSeries.createWithOnePoint(Arrays.asList(UNSET_VALUE, UNSET_VALUE, constantValue), Point.create(Value.doubleValue(100), TEST_TIME), null);
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.doubleValue(3), TEST_TIME), null));
expectedTimeSeriesList.add(defaultTimeSeries);
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
doubleGauge.removeTimeSeries(labelValues);
Metric metric2 = doubleGauge.getMetric(testClock);
assertThat(metric2).isNotNull();
assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
Aggregations