Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: third_party/grpc/tools/gcp/stress_test/run_server.py

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python2.7
2 # Copyright 2015-2016, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import datetime
32 import os
33 import select
34 import subprocess
35 import sys
36 import time
37
38 from stress_test_utils import BigQueryHelper
39 from stress_test_utils import EventType
40
41
42 def run_server():
43 """This is a wrapper around the interop server and performs the following:
44 1) Create a 'Summary table' in Big Query to record events like the server
45 started, completed successfully or failed. NOTE: This also creates
46 another table called the QPS table which is currently NOT needed on the
47 server (it is needed on the stress test clients)
48 2) Start the server process and add a row in Big Query summary table
49 3) Wait for the server process to terminate. The server process does not
50 terminate unless there is an error.
51 If the server process terminated with a failure, add a row in Big Query
52 and wait forever.
53 NOTE: This script typically runs inside a GKE pod which means that the
54 pod gets destroyed when the script exits. However, in case the server
55 process fails, we would not want the pod to be destroyed (since we
56 might want to connect to the pod for examining logs). This is the
57 reason why the script waits forever in case of failures.
58 """
59
60 # Read the parameters from environment variables
61 env = dict(os.environ)
62
63 run_id = env['RUN_ID'] # The unique run id for this test
64 image_type = env['STRESS_TEST_IMAGE_TYPE']
65 image_name = env['STRESS_TEST_IMAGE']
66 args_str = env['STRESS_TEST_ARGS_STR']
67 pod_name = env['POD_NAME']
68 project_id = env['GCP_PROJECT_ID']
69 dataset_id = env['DATASET_ID']
70 summary_table_id = env['SUMMARY_TABLE_ID']
71 qps_table_id = env['QPS_TABLE_ID']
72
73 logfile_name = env.get('LOGFILE_NAME')
74
75 print('pod_name: %s, project_id: %s, run_id: %s, dataset_id: %s, '
76 'summary_table_id: %s, qps_table_id: %s') % (
77 pod_name, project_id, run_id, dataset_id, summary_table_id,
78 qps_table_id)
79
80 bq_helper = BigQueryHelper(run_id, image_type, pod_name, project_id,
81 dataset_id, summary_table_id, qps_table_id)
82 bq_helper.initialize()
83
84 # Create BigQuery Dataset and Tables: Summary Table and Metrics Table
85 if not bq_helper.setup_tables():
86 print 'Error in creating BigQuery tables'
87 return
88
89 start_time = datetime.datetime.now()
90
91 logfile = None
92 details = 'Logging to stdout'
93 if logfile_name is not None:
94 print 'Opening log file: ', logfile_name
95 logfile = open(logfile_name, 'w')
96 details = 'Logfile: %s' % logfile_name
97
98 # Update status that the test is starting (in the status table)
99 bq_helper.insert_summary_row(EventType.STARTING, details)
100
101 stress_cmd = [image_name] + [x for x in args_str.split()]
102
103 print 'Launching process %s ...' % stress_cmd
104 stress_p = subprocess.Popen(args=stress_cmd,
105 stdout=logfile,
106 stderr=subprocess.STDOUT)
107
108 returncode = stress_p.wait()
109 if returncode != 0:
110 end_time = datetime.datetime.now().isoformat()
111 event_type = EventType.FAILURE
112 details = 'Returncode: %d; End time: %s' % (returncode, end_time)
113 bq_helper.insert_summary_row(event_type, details)
114 print 'Waiting indefinitely..'
115 select.select([], [], [])
116 return returncode
117
118
119 if __name__ == '__main__':
120 run_server()
OLDNEW
« no previous file with comments | « third_party/grpc/tools/gcp/stress_test/run_client.py ('k') | third_party/grpc/tools/gcp/stress_test/stress_test_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698