Search in sources :

Example 6 with DoublePoint

use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.

the class DoubleGaugeImplTest method getOrCreateTimeSeries.

@Test
public void getOrCreateTimeSeries() {
    DoublePoint point = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(100);
    DoublePoint point1 = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    point1.set(500);
    Metric metric = doubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.create(METRIC_DESCRIPTOR, Collections.singletonList(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(500), TEST_TIME), null))));
    assertThat(point).isSameInstanceAs(point1);
}
Also used : DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 7 with DoublePoint

use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.

the class DoubleGaugeImplTest method clear.

@Test
public void clear() {
    DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    doublePoint.add(-11);
    DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
    defaultPoint.set(100);
    Metric metric = doubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
    doubleGauge.clear();
    assertThat(doubleGauge.getMetric(testClock)).isNull();
}
Also used : DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 8 with DoublePoint

use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.

the class DoubleGaugeImplTest 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"));
    DoubleGaugeImpl doubleGauge = new DoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
    DoublePoint defaultPoint1 = doubleGauge.getDefaultTimeSeries();
    DoublePoint defaultPoint2 = doubleGauge.getDefaultTimeSeries();
    DoublePoint doublePoint1 = doubleGauge.getOrCreateTimeSeries(labelValues);
    DoublePoint doublePoint2 = doubleGauge.getOrCreateTimeSeries(labelValues);
    new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).testEquals();
    doubleGauge.clear();
    DoublePoint newDefaultPointAfterClear = doubleGauge.getDefaultTimeSeries();
    DoublePoint newDoublePointAfterClear = doubleGauge.getOrCreateTimeSeries(labelValues);
    doubleGauge.removeTimeSeries(labelValues);
    DoublePoint newDoublePointAfterRemove = doubleGauge.getOrCreateTimeSeries(labelValues);
    new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newDoublePointAfterClear).addEqualityGroup(newDoublePointAfterRemove).testEquals();
}
Also used : LabelValue(io.opencensus.metrics.LabelValue) EqualsTester(com.google.common.testing.EqualsTester) DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) LabelKey(io.opencensus.metrics.LabelKey) Test(org.junit.Test)

Example 9 with DoublePoint

use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.

the class DoubleGaugeImplTest method setDefaultLabelValues.

@Test
public void setDefaultLabelValues() {
    List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
    DoubleGaugeImpl doubleGauge = new DoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
    DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
    defaultPoint.set(-230);
    Metric metric = doubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(2);
    assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(0)).isEqualTo(UNSET_VALUE);
    assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(1)).isEqualTo(UNSET_VALUE);
}
Also used : DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 10 with DoublePoint

use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.

the class DoubleGaugeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    doublePoint.add(1);
    doublePoint.add(2);
    DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
    defaultPoint.set(100);
    DoublePoint doublePoint1 = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES1);
    doublePoint1.add(-100);
    doublePoint1.add(-20);
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(3), TEST_TIME), null));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), TEST_TIME), null));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.doubleValue(-120), TEST_TIME), null));
    Metric metric = doubleGauge.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) DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Aggregations

DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)10 Test (org.junit.Test)10 Metric (io.opencensus.metrics.export.Metric)8 LabelKey (io.opencensus.metrics.LabelKey)3 LabelValue (io.opencensus.metrics.LabelValue)2 TimeSeries (io.opencensus.metrics.export.TimeSeries)2 ArrayList (java.util.ArrayList)2 EqualsTester (com.google.common.testing.EqualsTester)1 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)1 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)1 DoubleGauge (io.opencensus.metrics.DoubleGauge)1 LongGauge (io.opencensus.metrics.LongGauge)1 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1