use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class DerivedDoubleCumulativeImplTest method addTimeSeries_IgnoreNegativeValue.
@Test
public void addTimeSeries_IgnoreNegativeValue() {
derivedDoubleCumulative.createTimeSeries(LABEL_VALUES, null, negativeDoubleFunction);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = derivedDoubleCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(0), endTime), START_TIME)));
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class DerivedDoubleCumulativeImplTest method addTimeSeries_WithNullObj.
@Test
public void addTimeSeries_WithNullObj() {
derivedDoubleCumulative.createTimeSeries(LABEL_VALUES, null, doubleFunction);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = derivedDoubleCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(5.5), endTime), START_TIME)));
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method getDefaultTimeSeries.
@Test
public void getDefaultTimeSeries() {
LongPoint point = longCumulativeMetric.getDefaultTimeSeries();
point.add(100);
LongPoint point1 = longCumulativeMetric.getDefaultTimeSeries();
point1.add(-100);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = longCumulativeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), endTime), START_TIME)));
assertThat(point).isSameInstanceAs(point1);
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest 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);
LongCumulativeImpl longCumulative = new LongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels, START_TIME);
LongPoint longPoint = longCumulative.getOrCreateTimeSeries(labelValues);
longPoint.add(1);
longPoint.add(2);
LongPoint defaultPoint = longCumulative.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_INT64, 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.longValue(100), endTime), START_TIME);
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.longValue(3), endTime), START_TIME));
expectedTimeSeriesList.add(defaultTimeSeries);
Metric metric = longCumulative.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
longCumulative.removeTimeSeries(labelValues);
Metric metric2 = longCumulative.getMetric(testClock);
assertThat(metric2).isNotNull();
assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class OcAgentNodeUtilsTest method getProcessIdentifier.
@Test
public void getProcessIdentifier() {
String jvmName = "54321@my.org";
Timestamp timestamp = Timestamp.create(10, 20);
ProcessIdentifier processIdentifier = OcAgentNodeUtils.getProcessIdentifier(jvmName, timestamp);
assertThat(processIdentifier.getHostName()).isEqualTo("my.org");
assertThat(processIdentifier.getPid()).isEqualTo(54321);
assertThat(processIdentifier.getStartTimestamp()).isEqualTo(com.google.protobuf.Timestamp.newBuilder().setSeconds(10).setNanos(20).build());
}
Aggregations