1
1
import subprocess
2
2
import argparse
3
3
import time
4
+ import os
4
5
5
6
6
7
nozzle_perf_params = [
7
- {" hec-workers" : "1" , " hec-batch-size" : " 100" },
8
- {" hec-workers" : "2" , " hec-batch-size" : " 100" },
9
- {" hec-workers" : "4" , " hec-batch-size" : " 100" },
10
- {" hec-workers" : "8" , " hec-batch-size" : " 100" },
11
- {" hec-workers" : "16" , " hec-batch-size" : " 100" },
12
- {" hec-workers" : "32" , " hec-batch-size" : " 100" },
13
- {" hec-workers" : "1" , " hec-batch-size" : " 1000" },
14
- {" hec-workers" : "2" , " hec-batch-size" : " 1000" },
15
- {" hec-workers" : "4" , " hec-batch-size" : " 1000" },
16
- {" hec-workers" : "8" , " hec-batch-size" : " 1000" },
17
- {" hec-workers" : "16" , " hec-batch-size" : " 1000" },
18
- {" hec-workers" : "32" , " hec-batch-size" : " 1000" },
8
+ {' hec-workers' : '1' , ' hec-batch-size' : ' 100' },
9
+ {' hec-workers' : '2' , ' hec-batch-size' : ' 100' },
10
+ {' hec-workers' : '4' , ' hec-batch-size' : ' 100' },
11
+ {' hec-workers' : '8' , ' hec-batch-size' : ' 100' },
12
+ {' hec-workers' : '16' , ' hec-batch-size' : ' 100' },
13
+ {' hec-workers' : '32' , ' hec-batch-size' : ' 100' },
14
+ {' hec-workers' : '1' , ' hec-batch-size' : ' 1000' },
15
+ {' hec-workers' : '2' , ' hec-batch-size' : ' 1000' },
16
+ {' hec-workers' : '4' , ' hec-batch-size' : ' 1000' },
17
+ {' hec-workers' : '8' , ' hec-batch-size' : ' 1000' },
18
+ {' hec-workers' : '16' , ' hec-batch-size' : ' 1000' },
19
+ {' hec-workers' : '32' , ' hec-batch-size' : ' 1000' },
19
20
]
20
21
21
22
nozzle_perf_suites = [
22
23
{
23
- " message-type" : " s256byte" ,
24
- " extra-fields" : " message_type:s256byte" ,
25
- " cases" : nozzle_perf_params ,
24
+ ' message-type' : ' s256byte' ,
25
+ ' extra-fields' : ' message_type:s256byte' ,
26
+ ' cases' : nozzle_perf_params ,
26
27
},
27
28
{
28
- " message-type" : " s1kbyte" ,
29
- " extra-fields" : " message_type:s1kbyte" ,
30
- " cases" : nozzle_perf_params ,
29
+ ' message-type' : ' s1kbyte' ,
30
+ ' extra-fields' : ' message_type:s1kbyte' ,
31
+ ' cases' : nozzle_perf_params ,
31
32
},
32
33
{
33
- " message-type" : " uns256byte" ,
34
- " extra-fields" : " message_type:uns256byte" ,
35
- " cases" : nozzle_perf_params ,
34
+ ' message-type' : ' uns256byte' ,
35
+ ' extra-fields' : ' message_type:uns256byte' ,
36
+ ' cases' : nozzle_perf_params ,
36
37
},
37
38
{
38
- " message-type" : " uns1kbyte" ,
39
- " extra-fields" : " message_type:uns1kbyte" ,
40
- " cases" : nozzle_perf_params ,
39
+ ' message-type' : ' uns1kbyte' ,
40
+ ' extra-fields' : ' message_type:uns1kbyte' ,
41
+ ' cases' : nozzle_perf_params ,
41
42
},
42
43
]
43
44
44
45
45
46
def run_nozzle_perf (config ):
46
47
for suite in nozzle_perf_suites :
47
- for case in suite [" cases" ]:
48
- kvs = "," .join (" {}:{}" .format (k , v ) for k , v in case .iteritems ())
49
- extra_fields = " {},{}" .format (suite [" extra-fields" ], kvs )
48
+ for case in suite [' cases' ]:
49
+ kvs = ',' .join (' {}:{}' .format (k , v ) for k , v in case .iteritems ())
50
+ extra_fields = ' {},{}' .format (suite [' extra-fields' ], kvs )
50
51
51
52
cmd = [
52
- " ./splunk-firehose-nozzle" ,
53
- " --api-endpoint" , config [" api-endpoint" ],
54
- " --user" , config [" user" ],
55
- " --password" , config [" password" ],
56
- " --splunk-host" , config [" splunk-host" ],
57
- " --splunk-token" , config [" splunk-token" ],
58
- " --splunk-index" , config [" splunk-index" ],
59
- " --hec-workers" , case [" hec-workers" ],
60
- " --hec-batch-size" , case [" hec-batch-size" ],
61
- " --events" , " ContainerMetric,CounterEvent,Error,HttpStart,HttpStartStop,HttpStop,LogMessage,ValueMetric" ,
62
- " --extra-fields" , extra_fields ,
63
- " --add-app-info" ,
64
- " --enable-event-tracing" ,
65
- " --skip-ssl-validation-cf" ,
66
- " --skip-ssl-validation-splunk" ,
53
+ ' ./splunk-firehose-nozzle' ,
54
+ ' --api-endpoint' , config [' api-endpoint' ],
55
+ ' --user' , config [' user' ],
56
+ ' --password' , config [' password' ],
57
+ ' --splunk-host' , config [' splunk-host' ],
58
+ ' --splunk-token' , config [' splunk-token' ],
59
+ ' --splunk-index' , config [' splunk-index' ],
60
+ ' --hec-workers' , case [' hec-workers' ],
61
+ ' --hec-batch-size' , case [' hec-batch-size' ],
62
+ ' --events' , ' ContainerMetric,CounterEvent,Error,HttpStart,HttpStartStop,HttpStop,LogMessage,ValueMetric' ,
63
+ ' --extra-fields' , extra_fields ,
64
+ ' --add-app-info' ,
65
+ ' --enable-event-tracing' ,
66
+ ' --skip-ssl-validation-cf' ,
67
+ ' --skip-ssl-validation-splunk' ,
67
68
]
68
- print " " .join (cmd )
69
- execute (cmd , config [" duration" ])
69
+ print ' ' .join (cmd )
70
+ execute (cmd , config [' duration' ])
70
71
71
72
72
73
def execute (cmd , duration ):
73
74
has_error = False
74
75
while 1 :
75
76
try :
76
77
start = time .time ()
77
- print " start {} {}" .format (" " .join (cmd ), start )
78
+ print ' start {} {}' .format (' ' .join (cmd ), start )
78
79
out , err = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE ).communicate ()
79
80
except Exception as e :
80
81
has_error = True
81
82
print e
82
83
else :
83
84
has_error = False
84
- print " out:" , out
85
- print " err:" , err
85
+ print ' out:' , out
86
+ print ' err:' , err
86
87
finally :
87
88
end = time .time ()
88
89
last = end - start
89
- print " end {} {} duration={}" .format (" " .join (cmd ), end , last )
90
+ print ' end {} {} duration={}' .format (' ' .join (cmd ), end , last )
90
91
91
92
# If we run too short, rerun it
92
93
if last < 0.8 * duration :
93
- print " run too short, retry..."
94
+ print ' run too short, retry...'
94
95
time .sleep (1 )
95
96
elif has_error :
96
97
pass
@@ -100,43 +101,43 @@ def execute(cmd, duration):
100
101
101
102
def run_trafficcontroller (duration ):
102
103
for suite in nozzle_perf_suites :
103
- for case in suite [" cases" ]:
104
- ip = " pcf_{}_{}" .format (
105
- suite [" message-type" ],
106
- "_" .join (" {}-{}" .format (k , v ) for k , v in case .iteritems ()))
104
+ for case in suite [' cases' ]:
105
+ ip = ' pcf_{}_{}' .format (
106
+ suite [' message-type' ],
107
+ '_' .join (' {}-{}' .format (k , v ) for k , v in case .iteritems ()))
107
108
cmd = [
108
- " ./trafficcontroller" ,
109
- " --config" , " loggregator_trafficcontroller.json" ,
110
- " --disableAccessControl" ,
111
- " --duration" , str (duration ),
112
- " --message-type" , suite [" message-type" ],
113
- " --ip" , ip ,
109
+ ' ./trafficcontroller' ,
110
+ ' --config' , ' loggregator_trafficcontroller.json' ,
111
+ ' --disableAccessControl' ,
112
+ ' --duration' , str (duration ),
113
+ ' --message-type' , suite [' message-type' ],
114
+ ' --ip' , ip ,
114
115
]
115
116
116
117
execute (cmd , duration )
117
118
time .sleep (10 )
118
119
119
120
120
121
def main ():
121
- parser = argparse .ArgumentParser (description = " Nozzle perf test driver" )
122
- parser .add_argument (" --run" , dest = " run" , required = True , help = " nozzle or trafficcontroller" )
123
- parser .add_argument (" --duration" , dest = " duration" , type = int , required = True , help = " how long to run in seconds" )
122
+ parser = argparse .ArgumentParser (description = ' Nozzle perf test driver' )
123
+ parser .add_argument (' --run' , dest = ' run' , required = True , help = ' nozzle or trafficcontroller' )
124
+ parser .add_argument (' --duration' , dest = ' duration' , type = int , required = True , help = ' how long to run in seconds' )
124
125
args = parser .parse_args ()
125
126
126
- if args .run == " nozzle" :
127
+ if args .run == ' nozzle' :
127
128
config = {
128
- " api-endpoint" : " http://ghost :9911" ,
129
- " user" : " admin" ,
130
- " password" : " admin" ,
131
- " splunk-host" : " https://localhost :8088" ,
132
- " splunk-token" : "1CB57F19-DC23-419A-8EDA-BA545DD3674D" ,
133
- " splunk-index" : " main" ,
134
- " duration" : args .duration ,
129
+ ' api-endpoint' : os . environ . get ( 'API_ENDPOINT' , ' http://trafficcontroller :9911' ) ,
130
+ ' user' : os . environ . get ( 'API_USER' , ' admin' ) ,
131
+ ' password' : os . environ . get ( 'API_PASSWORD' , ' admin' ) ,
132
+ ' splunk-host' : os . environ . get ( 'SPLUNK_HOST' , ' https://heclb1 :8088' ) ,
133
+ ' splunk-token' : os . environ . get ( 'SPLUNK_TOKEN' , '00000000-0000-0000-0000-000000000000' ) ,
134
+ ' splunk-index' : os . environ . get ( 'SPLUNK_INDEX' , ' main' ) ,
135
+ ' duration' : args .duration ,
135
136
}
136
137
run_nozzle_perf (config )
137
138
else :
138
139
run_trafficcontroller (args .duration )
139
140
140
141
141
- if __name__ == " __main__" :
142
+ if __name__ == ' __main__' :
142
143
main ()
0 commit comments