use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class OcAgentExportersQuickStart method doWork.
private static void doWork(int iteration, int jobs, LongGauge gauge) {
String childSpanName = "iteration-" + iteration;
LabelValue value = LabelValue.create(childSpanName);
LongPoint point = gauge.getOrCreateTimeSeries(Collections.singletonList(value));
try (Scope scope = tracer.spanBuilder(childSpanName).startScopedSpan()) {
for (int i = 0; i < jobs; i++) {
String grandChildSpanName = childSpanName + "-job-" + i;
try (Scope childScope = tracer.spanBuilder(grandChildSpanName).startScopedSpan()) {
point.set(jobs - i);
String line = generateRandom(random.nextInt(128));
processLine(line);
recordStat(M_LINES_IN, 1L);
recordStat(M_LINE_LENGTHS, (long) line.length());
} catch (Exception e) {
tracer.getCurrentSpan().setStatus(Status.INTERNAL.withDescription(e.toString()));
}
}
}
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsExporterIntegrationTest method doWork.
private static void doWork(int jobs, LongPoint point) {
for (int i = 0; i < jobs; i++) {
point.set(jobs - i);
String line = generateRandom(random.nextInt(128));
processLine(line);
recordStat(M_LINES_IN, 1L);
recordStat(M_LINE_LENGTHS, (long) line.length());
}
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method getOrCreateTimeSeries_WithNegativePointValues.
@Test
public void getOrCreateTimeSeries_WithNegativePointValues() {
LongPoint point = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point.add(-100);
point.add(-33);
Metric metric = longGaugeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(-133));
assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getTimestamp()).isEqualTo(TEST_TIME);
assertThat(metric.getTimeSeriesList().get(0).getStartTimestamp()).isNull();
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method setDefaultLabelValues.
@Test
public void setDefaultLabelValues() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
LongPoint defaultPoint = longGauge.getDefaultTimeSeries();
defaultPoint.set(-230);
Metric metric = longGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(0)).isEqualTo(UNSET_VALUE);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(1)).isEqualTo(UNSET_VALUE);
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method getDefaultTimeSeries.
@Test
public void getDefaultTimeSeries() {
LongPoint point = longGaugeMetric.getDefaultTimeSeries();
point.add(100);
point.set(500);
LongPoint point1 = longGaugeMetric.getDefaultTimeSeries();
point1.add(-100);
Metric metric = longGaugeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(400), TEST_TIME), null)));
assertThat(point).isSameInstanceAs(point1);
}
Aggregations