use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DropWizardMetricsTest method filter_GetMetrics.
@Test
public void filter_GetMetrics() {
MetricFilter filter = new MetricFilter() {
@Override
public boolean matches(MetricName name, io.dropwizard.metrics5.Metric metric) {
return name.getKey().startsWith("test");
}
};
dropWizardMetrics = new DropWizardMetrics(Collections.singletonList(metricRegistry), filter);
metricRegistry.timer("test_requests");
metricRegistry.timer("requests");
Collection<Metric> metrics = dropWizardMetrics.getMetrics();
assertThat(metrics).hasSize(1);
Metric value = metrics.iterator().next();
assertThat(value.getMetricDescriptor().getName()).isEqualTo("dropwizard5_test_requests_timer");
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedDoubleCumulativeImplTest 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);
DerivedDoubleCumulativeImpl derivedDoubleCumulative2 = new DerivedDoubleCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
derivedDoubleCumulative2.createTimeSeries(labelValues, new QueueManager(), queueManagerFunction);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
List<LabelKey> allKeys = new ArrayList<>(labelKeys);
allKeys.add(constantKey);
MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.CUMULATIVE_DOUBLE, allKeys);
List<LabelValue> allValues = new ArrayList<>(labelValues);
allValues.add(constantValue);
TimeSeries expectedTimeSeries = TimeSeries.createWithOnePoint(allValues, Point.create(Value.doubleValue(2.5), endTime), START_TIME);
Metric metric = derivedDoubleCumulative2.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList()).containsExactly(expectedTimeSeries);
derivedDoubleCumulative2.removeTimeSeries(labelValues);
Metric metric2 = derivedDoubleCumulative2.getMetric(testClock);
assertThat(metric2).isNull();
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedLongCumulativeImplTest method addTimeSeries_IgnoreNegativeValue.
@Test
public void addTimeSeries_IgnoreNegativeValue() {
derivedLongCumulative.createTimeSeries(LABEL_VALUES, null, negativeLongFunction);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = derivedLongCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(0), endTime), START_TIME)));
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DerivedLongCumulativeImplTest method createTimeSeries_WithObjFunction.
@Test
public void createTimeSeries_WithObjFunction() {
derivedLongCumulative.createTimeSeries(LABEL_VALUES, new QueueManager(), queueManagerFunction);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = derivedLongCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), endTime), START_TIME)));
}
use of io.opencensus.metrics.export.Metric in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest method clear.
@Test
public void clear() {
DoublePoint doublePoint = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
doublePoint.add(100);
Metric metric = doubleCumulativeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
doubleCumulativeMetric.clear();
assertThat(doubleCumulativeMetric.getMetric(testClock)).isNull();
}
Aggregations