Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Update OpenCensus version. #4494

Merged
merged 16 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the migration handled on the consumer side in the Census implementation? For not to break the interoperability between gRPC and Census inside Google, it seems necessary for Census to read both the old and the new measurements, giving the new ones precedence. If that's the case, we could just remove the old measurements here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, inside Google the new measurements are not completely consistent with Census Java, and only the old measurements will be read at this moment. Even for open source, users could still export and read the old measurements so I think it's important to continue recording stats for the old ones.

There are some ongoing discussion about making the new measurements consistent with Census Java. /cc @dinooliva

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The artifact providing the gRPC views has separate methods for registering the old and new views, so users can choose when to upgrade them. It might be easier for users to upgrade if they could get data for both sets of views at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to first change Census impls to convert the old measurements to the new ones, then switch gRPC to record the new measurements after all your customers have switched to the new impl and the new measurements? Then the migration of the measurements can go in line with the migration from NetworkEvent to MessageEvent (see my comment on that). Plus the gRPC code (esp. the tests) would be much cleaner if it ever has to deal with one API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I thought that we wanted users to explicitly switch to the new views, since the change isn't transparent like the switch to MessageEvent. For example, the stats may be exported to a service that uses the view or measure names.

/cc @bogdandrutu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, like @sebright said, OpenCensus users could be exporting the old RPC constants to other backends and using them for alerting rules. Since the new and old RPC constants have different names, they will be different metrics on other monitoring systems (Stackdriver, Prometheus). We would like to allow users to explicitly choose old or new RPC constants and update their monitoring accordingly, as in our APIs (registerAllGrpcViews vs registerAllViews). So I think it's import to have stats for both of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top of that, as I mentioned in the previous comments, currently it's particularly difficult to map the old RPC constants to the new ones inside Google. For example, there are no *_count measures in the new constants.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you don't have the "started count" measurements in the new constants, but it is a required metric inside Google.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed started_count, finished_count and error_count in the new specs. There are some rationale behind why error_count and finished_count gets removed, but I cannot remember why we removed started_count.

@bogdandrutu @Ramonza should we consider putting back the started_count measure since it's required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added *_started_rpcs constants to OpenCensus v0.14.0, and upgraded the version here. Now the started_rpcs are recorded. PTAL at the two latest commits.

.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