googlecloudplatform / ruby-docs-samples Goto Github PK
View Code? Open in Web Editor NEWRuby samples for Google Cloud Platform products.
Home Page: https://cloud.google.com/ruby
License: Apache License 2.0
Ruby samples for Google Cloud Platform products.
Home Page: https://cloud.google.com/ruby
License: Apache License 2.0
The default RuboCop configuration does not match many of the styles used here in these samples.
The styles for code sample snippets varies greatly from that of production Ruby applications, eg. the goal of samples is clarity and we often do non-traditional things such as putting require
statements into method definitions for the purpose of defining a snippet.
Add a RuboCop configuration and run via Travis that enforces some desired / common stylistic mistakes, eg. trailing whitespace or the use of the and
, or
, or then
keywords
See also: How to disable all cops except some
Story: I'm a Rubyist that wants to contribute.
Issue:
Possible Solution: Insert the Ruby Style Guide
Update to:
There are many ways to encode files e.g., LINEAR16, Mulaw and then there are different file formats that encapsulate them e.g., RAW and WAV.
Both RAW and WAV can encapsulate both LINEAR16 and Mulaw.
For our server - we don't need to know the file format - we only need to know the encoding e.g., using the term RAW to specify an encoding is an error.
See feature on google-cloud-bigquery: googleapis/google-cloud-ruby#911
Documentation: https://cloud.google.com/bigquery/docs/managing_jobs_datasets_projects#projects
appengine/endpoints
appengine/cloudsql
The app.yaml
configuration file uses vm: true
, which is deprecated. Also, the memcache service is currently not available for the App Engine flexible environment according to this.
I'm not sure what the correct sending rate is given a sample size of 44100Hz with 16bit rate. I was informed to send 88200 bytes per second, and I also tried brute forcing different values. The error message doesn't help and additional information in the error message would be helpful. Such as, how to better calibrate the transmission rate given a sample rate and encoding. I want to note that I used the data in audio.grpc.content
as the payload.
Any help would be appreciated! Thank you.
Error:
11:Audio data is being streamed too fast. Please stream audio data approximately at real time.
Code:
require 'google/cloud/speech'
# Stream to speech and wait for transcription...
speech = Google::Cloud::Speech.new
# Setup raw file to be sent in as an Asynchronous job maximum time is ~80mins
audio = speech.audio "prince.raw",
encoding: :raw, sample_rate: 44100,
language: :ja
# Send stream job
stream = speech.stream encoding: :raw, sample_rate: 44100, language: 'ja'
# Result callback
stream.on_result do |results|
result = results.first
puts result.transcript
end
# Error callback
stream.on_error do |error|
puts error
end
# Start callback
stream.on_speech_start do
puts "Started listening"
end
# Complete callback
stream.on_complete do
puts "Finished"
end
bytes_sent = 0
chunk_size = 88200
bytes_total = audio.grpc.content.size # Content of my raw file (This may be wrong)..
# Send one chunk per second
while bytes_sent < bytes_total do
stream.send audio.grpc.content[bytes_sent, (bytes_sent + chunk_size)]
bytes_sent += chunk_size
sleep 1
end
# Finished sending
stream.complete!
# Stop stream
stream.stop
I'm trying to get the Appengine Datastore sample to work.
$ export GOOGLE_CLOUD_PROJECT=myproject
$ bundle
$ bundle exec ruby ./app.rb
/var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/v1/datastore_api.rb:28:in require': cannot load such file -- google/gax (LoadError) from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/v1/datastore_api.rb:28:in
<top (required)>'
from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/v1.rb:16:in require' from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/v1.rb:16:in
<top (required)>'
from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/service.rb:19:in require' from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/service.rb:19:in
<top (required)>'
from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/dataset.rb:19:in require' from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore/dataset.rb:19:in
<top (required)>'
from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore.rb:18:in require' from /var/lib/gems/2.3.0/gems/google-cloud-datastore-0.21.0/lib/google/cloud/datastore.rb:18:in
<top (required)>'
from ./app.rb:18:in require' from ./app.rb:18:in
$ cat Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.0)
public_suffix (> 2.0, >= 2.0.2)> 0.21.0)
diff-lcs (1.2.5)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
google-cloud-core (0.21.0)
google-cloud-datastore (0.21.0)
google-cloud-core (
google-gax (> 0.6.0)> 3.0)
google-protobuf (
googleapis-common-protos (> 1.3)> 1.0)
grpc (
google-gax (0.6.0)
googleapis-common-protos (> 1.3.1)> 0.5.1)
googleauth (
grpc (> 1.0)> 0.2.3)
rly (
google-protobuf (3.0.2)
googleapis-common-protos (1.3.4)
google-protobuf (> 3.0)> 1.0)
grpc (
googleauth (0.5.1)
faraday (> 0.9)> 1.4)
jwt (
logging (> 2.0)> 0.12)
memoist (
multi_json (> 1.11)> 0.9)
os (
signet (> 0.7)> 3.0.2)
grpc (1.0.1)
google-protobuf (
googleauth (> 0.5.1)> 1.1)
jwt (1.5.6)
little-plugger (1.1.4)
logging (2.1.0)
little-plugger (
multi_json (> 1.10)> 3.5.0)
memoist (0.15.0)
multi_json (1.12.1)
multipart-post (2.0.0)
os (0.9.6)
public_suffix (2.0.4)
rack (1.6.4)
rack-protection (1.5.3)
rack
rly (0.2.3)
rspec (3.5.0)
rspec-core (
rspec-expectations (> 3.5.0)> 3.5.0)
rspec-mocks (
rspec-core (3.5.4)
rspec-support (> 3.5.0)> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (> 3.5.0)> 2.3)
rspec-support (3.5.0)
signet (0.7.3)
addressable (
faraday (> 0.9)> 1.5)
jwt (
multi_json (> 1.10)> 1.5)
sinatra (1.4.7)
rack (
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.5)
PLATFORMS
ruby
DEPENDENCIES
google-cloud-datastore
rspec
sinatra
BUNDLED WITH
1.13.4
Possible reason
A resource race-condition, running more than one instance of ruby-docs-samples tests will cause an error related to a resource being in use.
Storage and Datastore
Storage-Example-1
Storage-Example-2
Datastore-and-Storage-Example
The following in openapi.yaml
does not have effect anymore:
# This section requires all requests to any path to require an API key.
security:
- api_key: []
Instead it needs to be moved under the method (like in the python sample):
paths:
"/echo":
post:
description: "Echo back a given message."
operationId: "echo"
produces:
- "application/json"
responses:
200:
description: "Echo"
schema:
$ref: "#/definitions/echoMessage"
parameters:
- description: "Message to echo"
in: body
name: message
required: true
schema:
$ref: "#/definitions/echoMessage"
security:
- api_key: []
see endpoints docs for more info.
Dialogflow tests run into quota problems fairly frequently. Let's add some retry logic before increasing the quota.
See failed Travis storage build:
https://travis-ci.org/GoogleCloudPlatform/ruby-docs-samples/jobs/163856203
The bucket being used for tests here appears to also be configured to store access logs. Determine the cause.
Look into bucket (and project) isolation for test suites. Note that tests currently run in parallel on Travis.
The sample for creating a table shown here is the "Creating an empty table with a schema definition" section, but the sample does not have a schema specified.
To fix this:
List of tests to add
This one needs CORS headers.
See sample implementation here:
https://github.com/GoogleCloudPlatform/golang-samples/blob/master/docs/managed_vms/endpoints/app.go
and copy the new swagger file:
https://github.com/GoogleCloudPlatform/golang-samples/blob/master/docs/managed_vms/endpoints/swagger.yaml
Story
When a developer wants to run RSPEC tests locally, they need to run each sample RSPEC independently.
Issue
The developer needs to test each RSPEC by hand. There is no Rakefile with a task to call sub RSPEC automatically.
Possible-Solution
Add a Rakefile with a task to run all sample RSPEC. A developer can run tests with one CLI command instead of one per sample.
Add simplest possible Ruby on Rails application that successfully deploys to the Ruby runtime for Google App Engine flexible environment
This application will support documentation.
Application should include a few additions that demonstrate the App Engine flex runtime, eg.
config.public_file_server.enabled
to true via RAILS_SERVE_STATIC_FILES
secret_key_base
configuration, eg. via SECRET_KEY_BASE
in app.yaml or some other meansrails scaffold post title body:text
using Cloud SQL (extremely common Rails use-case :: database configuration can be replaced with any SQL database that the the user desires)The README for this application should include all of the commands taken to create this application, beginning with rails new
. Most of this information will be provided via documentation, which should be linked to from the README, but this application README should demonstrate the very few commands necessary to gcloud app deploy
an application generated via rails new
on the latest verion of Ruby on Rails
Tests should verify CRUD actions work on the deployed application
Possible directory location: rails/getting_started
or ruby_on_rails/getting_started
. When developers find this repository, I'd like "Ruby on Rails" to be immediately noticeable in the directories and READMEs. The ruby_on_rails
directory should have a README directing users to our Rails documentation and Google App Engine flexible environment documentation for Ruby
Story
Rubyist knows to use Google Data Store API. Rubyist wants to learn Google Vision API and the samples use different Google Cloud API Client initialization. Confusion begins.
Issue
Initialization is inconsistent between these two samples. The issue may exist in other samples within the Ruby space.
DataStore uses
require "gcloud"
gcloud = Gcloud.new
datastore = gcloud.datastore
Vision uses
require "google/cloud"
gcloud = Google::Cloud.new
vision = gcloud.vision
Issue exists in the following locations:
appengine/datastore/app.rb
appengine/pubsub/app.rb
appengine/pubsub/spec/pubsub_spec.rb
bigquery/shakespeare.rb
datastore/sample.rb
logging/spec/sample_spec.rb
logging/sample.rb
pubsub/sample.rb
Possible Solution
Use the same initialization in all Ruby samples.
TODO list specific samples
Story
When following README.md in Datastore sample, an issue exists under Creating Datastore Indexes. The CLI command gcloud components update app prints out a WARNING that the component APP no longer exists.
Issue
[app] component no longer exists and the README.md needs to be updated.
Possible Solution
Update README.md to have gcloud components update instead.
We have updated several of our libraries to a new version: https://github.com/GoogleCloudPlatform/google-cloud-ruby/releases
Especially important is that BigQuery, Storage, Datastore, and Logging are now at Beta.
We should update all our samples to test against the latest library for each of these APIs.
(and we can update the other samples for all other APIs to use the latest library as well).
A few failures I can see:
https://circleci.com/gh/GoogleCloudPlatform/ruby-docs-samples/1182
Google Analytics on Google App Engine
can track visit event (PENDING: End-to-end tests skipped)
Pending: (Failures listed here are expected and do not affect your suite's status)
1) Google Analytics on Google App Engine can track visit event
# End-to-end tests skipped
# ./spec/google_analytics_spec.rb:29
Finished in 0.0007 seconds (files took 0.44262 seconds to load)
1 example, 0 failures, 1 pending
> gcloud app versions delete -analytics-1182 -q
ERROR: (gcloud.app.versions.delete) unrecognized arguments: -analytics-1182
Usage: gcloud app versions delete VERSIONS [VERSIONS ...] [optional flags]
optional flags may be --help | --service
For detailed information on this command and its flags, run:
gcloud app versions delete --help
Failed to delete e2e version
Failures:
1) Cat Friends should display a list of cats
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/assets/application-63d002b4806ba81b3fd0ee343c8d37f5160ede65d821329ab2ce721f09280c3a.css"
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/railties-5.1.3/lib/rails/rack/logger.rb:36:in `call_app'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `block in call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/railties-5.1.3/lib/rails/engine.rb:522:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/capybara-2.15.1/lib/capybara/server.rb:44:in `call'
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/handler/webrick.rb:86:in `service'
# ------------------
# --- Caused by: ---
# Capybara::CapybaraError:
# Your application server raised an error - It has been raised in your test code because Capybara.raise_server_errors == true
# /opt/circleci/.rvm/gems/ruby-2.3.4/gems/capybara-2.15.1/lib/capybara/session.rb:145:in `raise_server_error!'
Failures:
1) Google Cloud Spanner API samples create_database
Failure/Error:
create_database project_id: @project_id,
instance_id: @instance.instance_id,
database_id: @database_id
Google::Cloud::ResourceExhaustedError:
8:Unable to create database 'test_database_1512163400' because the instance 'projects/cloud-samples-tests-ruby/instances/cloud-samples-tests-instance' has already reached the maximum database limit (100). Please delete a database in the instance and try again, or choose a different instance.
Failures:
1) Detect Faces detect faces from local image file
Failure/Error:
expect {
detect_faces project_id: @project_id,
image_path: image_path("face_no_surprise.jpg")
}.to output(
/Surprise: false/
).to_stdout
expected block to output /Surprise: false/ to stdout, but output "Joy: true\nAnger: true\nSorrow: false\nSurprise: true\n"
Diff:
@@ -1,2 +1,5 @@
-/Surprise: false/
+Joy: true
+Anger: true
+Sorrow: false
+Surprise: true
# ./spec/detect_faces_spec.rb:34:in `block (2 levels) in <top (required)>'
2) Detect Faces detect faces from image file in Google Cloud Storage
Failure/Error:
expect {
detect_faces_gcs project_id: @project_id,
image_path: storage_file.to_gs_url
}.to output(
/Surprise: false/
).to_stdout
expected block to output /Surprise: false/ to stdout, but output "Joy: true\nAnger: true\nSorrow: false\nSurprise: true\n"
Diff:
@@ -1,2 +1,5 @@
-/Surprise: false/
+Joy: true
+Anger: true
+Sorrow: false
+Surprise: true
# ./spec/detect_faces_spec.rb:46:in `block (2 levels) in <top (required)>'
Finished in 30.42 seconds (files took 0.56411 seconds to load)
22 examples, 2 failures
Failures:
1) Datastore sample supports inequality_range
Failure/Error: expect(tasks.size).to eq(1)
expected: 1
got: 2
(compared using ==)
# ./spec/sample_spec.rb:345:in `block (2 levels) in <top (required)>'
2) Datastore sample supports equal_and_inequality_range
Failure/Error: expect(tasks.size).to eq(1)
expected: 1
got: 2
(compared using ==)
# ./spec/sample_spec.rb:360:in `block (2 levels) in <top (required)>'
Finished in 13.13 seconds (files took 0.23901 seconds to load)
60 examples, 2 failures
Failed examples:
rspec ./spec/sample_spec.rb:340 # Datastore sample supports inequality_range
rspec ./spec/sample_spec.rb:355 # Datastore sample supports equal_and_inequality_range
Hello,
I'm not exactly sure if I'm doing something wrong but the ruby sample keeps telling me
wrong number of arguments (given 6, expected 0))
Steps to reproduce the errors
-> rails new test_app
-> cd test_app
-> add gem 'google-cloud-vision' && gem 'google-cloud-storage' in gemfile
-> bundle install
-> add config.autoload_paths += %W(#{config.root}/lib)
in application.rb
-> add file ocr_google_test.rb in lib
-> in file ocr_google_test.rb : class OcrGoogleTest + copy paste the provided sample code : https://github.com/GoogleCloudPlatform/ruby-docs-samples/blob/master/vision/detect_pdf.rb
-> change line def detect_pdf_gcs
with def self.detect_pdf_gcs
-> add arguments for gcs_source_uri:, gcs_destination_uri:, project_id: and also the key file when launching Google::Cloud::Vision.new
-> go in console rails console
-> launch OcrGoogleTest.detect_pdf_gcs
--> RESULT : ArgumentError (wrong number of arguments (given 6, expected 0))
If anyone could help me understand this, it would be greatly appreciated :)
Thanks a lot and have a great day
When I ran Cloud Datastore Sample locally on Win7 x64, I got this error:
Faraday::SSLError:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
# ./spec/quickstart_spec.rb:22:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# OpenSSL::SSL::SSLError:
# SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
# ./spec/quickstart_spec.rb:22:in `block (2 levels) in <top (required)>'
After I added OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
in quickstart_spec.rb and sample_spec.rb, this example ran successfully.
At the same time, there's a warning: already initialized constant OpenSSL::SSL::VERIFY_PEER in the log.
How to solve this problem correctly?
Recommended: Run against 2.0.0 using the Travis OS X Build Environment
See: https://docs.travis-ci.com/user/osx-ci-environment/#Ruby-versions-implementations
This excludes Datastore intentionally, because the snippets are used as a reference and are not written to be executable.
License header has been updated to the following and should be propagated to all files in the repository.
Copyright 2017 Google LLC
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
https://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.
Instead of vision/vision_samples.rb
we should have vision/detect_landmark.rb
, vision/detect_face.rb
, and vision/detect_labels.rb
or something similar
This is to support the documentation
Story
Trying to run RSPEC on samples which use a bucket id isn't straight forward. It always documented either. It's hidden in the SPEC.
Issue
No consistent ENV name was used. A quick grep reveals the following.
bigquery/spec/bigquery_sample_spec.rb:
appengine/storage/app.rb:bucket = storage.bucket ENV["GCLOUD_STORAGE_BUCKET"]
appengine/storage/README.md:export GCLOUD_STORAGE_BUCKET=
appengine/storage/spec/storage_spec.rb: .sub("", ENV["GCLOUD_STORAGE_BUCKET"])
appengine/storage/app.yaml: GCLOUD_STORAGE_BUCKET:
language/spec/language_samples_spec.rb: @bucket_name = ENV["STORAGE_BUCKET"]
logging/spec/sample_spec.rb: # BUCKET Name of Google Cloud Storage bucket to use for log sink
logging/spec/sample_spec.rb: # ALT_BUCKET Name of an alternative bucket to also use for log sink
logging/spec/sample_spec.rb: @bucket = @storage.bucket ENV["BUCKET"]
logging/spec/sample_spec.rb: @alt_bucket = @storage.bucket ENV["ALT_BUCKET"]
storage/spec/list_buckets_spec.rb: output(/#{BUCKET_NAME}/).to_stdout)
storage/spec/spec_helper.rb:BUCKET_NAME=ENV["GOOGLE_PROJECT_ID"]
Possible-Solution
Use a consistent name , maybe, GOOGLE_STORAGE_BUCKET_ID ?
Command-line samples should...
Where:
In the Deploy Refinery CMS to App Engine flexible environment code lab, step 7, "[Set up Google Cloud Storage](https://codelabs.developers.google.com/codelab", the code after "Next update the file "config/initializers/refinery/core.rb to include the following (expected result):"
2 Issues:
1: the code does not reflect what I'm seeing in my code editor.
2: the "expected result" link --> 404 (not found) message in my browser.
Looks like something was updated, but the change is not reflected in this lab?
After submitting a pull request, CircleCI is failing with:
$ gcloud config set project $GOOGLE_CLOUD_PROJECT
ERROR: (gcloud.config.set) argument VALUE is required
Usage: gcloud config set SECTION/PROPERTY VALUE [optional flags]
optional flags may be --help | --installation | -h
For detailed information on this command and its flags, run:
gcloud config set --help
gcloud config set project $GOOGLE_CLOUD_PROJECT returned exit code 2
Action failed: gcloud config set project $GOOGLE_CLOUD_PROJECT
See https://circleci.com/gh/GoogleCloudPlatform/ruby-docs-samples/1033.
See https://www.ruby-lang.org/en/downloads/ for listing
Currently:
Currently, samples instantiate product service clients using this syntax to be consistent with the Official google-cloud-ruby documentation
require "google/cloud"
gcloud = Google::Cloud.new
translate = gcloud.translate
Samples should be updated to use the following syntax instead:
translate = Google::Cloud::Translate.new
Story
Rubyist attempts to use environment variables to save GCP default values. After reading this (README)[https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/datastore] in Datastore, the Rubyist is overwhelmed by which environment variable to use.
Issue
Similar to issue #62. Environment variables are not consistent across the Ruby samples.
Possible-Solution
Similar to issue #62. Use a consistent environment variable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.