Search in sources :

Example 26 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class DerivedLongCumulativeImplTest method addTimeSeries_WithNullObj.

@Test
public void addTimeSeries_WithNullObj() {
    derivedLongCumulative.createTimeSeries(LABEL_VALUES, null, longFunction);
    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(15), endTime), START_TIME)));
}
Also used : Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 27 with Timestamp

use of io.opencensus.common.Timestamp 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);
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) LabelValue(io.opencensus.metrics.LabelValue) ArrayList(java.util.ArrayList) Timestamp(io.opencensus.common.Timestamp) MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 28 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class DoubleCumulativeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    DoublePoint doublePoint = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    doublePoint.add(1);
    doublePoint.add(2);
    DoublePoint defaultPoint = doubleCumulativeMetric.getDefaultTimeSeries();
    defaultPoint.add(100);
    DoublePoint doublePoint1 = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
    doublePoint1.add(-100);
    doublePoint1.add(-20);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(3), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.doubleValue(0), endTime), START_TIME));
    Metric metric = doubleCumulativeMetric.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.DoubleCumulative.DoublePoint) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 29 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class LongCumulativeImplTest method getOrCreateTimeSeries.

@Test
public void getOrCreateTimeSeries() {
    LongPoint point = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(100);
    LongPoint point1 = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    point1.add(500);
    assertThat(point).isSameInstanceAs(point1);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    Metric metric = longCumulativeMetric.getMetric(testClock);
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(600), endTime), START_TIME)));
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 30 with Timestamp

use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.

the class LongCumulativeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    LongPoint longPoint = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    longPoint.add(1);
    longPoint.add(2);
    LongPoint defaultPoint = longCumulativeMetric.getDefaultTimeSeries();
    defaultPoint.add(100);
    LongPoint longPoint1 = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
    longPoint1.add(-100);
    longPoint1.add(-20);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), endTime), START_TIME));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(0), endTime), START_TIME));
    Metric metric = longCumulativeMetric.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.LongCumulative.LongPoint) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (io.opencensus.common.Timestamp)40 Test (org.junit.Test)29 Metric (io.opencensus.metrics.export.Metric)19 ArrayList (java.util.ArrayList)12 TimeSeries (io.opencensus.metrics.export.TimeSeries)8 SpanContext (io.opencensus.trace.SpanContext)6 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)4 LabelKey (io.opencensus.metrics.LabelKey)4 LabelValue (io.opencensus.metrics.LabelValue)4 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)4 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)4 AggregationWindowData (io.opencensus.stats.ViewData.AggregationWindowData)4 View (io.opencensus.stats.View)3 ViewData (io.opencensus.stats.ViewData)3 AttributeValue (io.opencensus.trace.AttributeValue)3 SpanId (io.opencensus.trace.SpanId)3 Status (io.opencensus.trace.Status)3 SpanData (io.opencensus.trace.export.SpanData)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 CumulativeData (io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)2