-
Notifications
You must be signed in to change notification settings - Fork 553
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
docs(pubsub): Add ingestion from GCS samples #27434
Open
michaelpri10
wants to merge
12
commits into
googleapis:main
Choose a base branch
from
michaelpri10:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−5
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a4ade7c
docs(pubsub): Add samples for ingestion from GCS
michaelpri10 7f8455e
docs(pubsub): Fixes to GCS ingestion sample and tests
michaelpri10 a1e6e4c
docs(pubsub): Fix style on GCS ingestion sample
michaelpri10 21ed486
docs(pubsub): Change bucket name for GCS ingestion sample test
michaelpri10 f36c5c3
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 58afb85
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 058f238
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 7c90e33
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 57ccdf1
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 02d9064
docs(pubsub): Trigger build for GCS ingestion samples
michaelpri10 665c28b
docs(pubsub): Change bucket name
michaelpri10 f901143
docs(pubsub): Update bucket and add comment about resource need GCS i…
michaelpri10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
require_relative "../pubsub_create_pull_subscription.rb" | ||
require_relative "../pubsub_create_push_subscription.rb" | ||
require_relative "../pubsub_create_topic.rb" | ||
require_relative "../pubsub_create_topic_with_cloud_storage_ingestion.rb" | ||
require_relative "../pubsub_dead_letter_create_subscription.rb" | ||
require_relative "../pubsub_dead_letter_delivery_attempt.rb" | ||
require_relative "../pubsub_dead_letter_remove.rb" | ||
|
@@ -40,15 +41,18 @@ | |
let(:role) { "roles/pubsub.publisher" } | ||
let(:service_account_email) { "serviceAccount:kokoro@#{pubsub.project}.iam.gserviceaccount.com" } | ||
let(:topic_id) { random_topic_id } | ||
let(:cloud_storage_ingestion_topic_id) { random_topic_id } | ||
let(:cloud_storage_bucket) { "pubsub-ruby-sample-bucket" } | ||
let(:subscription_id) { random_subscription_id } | ||
let(:dead_letter_topic_id) { random_topic_id } | ||
|
||
after do | ||
@subscription.delete if @subscription | ||
@topic.delete if @topic | ||
@cloud_storage_ingestion_topic.delete if @cloud_storage_ingestion_topic | ||
end | ||
|
||
it "supports pubsub_create_topic, pubsub_list_topics, pubsub_set_topic_policy, pubsub_get_topic_policy, pubsub_test_topic_permissions, pubsub_delete_topic" do | ||
it "supports pubsub_create_topic, pubsub_create_topic_with_cloud_storage_ingestion, pubsub_list_topics, pubsub_set_topic_policy, pubsub_get_topic_policy, pubsub_test_topic_permissions, pubsub_delete_topic" do | ||
# pubsub_create_topic | ||
assert_output "Topic projects/#{pubsub.project}/topics/#{topic_id} created.\n" do | ||
create_topic topic_id: topic_id | ||
|
@@ -57,6 +61,20 @@ | |
assert topic | ||
assert_equal "projects/#{pubsub.project}/topics/#{topic_id}", topic.name | ||
|
||
# pubsub_create_topic_with_cloud_storage_ingestion | ||
# This test requires the existence of GCS bucket gs://pubsub-ruby-sample-bucket in `pubsub.project` with the P4SA for `pubsub.project` having the "storage.admin" role on the GCS bucket. | ||
assert_output "Topic projects/#{pubsub.project}/topics/#{cloud_storage_ingestion_topic_id} with Cloud Storage ingestion settings created.\n" do | ||
create_topic_with_cloud_storage_ingestion topic_id: cloud_storage_ingestion_topic_id, | ||
bucket: cloud_storage_bucket, | ||
input_format: "text", | ||
text_delimiter: ",", | ||
match_glob: "**.txt", | ||
minimum_object_create_time: "1970-01-01T00:00:01Z" | ||
end | ||
cloud_storage_ingestion_topic = pubsub.topic cloud_storage_ingestion_topic_id | ||
assert cloud_storage_ingestion_topic | ||
assert_equal "projects/#{pubsub.project}/topics/#{cloud_storage_ingestion_topic_id}", cloud_storage_ingestion_topic.name | ||
|
||
# pubsub_list_topics | ||
out, _err = capture_io do | ||
list_topics | ||
|
@@ -196,7 +214,7 @@ | |
#setup | ||
@topic = pubsub.create_topic topic_id | ||
@dead_letter_topic = pubsub.create_topic dead_letter_topic_id | ||
|
||
begin | ||
# pubsub_dead_letter_create_subscription | ||
out, _err = capture_io do | ||
|
@@ -239,7 +257,6 @@ | |
@subscription.reload! | ||
refute @subscription.dead_letter_topic | ||
refute @subscription.dead_letter_max_delivery_attempts | ||
|
||
ensure | ||
@dead_letter_topic.delete | ||
end | ||
|
@@ -392,14 +409,14 @@ | |
|
||
# Pub/Sub calls may not respond immediately. | ||
# Wrap expectations that may require multiple attempts with this method. | ||
def expect_with_retry sample_name, attempts: 5 | ||
def expect_with_retry(sample_name, attempts: 5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to add these parens. Our style prefers omitting them. |
||
@attempt_number ||= 0 | ||
yield | ||
@attempt_number = nil | ||
rescue Minitest::Assertion => e | ||
@attempt_number += 1 | ||
puts "failed attempt #{@attempt_number} for #{sample_name}" | ||
sleep @attempt_number*@attempt_number | ||
sleep @attempt_number * @attempt_number | ||
retry if @attempt_number < attempts | ||
@attempt_number = nil | ||
raise e | ||
|
66 changes: 66 additions & 0 deletions
66
google-cloud-pubsub/samples/pubsub_create_topic_with_cloud_storage_ingestion.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2024 Google, Inc | ||
# | ||
# 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. | ||
|
||
require "google/cloud/pubsub" | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
|
||
def create_topic_with_cloud_storage_ingestion topic_id:, | ||
bucket:, | ||
input_format:, | ||
text_delimiter:, | ||
match_glob:, | ||
minimum_object_create_time: | ||
# [START pubsub_create_topic_with_cloud_storage_ingestion] | ||
# project_id = "your-project-id" | ||
# topic_id = "your-topic-id" | ||
# bucket = "your-bucket" | ||
# input_format = "text" (can be one of "text", "avro", "pubsub_avro") | ||
# text_delimiter = "\n" | ||
# match_glob = "**.txt" | ||
# minimum_object_create_time = "YYYY-MM-DDThh:mm:ssZ" | ||
|
||
pubsub = Google::Cloud::Pubsub.new | ||
cloud_storage_settings = Google::Cloud::PubSub::V1::IngestionDataSourceSettings::CloudStorage.new( | ||
bucket: bucket, | ||
match_glob: match_glob | ||
) | ||
case input_format | ||
when "text" | ||
cloud_storage_settings.text_format = | ||
Google::Cloud::PubSub::V1::IngestionDataSourceSettings::CloudStorage::TextFormat.new( | ||
delimiter: text_delimiter | ||
) | ||
when "avro" | ||
cloud_storage_settings.avro_format = | ||
Google::Cloud::PubSub::V1::IngestionDataSourceSettings::CloudStorage::AvroFormat.new | ||
when "pubsub_avro" | ||
cloud_storage_settings.pubsub_avro_format = | ||
Google::Cloud::PubSub::V1::IngestionDataSourceSettings::CloudStorage::PubSubAvroFormat.new | ||
else | ||
puts "Invalid input format: #{input_format}; must be in ('text', 'avro', 'pubsub_avro')" | ||
return | ||
end | ||
unless minimum_object_create_time.empty? | ||
cloud_storage_settings.minimum_object_create_time = Time.parse minimum_object_create_time | ||
end | ||
ingestion_data_source_settings = Google::Cloud::PubSub::V1::IngestionDataSourceSettings.new( | ||
cloud_storage: cloud_storage_settings | ||
) | ||
topic = pubsub.create_topic topic_id, ingestion_data_source_settings: ingestion_data_source_settings | ||
puts "Topic #{topic.name} with Cloud Storage ingestion settings created." | ||
# [END pubsub_create_topic_with_cloud_storage_ingestion] | ||
end | ||
|
||
# rubocop:enable Metrics/MethodLength |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where this instance variable gets set. Did you intend to set it in the test below (i.e. instead of just setting a local variable in line 74)?