Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bbef44f

Browse filesBrowse files
authored
Merge branch 'master' into speech-continuous
2 parents 06d09c6 + 7aee849 commit bbef44f
Copy full SHA for bbef44f

File tree

Expand file treeCollapse file tree

11 files changed

+245
-5
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+245
-5
lines changed

‎.kokoro/presubmit_tests_trace.cfg

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "trace and py36 and not appengine"
15+
}

‎.kokoro/system_tests_trace.cfg

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "trace and py36 and not appengine"
15+
}

‎storage/cloud-client/acl_test.py

Copy file name to clipboardExpand all lines: storage/cloud-client/acl_test.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import time
1617

1718
from google.cloud import storage
1819
import google.cloud.storage.acl
@@ -36,7 +37,9 @@ def test_bucket():
3637
object_default_acl = google.cloud.storage.acl.DefaultObjectACL(bucket)
3738
acl.reload()
3839
object_default_acl.reload()
40+
time.sleep(1) # bucket ops rate limited 1 update per second
3941
yield bucket
42+
time.sleep(1) # bucket ops rate limited 1 update per second
4043
acl.save()
4144
object_default_acl.save()
4245

@@ -49,7 +52,9 @@ def test_blob():
4952
blob.upload_from_string('Hello, is it me you\'re looking for?')
5053
acl = google.cloud.storage.acl.ObjectACL(blob)
5154
acl.reload()
55+
time.sleep(1) # bucket ops rate limited 1 update per second
5256
yield blob
57+
time.sleep(1) # bucket ops rate limited 1 update per second
5358
acl.save()
5459

5560

‎storage/cloud-client/requirements.txt

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
google-cloud-pubsub==0.38.0
2-
google-cloud-storage==1.13.0
2+
google-cloud-storage==1.13.2

‎storage/cloud-client/snippets.py

Copy file name to clipboardExpand all lines: storage/cloud-client/snippets.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def generate_signed_url(bucket_name, blob_name):
266266
method='GET')
267267

268268
print('The signed url for {} is {}'.format(blob.name, url))
269+
return url
269270

270271

271272
def rename_blob(bucket_name, blob_name, new_name):

‎storage/cloud-client/snippets_test.py

Copy file name to clipboardExpand all lines: storage/cloud-client/snippets_test.py
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import tempfile
17+
import time
1718

1819
from google.cloud import storage
1920
import google.cloud.exceptions
@@ -30,6 +31,7 @@ def test_enable_default_kms_key():
3031
snippets.enable_default_kms_key(
3132
bucket_name=BUCKET,
3233
kms_key_name=KMS_KEY)
34+
time.sleep(2) # Let change propagate as needed
3335
bucket = storage.Client().get_bucket(BUCKET)
3436
assert bucket.default_kms_key_name.startswith(KMS_KEY)
3537
bucket.default_kms_key_name = None
@@ -135,13 +137,10 @@ def test_make_blob_public(test_blob):
135137

136138

