use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class DropWizardMetricsTest method collect_Timer.
@Test
public void collect_Timer() throws InterruptedException {
Timer timer = metricRegistry.timer("requests");
Timer.Context context = timer.time();
Thread.sleep(1L);
context.stop();
ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
assertThat(metrics.size()).isEqualTo(1);
assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_requests_timer", "Collected from codahale (metric=requests, " + "type=com.codahale.metrics.Timer)", NS_UNIT, Type.SUMMARY, Collections.<LabelKey>emptyList()));
assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.summaryValue(Summary.create(1L, 0.0, Snapshot.create(1L, 0.0, Arrays.asList(ValueAtPercentile.create(50.0, timer.getSnapshot().getMedian()), ValueAtPercentile.create(75.0, timer.getSnapshot().get75thPercentile()), ValueAtPercentile.create(98.0, timer.getSnapshot().get98thPercentile()), ValueAtPercentile.create(99.0, timer.getSnapshot().get99thPercentile()), ValueAtPercentile.create(99.9, timer.getSnapshot().get999thPercentile()))))));
assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class DropWizardMetricsTest method collect_Meter.
@Test
public void collect_Meter() {
Meter getRequests = metricRegistry.meter("get_requests");
getRequests.mark();
getRequests.mark();
ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
assertThat(metrics.size()).isEqualTo(1);
assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_get_requests_meter", "Collected from codahale (metric=get_requests, " + "type=com.codahale.metrics.Meter)", DEFAULT_UNIT, Type.CUMULATIVE_INT64, Collections.<LabelKey>emptyList()));
assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(2));
assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class DerivedLongCumulativeImplTest 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);
DerivedLongCumulativeImpl derivedLongCumulative2 = new DerivedLongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
derivedLongCumulative2.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_INT64, allKeys);
List<LabelValue> allValues = new ArrayList<>(labelValues);
allValues.add(constantValue);
TimeSeries expectedTimeSeries = TimeSeries.createWithOnePoint(allValues, Point.create(Value.longValue(3), endTime), START_TIME);
Metric metric = derivedLongCumulative2.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList()).containsExactly(expectedTimeSeries);
derivedLongCumulative2.removeTimeSeries(labelValues);
Metric metric2 = derivedLongCumulative2.getMetric(testClock);
assertThat(metric2).isNull();
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest 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);
DoubleCumulativeImpl doubleCumulative = new DoubleCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
DoublePoint doublePoint = doubleCumulative.getOrCreateTimeSeries(labelValues);
doublePoint.add(1);
doublePoint.add(2);
DoublePoint defaultPoint = doubleCumulative.getDefaultTimeSeries();
defaultPoint.add(100);
List<LabelKey> allKeys = new ArrayList<>(labelKeys);
allKeys.add(constantKey);
MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.CUMULATIVE_DOUBLE, allKeys);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
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), endTime), START_TIME);
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.doubleValue(3), endTime), START_TIME));
expectedTimeSeriesList.add(defaultTimeSeries);
Metric metric = doubleCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
doubleCumulative.removeTimeSeries(labelValues);
Metric metric2 = doubleCumulative.getMetric(testClock);
assertThat(metric2).isNotNull();
assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
use of io.opencensus.metrics.LabelKey in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method testEquals.
@Test
public void testEquals() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
LongCumulativeImpl longCumulative = new LongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS, START_TIME);
LongPoint defaultPoint1 = longCumulative.getDefaultTimeSeries();
LongPoint defaultPoint2 = longCumulative.getDefaultTimeSeries();
LongPoint longPoint1 = longCumulative.getOrCreateTimeSeries(labelValues);
LongPoint longPoint2 = longCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
longCumulative.clear();
LongPoint newDefaultPointAfterClear = longCumulative.getDefaultTimeSeries();
LongPoint newLongPointAfterClear = longCumulative.getOrCreateTimeSeries(labelValues);
longCumulative.removeTimeSeries(labelValues);
LongPoint newLongPointAfterRemove = longCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newLongPointAfterClear).addEqualityGroup(newLongPointAfterRemove).testEquals();
}
Aggregations