Search in sources :

Example 16 with Timestamp

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

the class DerivedLongCumulativeImplTest method createTimeSeries_WithObjFunction.

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

Example 17 with Timestamp

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

the class DoubleCumulativeImplTest method getDefaultTimeSeries.

@Test
public void getDefaultTimeSeries() {
    DoublePoint point = doubleCumulativeMetric.getDefaultTimeSeries();
    point.add(100);
    DoublePoint point1 = doubleCumulativeMetric.getDefaultTimeSeries();
    point1.add(-100);
    testClock.advanceTime(ONE_MINUTE);
    Timestamp endTime = testClock.now();
    Metric metric = doubleCumulativeMetric.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), endTime), START_TIME)));
    assertThat(point).isSameInstanceAs(point1);
}
Also used : DoublePoint(io.opencensus.metrics.DoubleCumulative.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 18 with Timestamp

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

the class DoubleCumulativeImplTest method getOrCreateTimeSeries.

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

Example 19 with Timestamp

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

the class MeasureToViewMap method getMetrics.

synchronized List<Metric> getMetrics(Clock clock, State state) {
    List<Metric> metrics = new ArrayList<Metric>();
    Timestamp now = clock.now();
    for (Entry<String, MutableViewData> entry : mutableMap.entries()) {
        Metric metric = entry.getValue().toMetric(now, state);
        if (metric != null) {
            metrics.add(metric);
        }
    }
    return metrics;
}
Also used : ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp)

Example 20 with Timestamp

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

the class MeasureToViewMap method registerView.

/**
 * Enable stats collection for the given {@link View}.
 */
synchronized void registerView(View view, Clock clock) {
    exportedViews = null;
    View existing = registeredViews.get(view.getName());
    if (existing != null) {
        if (existing.equals(view)) {
            // Ignore views that are already registered.
            return;
        } else {
            throw new IllegalArgumentException("A different view with the same name is already registered: " + existing);
        }
    }
    Measure measure = view.getMeasure();
    Measure registeredMeasure = registeredMeasures.get(measure.getName());
    if (registeredMeasure != null && !registeredMeasure.equals(measure)) {
        throw new IllegalArgumentException("A different measure with the same name is already registered: " + registeredMeasure);
    }
    registeredViews.put(view.getName(), view);
    if (registeredMeasure == null) {
        registeredMeasures.put(measure.getName(), measure);
    }
    Timestamp now = clock.now();
    mutableMap.put(view.getMeasure().getName(), MutableViewData.create(view, now));
}
Also used : Measure(io.opencensus.stats.Measure) View(io.opencensus.stats.View) Timestamp(io.opencensus.common.Timestamp)

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