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

fix(pubsub): get future value before returning #13241

Merged
merged 12 commits into from
Dec 8, 2023

Conversation

alevenberg
Copy link
Member

@alevenberg alevenberg commented Dec 6, 2023

Closes #13240 and #13244

This change is Reviewable

@alevenberg alevenberg requested a review from a team as a code owner December 6, 2023 18:34
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Dec 6, 2023
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

The change looks good, but some kind of test was (and remains) missing if this made it so far.

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e7df5df) 93.04% compared to head (ebec756) 93.05%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13241      +/-   ##
==========================================
+ Coverage   93.04%   93.05%   +0.01%     
==========================================
  Files        2136     2137       +1     
  Lines      186524   186562      +38     
==========================================
+ Hits       173545   173612      +67     
+ Misses      12979    12950      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dbolduc
dbolduc previously approved these changes Dec 6, 2023
Copy link
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

Is this really a fix? @coryan would know better, but I thought we implicitly get the future in this case.

template <typename T>
inline future<T>::future(future<future<T>>&& rhs)
: future<T>(rhs.then([](future<future<T>> f) { return f.get(); })) {}

If so, this is just a cleanup.

@alevenberg
Copy link
Member Author

I'm not sure what test would cover this.... Do you have any ideas @coryan?

@coryan
Copy link
Contributor

coryan commented Dec 6, 2023

I'm not sure what test would cover this.... Do you have any ideas @coryan?

No simple ideas, just some thoughts on how to start thinking about it: do you have a way to reproduce #13240 ? Can you turn that repro into a unit test?

@alevenberg
Copy link
Member Author

#13244

coryan
coryan previously approved these changes Dec 7, 2023
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

If you prefer to merge this and then add the regression test please go ahead.

@alevenberg
Copy link
Member Author

Tested locally with: bazel test //google/cloud/pubsub/integration_tests:publisher_integration_test --test_env=GOOGLE_CLOUD_PROJECT=cloud-cpp-testing-resources --test_env=HOME=$HOME

using ::google::cloud::testing_util::DisableTracing;
using ::google::cloud::testing_util::EnableTracing;

TEST_F(PublisherIntegrationTest, TracingEnabled) {
Copy link
Member

@dbolduc dbolduc Dec 7, 2023

Choose a reason for hiding this comment

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

We should install the span catcher in these tests, and set some expectations on the results. While something like #13034 would be nice, it might take some brainpower to design. I think we should start by verifying spans that we know are created all of the time. Something like:

EXPECT_THAT(span_catcher->GetSpans(), AllOf(
    Contains(SpanNamed("publish")),
    Contains(SpanNamed("google.pubsub.v1.PublisherClient/Publish"))));

We can worry about parent/child relationships, sequence of spans, conditional spans (e.g. the backoffs) later.

Copy link
Member Author

@alevenberg alevenberg Dec 7, 2023

Choose a reason for hiding this comment

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

I don't think we want a SpanCatcher here. That's what the publisher_connection is for.

Copy link
Member

Choose a reason for hiding this comment

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

So your test verifies that if you make a client with tracing enabled and use it, the application does not crash.

Why not also verify that if you make a client with tracing enabled and use it, it produces spans?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because that's what the publisher_connection_test does. Then I would have 2 of the same tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

For an end to end test of traces generated, I think there's a better spot then here. Maybe something that creates a publisher, exports the span data to a .txt file, then diffs it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want a SpanCatcher here.

Also, if we don't set an exporter, all of the OTel functions will be no-ops. That will probably limit the coverage we are hoping to achieve from an end-to-end integration test.

Because that's what the publisher_connection_test does.

Ok, I did not realize we decorated the mock stub in those tests

SpanNamed("google.pubsub.v1.Publisher/Publish"),

Still, the production code path is slightly different from the test code path. For integration tests, we want to be using the clients and public APIs the way an application would.

For an end to end test of traces generated, I think there's a better spot then here.

Yeah, you could have a pubsub/integration_tests/publisher_tracing_test.cc that makes all different sorts of publisher clients, uses them against production / an emulator, and verifies the spans produced. I am thinking like one TEST() per client configuration.

Maybe something that creates a publisher, exports the span data to a .txt file, then diffs it.

You are going to have to explain this one to me. Why are we exporting to a .txt file, when we have access to the spans programmatically? What are we diffing the .txt file against? Are we writing the span's creation time, which would change every time we run the program?

Copy link
Member Author

@alevenberg alevenberg Dec 7, 2023

Choose a reason for hiding this comment

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

I don't think we want a SpanCatcher here.

Also, if we don't set an exporter, all of the OTel functions will be no-ops. That will probably limit the coverage we are hoping to achieve from an end-to-end integration test.

Yes that makes sense.

Because that's what the publisher_connection_test does.

Ok, I did not realize we decorated the mock stub in those tests

SpanNamed("google.pubsub.v1.Publisher/Publish"),

Still, the production code path is slightly different from the test code path. For integration tests, we want to be using the clients and public APIs the way an application would.

Is it that different? I'm not sure... Also, this is test is not using the client in any special way. I really think it has the same coverage as publisher_connection_test. At least if the only assertion we make is

EXPECT_THAT(span_catcher->GetSpans(), AllOf(
  Contains(SpanNamed("publish")),
 Contains(SpanNamed("google.pubsub.v1.PublisherClient/Publish"))));

For an end to end test of traces generated, I think there's a better spot then here.

Yeah, you could have a pubsub/integration_tests/publisher_tracing_test.cc that makes all different sorts of publisher clients, uses them against production / an emulator, and verifies the spans produced. I am thinking like one TEST() per client configuration.

This sounds like a better idea. WDYM by client configuration? Different options?

Maybe something that creates a publisher, exports the span data to a .txt file, then diffs it.

You are going to have to explain this one to me. Why are we exporting to a .txt file, when we have access to the spans programmatically? What are we diffing the .txt file against? Are we writing the span's creation time, which would change every time we run the program?

It does not need to be this. What I meant was a solution to #13034

Copy link
Member

Choose a reason for hiding this comment

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

WDYM by client configuration? Different options?

👍

What I meant was a solution to #13034

I am trying to understand the solution, but failing to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just my guess about what happens under the hood in something like https://tracetest.io/

@dbolduc dbolduc dismissed stale reviews from coryan and themself December 7, 2023 19:12

stale

if (using_emulator) {
options_ = Options{}
.set<UnifiedCredentialsOption>(MakeInsecureCredentials())
.set<internal::UseInsecureChannelOption>(true);
Copy link
Member

Choose a reason for hiding this comment

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

TIL: UseInsecureChannelOption

@alevenberg
Copy link
Member Author

I think any reviews are stale, so requested a re-review

@alevenberg alevenberg enabled auto-merge (squash) December 8, 2023 19:43
@alevenberg alevenberg merged commit 32f90f1 into googleapis:main Dec 8, 2023
59 checks passed
@alevenberg alevenberg deleted the fix-3 branch December 8, 2023 20:25
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pubsub publish with tracing not working
4 participants