Skip to content

Conversation

@dinooliva
Copy link

Adds OpenCensus context propagation to the CPS Publisher and Subscriber. This pr is initially meant for discussion between OpenCensus and CPS.

@dinooliva dinooliva requested a review from a team as a code owner December 18, 2018 20:16
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 18, 2018
@chingor13 chingor13 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 19, 2018
@sduskis
Copy link
Contributor

sduskis commented Jan 10, 2019

@dinooliva, did @igorbernstein2 reach out to you yet about his work in GAX? That work should supersede this PR.

@igorbernstein2
Copy link

we are in touch

Copy link
Contributor

@sduskis sduskis left a comment

Choose a reason for hiding this comment

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

Please add a some unit tests for this

<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
<version>${opencensus.version}</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

This version should be inherited from google-cloud-clients

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs to be changed. Please remove <version>${opencensus.version}</version>

Copy link
Author

Choose a reason for hiding this comment

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

Seems this dependency is inherited from google-cloud-clients so I can remove it altogether.

.spanBuilderWithExplicitParent(name, tracer.getCurrentSpan())
.setRecordEvents(true)
// TODO(dpo): set to default.
.setSampler(Samplers.alwaysSample())
Copy link
Contributor

Choose a reason for hiding this comment

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

@dinooliva, does this need to be fixed before merging?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, as per the TODO() - done now.

</parent>
<properties>
<site.installationModule>google-cloud-pubsub</site.installationModule>
<opencensus.version>0.15.1</opencensus.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this variable.

Copy link
Author

Choose a reason for hiding this comment

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

I've moved the variable to google-cloud-clients.

