use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedDoubleGaugeImplTest method createTimeSeries_WithObjFunction.
@Test
public void createTimeSeries_WithObjFunction() {
derivedDoubleGauge.createTimeSeries(LABEL_VALUES, new QueueManager(), queueManagerFunction);
Metric metric = derivedDoubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(2.5), TEST_TIME), null)));
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedDoubleGaugeImplTest method removeTimeSeries.
@Test
public void removeTimeSeries() {
derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, doubleFunction);
Metric metric = derivedDoubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
derivedDoubleGauge.removeTimeSeries(LABEL_VALUES);
assertThat(derivedDoubleGauge.getMetric(testClock)).isNull();
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedDoubleGaugeImplTest 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);
DerivedDoubleGaugeImpl derivedDoubleGauge2 = new DerivedDoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels);
derivedDoubleGauge2.createTimeSeries(labelValues, new QueueManager(), queueManagerFunction);
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);
TimeSeries expectedTimeSeries = TimeSeries.createWithOnePoint(allValues, Point.create(Value.doubleValue(2.5), TEST_TIME), null);
Metric metric = derivedDoubleGauge2.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList()).containsExactly(expectedTimeSeries);
derivedDoubleGauge2.removeTimeSeries(labelValues);
Metric metric2 = derivedDoubleGauge2.getMetric(testClock);
assertThat(metric2).isNull();
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedDoubleGaugeImplTest method clear.
@Test
public void clear() {
derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, doubleFunction);
derivedDoubleGauge.createTimeSeries(LABEL_VALUES_1, new QueueManager(), queueManagerFunction);
Metric metric = derivedDoubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
derivedDoubleGauge.clear();
assertThat(derivedDoubleGauge.getMetric(testClock)).isNull();
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedLongGaugeImplTest method addTimeSeries_WithNullObj.
@Test
public void addTimeSeries_WithNullObj() {
derivedLongGauge.createTimeSeries(LABEL_VALUES, null, negativeLongFunction);
Metric metric = derivedLongGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(-200), TEST_TIME), null)));
}
Aggregations