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)));
}
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);
}
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)));
}
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;
}
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));
}
Aggregations