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

doc(pubsub): add update topic schema and create topic with schema revisions to samples #11872

Merged
merged 4 commits into from
Jun 13, 2023

Conversation

alevenberg
Copy link
Member

@alevenberg alevenberg commented Jun 12, 2023

Fixes part of Issue #11720


This change is Reviewable

@alevenberg alevenberg requested a review from a team as a code owner June 12, 2023 20:27
@snippet-bot
Copy link

snippet-bot bot commented Jun 12, 2023

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples. labels Jun 12, 2023
create_request.mutable_schema()->set_definition(initial_definition);
auto schema = client.CreateSchema(create_request);
if (!schema) throw std::move(schema).status();
std::string const first_revision_id = schema.value().revision_id();
Copy link
Contributor

Choose a reason for hiding this comment

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

We spell these schema->revision_id(). Also, making this a const prevents move-from. Does not matter in this test, but generally it would be more efficient to write:

... ..
  auto first_revision_id = schema->value();
...
  return {std::move(first_revision_id), std::move(last_revision_id)}

If you want to save even more copying you would write:

  auto first_revision_id = std::move(*schema->mutable_revision_id());
 ..
...
  return {std::move(first_revision_id), std::move(*schema->mutable_revision_id())};

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack. For StatusOr's, use indirection instead of .value().

Changed so that we are using std::move in the return. I think the second version is overkill for the samples.

if (!schema) throw std::move(schema).status();
return first_revision_id;
std::string const last_revision_id = schema.value().revision_id();
Copy link
Contributor

Choose a reason for hiding this comment

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

See above

Copy link
Member Author

@alevenberg alevenberg Jun 12, 2023

Choose a reason for hiding this comment

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

Done

// Commit two new schema revision and return the first revision id.
std::string CommitSchemaRevisionsForRollbackSchemaTesting(
google::cloud::pubsub::SchemaServiceClient& schema_admin,
// Commit a schema with a revision and return the first and last revision id.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/revision id/revision ids/ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1197 to 1200
if (topic.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The topic already exists\n";
return;
} else if (topic.status().code() ==
Copy link
Contributor

Choose a reason for hiding this comment

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

We typically write

Suggested change
if (topic.status().code() == google::cloud::StatusCode::kAlreadyExists) {
std::cout << "The topic already exists\n";
return;
} else if (topic.status().code() ==
return;
}
if (topic.status().code() == google::cloud::StatusCode::kInvalidArgument) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack. Removed since the code is thrown says the same thing.

.set_first_revision_id(first_revision_id)
.set_last_revision_id(last_revision_id));

if (topic.status().code() == google::cloud::StatusCode::kInvalidArgument) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a multitude of reasons why we may get this error, just skip this if() I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the if

std::cout << "The topic already exists\n";
return;
} else if (topic.status().code() ==
google::cloud::StatusCode::kInvalidArgument) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure the message for kInvalidArgument is accurate, or more informative than the message in topic.status()?

Copy link
Member Author

Choose a reason for hiding this comment

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

The messages are the same if the revision ids are incorrect, but it could be something else that triggers the error.

Instead of trying to catch the error, changed to rely on throwing the error at the end

@codecov
Copy link

codecov bot commented Jun 12, 2023

Codecov Report

Patch coverage: 84.04% and project coverage change: -0.01 ⚠️

Comparison is base (f9cc920) 93.67% compared to head (1f230c4) 93.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11872      +/-   ##
==========================================
- Coverage   93.67%   93.66%   -0.01%     
==========================================
  Files        1838     1838              
  Lines      166116   166195      +79     
==========================================
+ Hits       155601   155670      +69     
- Misses      10515    10525      +10     
Impacted Files Coverage Δ
google/cloud/pubsub/samples/samples.cc 87.13% <75.80%> (-0.43%) ⬇️
...ogle/cloud/pubsub/samples/pubsub_samples_common.cc 100.00% <100.00%> (ø)
google/cloud/pubsub/topic_builder.h 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@alevenberg alevenberg merged commit dcdce3e into googleapis:main Jun 13, 2023
@alevenberg alevenberg deleted the issue-11720-c branch June 13, 2023 13:32
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. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants