Search in sources :

Example 1 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest method clear.

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

Example 2 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest method pointImpl_InstanceOf.

@Test
public void pointImpl_InstanceOf() {
    LongPoint longPoint = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    assertThat(longPoint).isInstanceOf(LongGaugeImpl.PointImpl.class);
}
Also used : LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 3 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest 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);
    LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels);
    LongPoint longPoint = longGauge.getOrCreateTimeSeries(labelValues);
    longPoint.add(1);
    longPoint.add(2);
    LongPoint defaultPoint = longGauge.getDefaultTimeSeries();
    defaultPoint.set(100);
    List<LabelKey> allKeys = new ArrayList<>(labelKeys);
    allKeys.add(constantKey);
    MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.GAUGE_INT64, allKeys);
    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.longValue(100), TEST_TIME), null);
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.longValue(3), TEST_TIME), null));
    expectedTimeSeriesList.add(defaultTimeSeries);
    Metric metric = longGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
    assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
    longGauge.removeTimeSeries(labelValues);
    Metric metric2 = longGauge.getMetric(testClock);
    assertThat(metric2).isNotNull();
    assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) LabelValue(io.opencensus.metrics.LabelValue) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 4 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest method getOrCreateTimeSeries.

@Test
public void getOrCreateTimeSeries() {
    LongPoint point = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(100);
    LongPoint point1 = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point1.set(500);
    Metric metric = longGaugeMetric.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(500), 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 5 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class MetricRegistryImplTest method getMetrics.

@Test
public void getMetrics() {
    LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
    LongPoint longPoint = longGauge.getOrCreateTimeSeries(LABEL_VALUES);
    longPoint.set(200);
    DoubleGauge doubleGauge = metricRegistry.addDoubleGauge(NAME_2, METRIC_OPTIONS);
    DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    doublePoint.set(-300.13);
    DerivedLongGauge derivedLongGauge = metricRegistry.addDerivedLongGauge(NAME_3, METRIC_OPTIONS);
    derivedLongGauge.createTimeSeries(LABEL_VALUES, null, longFunction);
    DerivedDoubleGauge derivedDoubleGauge = metricRegistry.addDerivedDoubleGauge(NAME_4, METRIC_OPTIONS);
    derivedDoubleGauge.createTimeSeries(LABEL_VALUES, null, doubleFunction);
    Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
    assertThat(metricCollections.size()).isEqualTo(4);
    assertThat(metricCollections).containsExactly(Metric.createWithOneTimeSeries(LONG_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.longValue(200), TEST_TIME), null)), Metric.createWithOneTimeSeries(DOUBLE_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.doubleValue(-300.13), TEST_TIME), null)), Metric.createWithOneTimeSeries(DERIVED_LONG_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.longValue(5), TEST_TIME), null)), Metric.createWithOneTimeSeries(DERIVED_DOUBLE_METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(ALL_VALUES, Point.create(Value.doubleValue(5.0), TEST_TIME), null)));
}
Also used : DerivedDoubleGauge(io.opencensus.metrics.DerivedDoubleGauge) DerivedLongGauge(io.opencensus.metrics.DerivedLongGauge) LongGauge(io.opencensus.metrics.LongGauge) DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) DerivedLongGauge(io.opencensus.metrics.DerivedLongGauge) DoubleGauge(io.opencensus.metrics.DoubleGauge) DerivedDoubleGauge(io.opencensus.metrics.DerivedDoubleGauge) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Aggregations

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