io.opencensus.stats.MeasureMap Java Examples

The following examples show how to use io.opencensus.stats.MeasureMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatsRecorderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void record_MapDeprecatedRpcConstants() {
  View view =
      View.create(
          VIEW_NAME,
          "description",
          MEASURE_DOUBLE,
          Sum.create(),
          Arrays.asList(RecordUtils.RPC_METHOD));

  viewManager.registerView(view);
  MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
  statsRecord.record(new SimpleTagContext(Tag.create(RecordUtils.GRPC_CLIENT_METHOD, VALUE)));
  ViewData viewData = viewManager.getView(VIEW_NAME);

  // There should be two entries.
  StatsTestUtil.assertAggregationMapEquals(
      viewData.getAggregationMap(),
      ImmutableMap.of(
          Arrays.asList(VALUE),
          StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)),
      1e-6);
}
 
Example #2
Source File: StatsRecorderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void recordTwice() {
  View view =
      View.create(
          VIEW_NAME,
          "description",
          MEASURE_DOUBLE,
          Sum.create(),
          Arrays.asList(KEY),
          Cumulative.create());
  viewManager.registerView(view);
  MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
  statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE)));
  statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE_2)));
  ViewData viewData = viewManager.getView(VIEW_NAME);

  // There should be two entries.
  StatsTestUtil.assertAggregationMapEquals(
      viewData.getAggregationMap(),
      ImmutableMap.of(
          Arrays.asList(VALUE),
          StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0),
          Arrays.asList(VALUE_2),
          StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)),
      1e-6);
}
 
Example #3
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double distribution measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleDistribution(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example #4
Source File: ViewManagerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap putToMeasureMap(MeasureMap measureMap, Measure measure, double value) {
  if (measure instanceof MeasureDouble) {
    return measureMap.put((MeasureDouble) measure, value);
  } else if (measure instanceof MeasureLong) {
    return measureMap.put((MeasureLong) measure, Math.round(value));
  } else {
    // Future measures.
    throw new AssertionError();
  }
}
 
Example #5
Source File: ViewManagerImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private void testMultipleViews_DifferentMeasures(
    Measure measure1, Measure measure2, double value1, double value2) {
  final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY));
  final View view2 =
      createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY));
  clock.setTime(Timestamp.create(1, 0));
  viewManager.registerView(view1);
  clock.setTime(Timestamp.create(2, 0));
  viewManager.registerView(view2);
  TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
  MeasureMap measureMap = statsRecorder.newMeasureMap();
  putToMeasureMap(measureMap, measure1, value1);
  putToMeasureMap(measureMap, measure2, value2);
  measureMap.record(tags);
  clock.setTime(Timestamp.create(3, 0));
  ViewData viewData1 = viewManager.getView(VIEW_NAME);
  clock.setTime(Timestamp.create(4, 0));
  ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
  assertThat(viewData1.getWindowData())
      .isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
  StatsTestUtil.assertAggregationMapEquals(
      viewData1.getAggregationMap(),
      ImmutableMap.of(
          Arrays.asList(VALUE),
          StatsTestUtil.createAggregationData(DISTRIBUTION, measure1, value1)),
      EPSILON);
  assertThat(viewData2.getWindowData())
      .isEqualTo(CumulativeData.create(Timestamp.create(2, 0), Timestamp.create(4, 0)));
  StatsTestUtil.assertAggregationMapEquals(
      viewData2.getAggregationMap(),
      ImmutableMap.of(
          Arrays.asList(VALUE),
          StatsTestUtil.createAggregationData(DISTRIBUTION, measure2, value2)),
      EPSILON);
}
 
Example #6
Source File: RecordDifferentTagValuesBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureLong measure, int value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value);
  for (TagContext tags : data.contexts) {
    map.record(tags);
  }
  return map;
}
 
Example #7
Source File: RecordDifferentTagValuesBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureDouble measure, double value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value);
  for (TagContext tags : data.contexts) {
    map.record(tags);
  }
  return map;
}
 
