Search in sources :

Example 66 with Metric

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);
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 67 with Metric

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);
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 68 with Metric

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))));
}
Also used : DerivedLongGauge(io.opencensus.metrics.DerivedLongGauge) LongGauge(io.opencensus.metrics.LongGauge) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 69 with Metric

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)));
}
Also used : DoubleGauge(io.opencensus.metrics.DoubleGauge) DerivedDoubleGauge(io.opencensus.metrics.DerivedDoubleGauge) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 70 with Metric

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)));
}
Also used : DerivedLongGauge(io.opencensus.metrics.DerivedLongGauge) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Aggregations

Metric (io.opencensus.metrics.export.Metric)73 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)26 Timestamp (io.opencensus.common.Timestamp)19 TimeSeries (io.opencensus.metrics.export.TimeSeries)16 LabelKey (io.opencensus.metrics.LabelKey)15 LabelValue (io.opencensus.metrics.LabelValue)9 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)9 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)8 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)8 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)6 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)6 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)4 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)3 LongGauge (io.opencensus.metrics.LongGauge)3 MetricName (io.dropwizard.metrics5.MetricName)2 DoubleGauge (io.opencensus.metrics.DoubleGauge)2 MetricProducer (io.opencensus.metrics.export.MetricProducer)2 Span (io.opencensus.trace.Span)2 Counter (com.codahale.metrics.Counter)1