Search in sources :

Example 6 with LongPoint

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()));
            }
        }
    }
}
Also used : LabelValue(io.opencensus.metrics.LabelValue) Scope(io.opencensus.common.Scope) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) LongPoint(io.opencensus.metrics.LongGauge.LongPoint)

Example 7 with LongPoint

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());
    }
}
Also used : LongPoint(io.opencensus.metrics.LongGauge.LongPoint)

Example 8 with LongPoint

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();
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 9 with LongPoint

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);
}
Also used : LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 10 with LongPoint

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);
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Aggregations

LongPoint (io.opencensus.metrics.LongGauge.LongPoint)13 Test (org.junit.Test)11 Metric (io.opencensus.metrics.export.Metric)9 LabelKey (io.opencensus.metrics.LabelKey)3 LabelValue (io.opencensus.metrics.LabelValue)3 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)2 LongGauge (io.opencensus.metrics.LongGauge)2 TimeSeries (io.opencensus.metrics.export.TimeSeries)2 ArrayList (java.util.ArrayList)2 EqualsTester (com.google.common.testing.EqualsTester)1 Scope (io.opencensus.common.Scope)1 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)1 DoubleGauge (io.opencensus.metrics.DoubleGauge)1 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1