Example #8
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long last value measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongLastValue(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_LASTVALUE_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example #9
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double last value measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleLastValue(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_LASTVALUE_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example #10
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched ling distribution measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongDistribution(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_DISTRIBUTION_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example #11
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long sum measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongSum(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_SUM_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example #12
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double sum measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleSum(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_SUM_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example #13
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched long count measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedLongCount(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.LONG_COUNT_MEASURES[i], i);
  }
  map.record(data.tags);
  return map;
}
 
Example #14
Source File: RecordBatchedBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Record batched double count measures. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordBatchedDoubleCount(Data data) {
  MeasureMap map = data.recorder.newMeasureMap();
  for (int i = 0; i < data.numValues; i++) {
    map.put(StatsBenchmarksUtil.DOUBLE_COUNT_MEASURES[i], (double) i);
  }
  map.record(data.tags);
  return map;
}
 
Example #15
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
private void recordRealTimeMetric(TagContext ctx, MeasureDouble measure, double value) {
  if (recordRealTimeMetrics) {
    MeasureMap measureMap = statsRecorder.newMeasureMap().put(measure, value);
    measureMap.record(ctx);
  }
}
 
Example #16
Source File: MeasureMapImpl.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap putAttachment(String key, AttachmentValue value) {
  builder.putAttachment(key, value);
  return this;
}
 
Example #17
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureDouble measure, double value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value).record(data.tagContext);
  return map;
}
 
Example #18
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
private static MeasureMap record(Data data, Measure.MeasureLong measure, int value) {
  MeasureMap map = data.recorder.newMeasureMap();
  map.put(measure, value).record(data.tagContext);
  return map;
}
 
Example #19
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordLongLastValue(Data data) {
  return record(data, StatsBenchmarksUtil.LONG_LASTVALUE_MEASURES[0], 11);
}
 
Example #20
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordDoubleLastValue(Data data) {
  return record(data, StatsBenchmarksUtil.DOUBLE_LASTVALUE_MEASURES[0], (double) 11);
}
 
Example #21
Source File: ExemplarUtilsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap putAttachment(String key, AttachmentValue value) {
  attachments.put(key, value);
  return this;
}
 
Example #22
Source File: ExemplarUtilsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap put(MeasureDouble measure, double value) {
  return this;
}
 
Example #23
Source File: ExemplarUtilsTest.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap put(MeasureLong measure, long value) {
  return this;
}
 
Example #24
Source File: RecordMultipleViewsBenchmark.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public MeasureMap recordLongCount(Data data) {
  return record(data, StatsBenchmarksUtil.LONG_COUNT_MEASURES[0], 11);
}
 
Example #25
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
private void recordRealTimeMetric(TagContext ctx, MeasureLong measure, long value) {
  if (recordRealTimeMetrics) {
    MeasureMap measureMap = statsRecorder.newMeasureMap().put(measure, value);
    measureMap.record(ctx);
  }
}
 
Example #26
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished call and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
void callEnded(Status status) {
  if (callEndedUpdater != null) {
    if (callEndedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (callEnded != 0) {
      return;
    }
    callEnded = 1;
  }
  if (!module.recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  ClientTracer tracer = streamTracer;
  if (tracer == null) {
    tracer = new ClientTracer(module, startCtx);
  }
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY,
          roundtripNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
          tracer.outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
          tracer.inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(startCtx)
          .putLocal(RpcMeasureConstants.GRPC_CLIENT_STATUS, statusTag)
          .build());
}
 
Example #27
Source File: CensusStatsModule.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Record a finished stream and mark the current time as the end time.
 *
 * <p>Can be called from any thread without synchronization.  Calling it the second time or more
 * is a no-op.
 */
@Override
public void streamClosed(Status status) {
  if (streamClosedUpdater != null) {
    if (streamClosedUpdater.getAndSet(this, 1) != 0) {
      return;
    }
  } else {
    if (streamClosed != 0) {
      return;
    }
    streamClosed = 1;
  }
  if (!module.recordFinishedRpcs) {
    return;
  }
  stopwatch.stop();
  long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
  MeasureMap measureMap = module.statsRecorder.newMeasureMap()
      // TODO(songya): remove the deprecated measure constants once they are completed removed.
      .put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1)
      // The latency is double value
      .put(
          DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY,
          elapsedTimeNanos / NANOS_PER_MILLI)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount)
      .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize)
      .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES,
          outboundUncompressedSize)
      .put(
          DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES,
          inboundUncompressedSize);
  if (!status.isOk()) {
    measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1);
  }
  TagValue statusTag = TagValue.create(status.getCode().toString());
  measureMap.record(
      module
          .tagger
          .toBuilder(parentCtx)
          .putLocal(RpcMeasureConstants.GRPC_SERVER_STATUS, statusTag)
          .build());
}
 
Example #28
Source File: StatsTestUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap newMeasureMap() {
  return new FakeStatsRecord(this);
}
 
Example #29
Source File: StatsTestUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap put(Measure.MeasureDouble measure, double value) {
  metrics.put(measure, value);
  return this;
}
 
Example #30
Source File: StatsTestUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public MeasureMap put(Measure.MeasureLong measure, long value) {
  metrics.put(measure, value);
  return this;
}