@sduskis sduskis added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 25, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 25, 2019
String encodedSpanContext = message.getAttributesOrDefault(TRACE_CONTEXT_KEY, "");
try (
Scope spanScope = createScopedSpan("receiver");
Scope statsScope = createScopedTagContext(encodedTagContext)) {

Choose a reason for hiding this comment

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

Shouldn't the creation of the span be conditional on the attributes being present?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@MustBeClosed
private static Scope createScopedSpan(String name) {
return tracer
.spanBuilderWithExplicitParent(name, tracer.getCurrentSpan())
Copy link

@igorbernstein2 igorbernstein2 Jan 25, 2019

Choose a reason for hiding this comment

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

What would be the current span on the receiver side? Shouldn't it start a new root span? Also, shouldn't recordEvents setting be copied from the publisher's span config?

Copy link
Author

Choose a reason for hiding this comment

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

On the receiver side, we create a root span and set the publisher's span as a parent link.

String encodedTagContext = message.getAttributesOrDefault(TAG_CONTEXT_KEY, "");
String encodedSpanContext = message.getAttributesOrDefault(TRACE_CONTEXT_KEY, "");
try (
Scope spanScope = createScopedSpan("receiver");

Choose a reason for hiding this comment

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

If I'm not mistaken, there is a good probability that this will be a top level span. Since this is a continuation of the publisher span, maybe it should be prefixed with the publisher span's name?

Copy link
Author

Choose a reason for hiding this comment

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

We don't transfer the Publisher's span name over the wire so it's not available. The link contains the Publisher's trace and span id's so users can find them through that.

throw new IllegalStateException("Cannot publish on a shut-down publisher.");
}

PubsubMessage message = OpenCensusUtil.putOpenCensusAttributes(originalMessage);

Choose a reason for hiding this comment

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

Is there any way to hook into OpenCensus' sampling logic here and avoid increasing request size if the span will not be published?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@dinooliva dinooliva changed the title DO NOT MERGE: OpenCensus Support for Cloud Pub/Sub OpenCensus Support for Cloud Pub/Sub Feb 5, 2019
@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Feb 7, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Feb 7, 2019
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
<version>${opencensus.version}</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs to be changed. Please remove <version>${opencensus.version}</version>

@@ -0,0 +1,193 @@
/* Copyright 2018 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/2018/2019

Copy link
Author

Choose a reason for hiding this comment

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

Done.

import java.util.logging.Level;
import java.util.logging.Logger;

final class OpenCensusUtil {
Copy link
Contributor

Choose a reason for hiding this comment

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

class comments are need

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Are class comments necessary even though the class isn't public?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will we have to make this class public in the new scheme?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, done.

<!-- test dependency versions -->
<easymock.version>3.4</easymock.version>
<objenesis.version>2.6</objenesis.version>
<opencensus.version>0.16.0</opencensus.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already an <opencensus.version> above. Please remove this duplicate entry.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

private static final Tracer tracer = Tracing.getTracer();

// Used in Publisher.
// TODO: consider adding configuration support to control adding these attributes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need the configuration control before merging this. This should be off by default, I would think.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, that makes sense - do you have any links to how configuration is handled in the Google Cloud Java client libraries?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know offhand. I'm just concerned that this will change user behavior without user selecting to turn this on.

Copy link
Author

Choose a reason for hiding this comment

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

The library only has a dependency on the OpenCensus API library, which means this code is a no-op. To enable propagation, an application will need to explicitly add a dependency on an OpenCensus Impl library. This is how configuration is done for other Java cloud client libraries (e.g. cloud bigtable and spanner).

}

@Override
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need configuration here as well, so that the user can define whether or not they want this?

Copy link
Author

Choose a reason for hiding this comment

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

I think that makes sense too.

@sduskis sduskis added status: blocked Resolving the issue is dependent on other work. kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed 🚨 This issue needs some love. labels Feb 11, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 12, 2019
private static final Tracer tracer = Tracing.getTracer();

// Used in Publisher.
// TODO: consider adding configuration support to control adding these attributes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know offhand. I'm just concerned that this will change user behavior without user selecting to turn this on.

}
return "traceid=" + traceId.toLowerBase16()
+ "&spanid=" + spanId.toLowerBase16()
+ "&traceopt=" + (traceOpts.isSampled() ? "t&" : "f&");
Copy link
Contributor

Choose a reason for hiding this comment

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

should this line now be "&traceopt=f&"?

Copy link
Author

Choose a reason for hiding this comment

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

I've changed the text encoding of span to use our standard TraceContext text format.

@codecov
Copy link

codecov bot commented Feb 14, 2019

Codecov Report

Merging #4240 into master will increase coverage by 0.47%.
The diff coverage is 70.42%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4240      +/-   ##
============================================
+ Coverage     49.19%   49.66%   +0.47%     
- Complexity    21958    22705     +747     
============================================
  Files          2076     2158      +82     
  Lines        207416   213518    +6102     
  Branches      24111    24206      +95     
============================================
+ Hits         102033   106043    +4010     
- Misses        97207    99182    +1975     
- Partials       8176     8293     +117
Impacted Files Coverage Δ Complexity Δ
...ain/java/com/google/cloud/pubsub/v1/Publisher.java 80.97% <62.5%> (-0.68%) 26 <0> (ø)
...ava/com/google/cloud/pubsub/v1/OpenCensusUtil.java 71.42% <71.42%> (ø) 5 <5> (?)
...mpute/v1/stub/HttpJsonDiskTypeCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...ute/v1/stub/HttpJsonAutoscalerCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...b/HttpJsonInstanceGroupManagerCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...HttpJsonInterconnectAttachmentCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...compute/v1/stub/HttpJsonRegionCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...1/stub/HttpJsonRegionOperationCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...b/HttpJsonRegionBackendServiceCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
...compute/v1/stub/HttpJsonUrlMapCallableFactory.java 60% <0%> (-15%) 3% <0%> (ø)
... and 268 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ef0c0e...b2a41f3. Read the comment docs.

@sduskis sduskis requested a review from kolea2 February 14, 2019 23:34
@dinooliva
Copy link
Author

Note: I developed the design of the OpenCensus Pub/Sub integration in conjunction with the Cloud Pub/Sub team.

Also, as previously noted, similar to Google Cloud Bigtable and Spanner (and other libraries e.g. gRPC), this feature is inactive unless a dependency on an OpenCensus implementation is added to the application.

@sduskis sduskis added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 28, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 28, 2019
<artifactId>grpc-google-iam-v1</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to add opencensus-impl here?

Choose a reason for hiding this comment

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

We should not, only the final app should do this.

Copy link
Author

Choose a reason for hiding this comment

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

These are the test dependencies rather than the library dependencies. I use the implementation to test OpenCensusUtil.

</parent>
<properties>
<site.installationModule>google-cloud-pubsub</site.installationModule>
<opencensus.version>0.15.1</opencensus.version>

This comment was marked as spam.

<artifactId>grpc-google-iam-v1</artifactId>
<scope>test</scope>
</dependency>
<dependency>

Choose a reason for hiding this comment

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

We should not, only the final app should do this.

import java.util.logging.Level;
import java.util.logging.Logger;

final class OpenCensusUtil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we have to make this class public in the new scheme?

private static final TagContextBinarySerializer serializer =
Tags.getTagPropagationComponent().getBinarySerializer();

private static final TraceOptions SAMPLED = TraceOptions.builder().setIsSampled(true).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

SAMPLED isn't used anymore. Please remove it.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@sduskis sduskis added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 18, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 18, 2019
@sduskis sduskis added api: pubsub Issues related to the Pub/Sub API. kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. status: blocked Resolving the issue is dependent on other work. labels Mar 19, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 19, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 19, 2019
@sduskis sduskis added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 20, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 20, 2019
@sduskis sduskis merged commit e3e812b into googleapis:master Mar 20, 2019
@dinooliva
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants