Skip to content

Commit acf89eb

Browse files
authored
Add progress messages and remove new line from response (GoogleCloudPlatform#3289)
- Log some progress messages while fetching services' endpoints - Remove newline character in return.
1 parent 5adbbc5 commit acf89eb

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

trace/cloud-trace-demo-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ If you are using the provided image, skip to the next section.
4242
`./setup.sh`
4343
12. Send request to the last service:
4444

45-
`curl $(kubectl get svc cloud-trace-demo-c -ojsonpath='{.status.loadBalancer.ingress[0].ip}')`
45+
`curl -w "\n" $(kubectl get svc cloud-trace-demo-c -ojsonpath='{.status.loadBalancer.ingress[0].ip}')`
4646
13. Visit [Trace List](https://pantheon.corp.google.com/traces/list) to check traces generated.
4747
Click on any trace in the graph to see the Waterfall View.
4848
![Screenshot](./example.png)

trace/cloud-trace-demo-app/app/app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
"""
1515
A sample app demonstrating Stackdriver Trace
1616
"""
17-
17+
# [START trace_demo_imports]
1818
from flask import Flask
1919
from opencensus.trace import execution_context
2020
from opencensus.trace.propagation import google_cloud_format
2121
from opencensus.trace.samplers import AlwaysOnSampler
2222
from opencensus.ext.stackdriver.trace_exporter import StackdriverExporter
2323
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
24+
# [END trace_demo_imports]
2425

2526
import requests
2627
import argparse
@@ -29,6 +30,7 @@
2930

3031
app = Flask(__name__)
3132

33+
# [START trace_demo_middleware]
3234
propagator = google_cloud_format.GoogleCloudFormatPropagator()
3335

3436

@@ -41,6 +43,7 @@ def createMiddleWare(exporter):
4143
propagator=propagator,
4244
sampler=AlwaysOnSampler())
4345
return middleware
46+
# [END trace_demo_middleware]
4447

4548

4649
@app.route('/')
@@ -55,13 +58,15 @@ def template_test():
5558
return output_string, 200
5659
# Endpoint is the next service to send string to.
5760
data = {'body': output_string}
61+
# [START trace_context_header]
5862
trace_context_header = propagator.to_header(execution_context.get_opencensus_tracer().span_context)
5963
response = requests.get(
6064
url,
6165
params=data,
6266
headers={
6367
'X-Cloud-Trace-Context' : trace_context_header}
6468
)
69+
# [END trace_context_header]
6570
return response.text + app.config['keyword']
6671

6772

@@ -72,5 +77,7 @@ def template_test():
7277
args = parser.parse_args()
7378
app.config['keyword'] = args.keyword
7479
app.config['endpoint'] = args.endpoint
80+
# [START trace_demo_create_exporter]
7581
createMiddleWare(StackdriverExporter())
82+
# [END trace_demo_create_exporter]
7683
app.run(debug=True, host='0.0.0.0', port=8080)

trace/cloud-trace-demo-app/app/demo-service-c.yaml.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
- python
2323
args:
2424
- app.py
25-
- --keyword=!\n
25+
- --keyword=!
2626
- --endpoint=http://{{ endpoint }}
2727
ports:
2828
- containerPort: 8080

trace/cloud-trace-demo-app/setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ echo "Fetching the external IP of service a"
99
endpoint=""
1010
for run in {1..20}
1111
do
12+
echo "Attempt #${run} to fetch the external IP of service a..."
1213
sleep 5
1314
endpoint=`kubectl get svc cloud-trace-demo-a -ojsonpath='{.status.loadBalancer.ingress[0].ip}'`
1415
if [[ "$endpoint" != "" ]]; then
@@ -31,6 +32,7 @@ echo "Fetching the external IP of service b"
3132
endpoint=""
3233
for run in {1..20}
3334
do
35+
echo "Attempt #${run} to fetch the external IP of service b..."
3436
sleep 5
3537
endpoint=`kubectl get svc cloud-trace-demo-b -ojsonpath='{.status.loadBalancer.ingress[0].ip}'`
3638
if [[ "$endpoint" != "" ]]; then

0 commit comments

Comments
 (0)