137139
def test_generate_signed_url(test_blob, capsys):
138-
snippets.generate_signed_url(
140+
url = snippets.generate_signed_url(
139141
BUCKET,
140142
test_blob.name)
141143

142-
out, _ = capsys.readouterr()
143-
url = out.rsplit().pop()
144-
145144
r = requests.get(url)
146145
assert r.text == 'Hello, is it me you\'re looking for?'
147146

‎trace/README.rst

Copy file name to clipboard
+97Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Stackdriver Trace Python Samples
4+
===============================================================================
5+
6+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
7+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=trace/README.rst
8+
9+
10+
This directory contains samples for Stackdriver Trace. `Stackdriver Trace`_ collects latency data from applications and displays it in near real time in the Google Cloud Platform Console.
11+
12+
13+
14+
15+
.. _Stackdriver Trace: https://cloud.google.com/trace/docs
16+
17+
Setup
18+
-------------------------------------------------------------------------------
19+
20+
21+
Authentication
22+
++++++++++++++
23+
24+
This sample requires you to have authentication setup. Refer to the
25+
`Authentication Getting Started Guide`_ for instructions on setting up
26+
credentials for applications.
27+
28+
.. _Authentication Getting Started Guide:
29+
https://cloud.google.com/docs/authentication/getting-started
30+
31+
Install Dependencies
32+
++++++++++++++++++++
33+
34+
#. Clone python-docs-samples and change directory to the sample directory you want to use.
35+
36+
.. code-block:: bash
37+
38+
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
39+
40+
#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.
41+
42+
.. _Python Development Environment Setup Guide:
43+
https://cloud.google.com/python/setup
44+
45+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
46+
47+
.. code-block:: bash
48+
49+
$ virtualenv env
50+
$ source env/bin/activate
51+
52+
#. Install the dependencies needed to run the samples.
53+
54+
.. code-block:: bash
55+
56+
$ pip install -r requirements.txt
57+
58+
.. _pip: https://pip.pypa.io/
59+
.. _virtualenv: https://virtualenv.pypa.io/
60+
61+
Samples
62+
-------------------------------------------------------------------------------
63+
64+
Web Server
65+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66+
67+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
68+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=trace/main.py,trace/README.rst
69+
70+
71+
72+
73+
To run this sample:
74+
75+
.. code-block:: bash
76+
77+
$ python main.py
78+
79+
80+
81+
82+
The client library
83+
-------------------------------------------------------------------------------
84+
85+
This sample uses the `Google Cloud Client Library for Python`_.
86+
You can read the documentation for more details on API usage and use GitHub
87+
to `browse the source`_ and `report issues`_.
88+
89+
.. _Google Cloud Client Library for Python:
90+
https://googlecloudplatform.github.io/google-cloud-python/
91+
.. _browse the source:
92+
https://github.com/GoogleCloudPlatform/google-cloud-python
93+
.. _report issues:
94+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
95+
96+
97+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

‎trace/README.rst.in

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Stackdriver Trace
5+
short_name: Stackdriver Trace
6+
url: https://cloud.google.com/trace/docs
7+
description: >
8+
`Stackdriver Trace`_ collects latency data from applications and displays
9+
it in near real time in the Google Cloud Platform Console.
10+
11+
setup:
12+
- auth
13+
- install_deps
14+
15+
samples:
16+
- name: Web Server
17+
file: main.py
18+
19+
cloud_client_library: true
20+
21+
folder: trace

‎trace/main.py

Copy file name to clipboard
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import random
16+
import time
17+
18+
from flask import Flask, redirect, url_for
19+
20+
# [START trace_setup_python_configure]
21+
from opencensus.trace.exporters import stackdriver_exporter
22+
import opencensus.trace.tracer
23+
24+
exporter = stackdriver_exporter.StackdriverExporter()
25+
tracer = opencensus.trace.tracer.Tracer(exporter=exporter)
26+
# [END trace_setup_python_configure]
27+
28+
app = Flask(__name__)
29+
30+
31+
@app.route('/', methods=['GET'])
32+
def root():
33+
return redirect(url_for('index'))
34+
35+
36+
# [START trace_setup_python_quickstart]
37+
@app.route('/index.html', methods=['GET'])
38+
def index():
39+
tracer.start_span(name='index')
40+
41+
# Add up to 1 sec delay, weighted toward zero
42+
time.sleep(random.random() ** 2)
43+
result = "Tracing requests"
44+
45+
tracer.end_span()
46+
return result
47+
# [END trace_setup_python_quickstart]
48+
49+
50+
if __name__ == '__main__':
51+
app.run()

‎trace/main_test.py

Copy file name to clipboard
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_index():
19+
main.app.testing = True
20+
client = main.app.test_client()
21+
22+
resp = client.get('/index.html')
23+
assert resp.status_code == 200
24+
assert 'Tracing requests' in resp.data.decode('utf-8')
25+
26+
27+
def test_redirect():
28+
main.app.testing = True
29+
client = main.app.test_client()
30+
31+
resp = client.get('/')
32+
assert resp.status_code == 302
33+
assert '/index.html' in resp.headers.get('location', '')

‎trace/requirements.txt

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
google-cloud-trace==0.20.2
2+
opencensus==0.1.10
3+
Flask==1.0.2

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.