Skip to content

Commit

Permalink
core: Update OpenCensus version to 0.17.0 (#4494)
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 authored and zhangkun83 committed Nov 10, 2018
1 parent 4064123 commit 09b13fe
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 150 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ subprojects {
protobufVersion = '3.5.1'
protocVersion = '3.5.1-1'
protobufNanoVersion = '3.0.0-alpha-5'
opencensusVersion = '0.12.3'
opencensusVersion = '0.17.0'

configureProtoCompilation = {
String generatedSourcePath = "${projectDir}/src/generated"
Expand Down
66 changes: 41 additions & 25 deletions core/src/main/java/io/grpc/internal/CensusStatsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import io.grpc.ServerStreamTracer;
import io.grpc.Status;
import io.grpc.StreamTracer;
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;
import io.opencensus.stats.MeasureMap;
import io.opencensus.stats.Stats;
import io.opencensus.stats.StatsRecorder;
Expand Down Expand Up @@ -325,13 +324,16 @@ static final class ClientCallTracer extends ClientStreamTracer.Factory {
boolean recordFinishedRpcs) {
this.module = module;
this.parentCtx = checkNotNull(parentCtx);
TagValue methodTag = TagValue.create(fullMethodName);
this.startCtx =
module.tagger.toBuilder(parentCtx)
.put(RpcMeasureConstants.RPC_METHOD, TagValue.create(fullMethodName)).build();
.put(DeprecatedCensusConstants.RPC_METHOD, methodTag)
.build();
this.stopwatch = module.stopwatchSupplier.get().start();
this.recordFinishedRpcs = recordFinishedRpcs;
if (recordStartedRpcs) {
module.statsRecorder.newMeasureMap().put(RpcMeasureConstants.RPC_CLIENT_STARTED_COUNT, 1)
module.statsRecorder.newMeasureMap()
.put(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT, 1)
.record(startCtx);
}
}
Expand Down Expand Up @@ -387,27 +389,31 @@ void callEnded(Status status) {
tracer = BLANK_CLIENT_TRACER;
}
MeasureMap measureMap = module.statsRecorder.newMeasureMap()
.put(RpcMeasureConstants.RPC_CLIENT_FINISHED_COUNT, 1)
// 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(RpcMeasureConstants.RPC_CLIENT_ROUNDTRIP_LATENCY, roundtripNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount)
.put(RpcMeasureConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount)
.put(RpcMeasureConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize)
.put(RpcMeasureConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize)
.put(
RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
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(
RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
tracer.inboundUncompressedSize);
if (!status.isOk()) {
measureMap.put(RpcMeasureConstants.RPC_CLIENT_ERROR_COUNT, 1);
measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1);
}
TagValue statusTag = TagValue.create(status.getCode().toString());
measureMap.record(
module
.tagger
.toBuilder(startCtx)
.put(RpcMeasureConstants.RPC_STATUS, TagValue.create(status.getCode().toString()))
.put(DeprecatedCensusConstants.RPC_STATUS, statusTag)
.build());
}
}
Expand Down Expand Up @@ -498,7 +504,8 @@ private static final class ServerTracer extends ServerStreamTracer {
this.tagger = tagger;
this.recordFinishedRpcs = recordFinishedRpcs;
if (recordStartedRpcs) {
module.statsRecorder.newMeasureMap().put(RpcMeasureConstants.RPC_SERVER_STARTED_COUNT, 1)
module.statsRecorder.newMeasureMap()
.put(DeprecatedCensusConstants.RPC_SERVER_STARTED_COUNT, 1)
.record(parentCtx);
}
}
Expand Down Expand Up @@ -587,23 +594,31 @@ public void streamClosed(Status status) {
stopwatch.stop();
long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
MeasureMap measureMap = module.statsRecorder.newMeasureMap()
.put(RpcMeasureConstants.RPC_SERVER_FINISHED_COUNT, 1)
// 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(RpcMeasureConstants.RPC_SERVER_SERVER_LATENCY, elapsedTimeNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount)
.put(RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount)
.put(RpcMeasureConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize)
.put(RpcMeasureConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize)
.put(RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES, outboundUncompressedSize)
.put(RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES, inboundUncompressedSize);
.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(RpcMeasureConstants.RPC_SERVER_ERROR_COUNT, 1);
measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1);
}
TagValue statusTag = TagValue.create(status.getCode().toString());
measureMap.record(
module
.tagger
.toBuilder(parentCtx)
.put(RpcMeasureConstants.RPC_STATUS, TagValue.create(status.getCode().toString()))
.put(DeprecatedCensusConstants.RPC_STATUS, statusTag)
.build());
}

Expand Down Expand Up @@ -632,10 +647,11 @@ public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata
if (parentCtx == null) {
parentCtx = tagger.empty();
}
TagValue methodTag = TagValue.create(fullMethodName);
parentCtx =
tagger
.toBuilder(parentCtx)
.put(RpcMeasureConstants.RPC_METHOD, TagValue.create(fullMethodName))
.put(DeprecatedCensusConstants.RPC_METHOD, methodTag)
.build();
return new ServerTracer(
CensusStatsModule.this,
Expand Down
80 changes: 80 additions & 0 deletions core/src/main/java/io/grpc/internal/DeprecatedCensusConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2018 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc.internal;

import com.google.common.annotations.VisibleForTesting;
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;
import io.opencensus.stats.Measure.MeasureDouble;
import io.opencensus.stats.Measure.MeasureLong;
import io.opencensus.tags.TagKey;

/** Holder class for the deprecated OpenCensus constants. */
@SuppressWarnings("deprecation")
@VisibleForTesting
public final class DeprecatedCensusConstants {

public static final TagKey RPC_STATUS = RpcMeasureConstants.RPC_STATUS;
public static final TagKey RPC_METHOD = RpcMeasureConstants.RPC_METHOD;

public static final MeasureLong RPC_CLIENT_ERROR_COUNT =
RpcMeasureConstants.RPC_CLIENT_ERROR_COUNT;
public static final MeasureDouble RPC_CLIENT_REQUEST_BYTES =
RpcMeasureConstants.RPC_CLIENT_REQUEST_BYTES;
public static final MeasureDouble RPC_CLIENT_RESPONSE_BYTES =
RpcMeasureConstants.RPC_CLIENT_RESPONSE_BYTES;
public static final MeasureDouble RPC_CLIENT_ROUNDTRIP_LATENCY =
RpcMeasureConstants.RPC_CLIENT_ROUNDTRIP_LATENCY;
public static final MeasureDouble RPC_CLIENT_SERVER_ELAPSED_TIME =
RpcMeasureConstants.RPC_CLIENT_SERVER_ELAPSED_TIME;
public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES =
RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES;
public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES =
RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES;
public static final MeasureLong RPC_CLIENT_STARTED_COUNT =
RpcMeasureConstants.RPC_CLIENT_STARTED_COUNT;
public static final MeasureLong RPC_CLIENT_FINISHED_COUNT =
RpcMeasureConstants.RPC_CLIENT_FINISHED_COUNT;
public static final MeasureLong RPC_CLIENT_REQUEST_COUNT =
RpcMeasureConstants.RPC_CLIENT_REQUEST_COUNT;
public static final MeasureLong RPC_CLIENT_RESPONSE_COUNT =
RpcMeasureConstants.RPC_CLIENT_RESPONSE_COUNT;

public static final MeasureLong RPC_SERVER_ERROR_COUNT =
RpcMeasureConstants.RPC_SERVER_ERROR_COUNT;
public static final MeasureDouble RPC_SERVER_REQUEST_BYTES =
RpcMeasureConstants.RPC_SERVER_REQUEST_BYTES;
public static final MeasureDouble RPC_SERVER_RESPONSE_BYTES =
RpcMeasureConstants.RPC_SERVER_RESPONSE_BYTES;
public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME =
RpcMeasureConstants.RPC_SERVER_SERVER_ELAPSED_TIME;
public static final MeasureDouble RPC_SERVER_SERVER_LATENCY =
RpcMeasureConstants.RPC_SERVER_SERVER_LATENCY;
public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES =
RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES;
public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES =
RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES;
public static final MeasureLong RPC_SERVER_STARTED_COUNT =
RpcMeasureConstants.RPC_SERVER_STARTED_COUNT;
public static final MeasureLong RPC_SERVER_FINISHED_COUNT =
RpcMeasureConstants.RPC_SERVER_FINISHED_COUNT;
public static final MeasureLong RPC_SERVER_REQUEST_COUNT =
RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT;
public static final MeasureLong RPC_SERVER_RESPONSE_COUNT =
RpcMeasureConstants.RPC_SERVER_RESPONSE_COUNT;

private DeprecatedCensusConstants() {}
}
Loading

0 comments on commit 09b13fe

Please sign in to comment.