1111import logging
1212from collections import defaultdict
1313from functools import partial
14+ from dotenv import load_dotenv
1415
1516from azure .identity import ClientSecretCredential
1617from azure .eventhub .extensions .checkpointstoreblob import BlobCheckpointStore
2021from process_monitor import ProcessMonitor
2122from app_insights_metric import AzureMonitorMetric
2223
24+ ENV_FILE = os .environ .get ('ENV_FILE' )
25+ load_dotenv (dotenv_path = ENV_FILE , override = True )
26+
2327
2428def parse_starting_position (args ):
2529 starting_position = None
@@ -37,26 +41,26 @@ def parse_starting_position(args):
3741
3842
3943parser = argparse .ArgumentParser ()
40- parser .add_argument ("--link_credit" , default = 3000 , type = int )
41- parser .add_argument ("--output_interval" , type = float , default = 1000 )
42- parser .add_argument ("--duration" , help = "Duration in seconds of the test" , type = int , default = 30 )
43- parser .add_argument ("--consumer_group" , help = "Consumer group name" , default = " $default" )
44+ parser .add_argument ("--link_credit" , default = int ( os . environ . get ( "LINK_CREDIT" , 3000 )) , type = int )
45+ parser .add_argument ("--output_interval" , type = float , default = int ( os . environ . get ( "OUTPUT_INTERVAL" , 5000 )) )
46+ parser .add_argument ("--duration" , help = "Duration in seconds of the test" , type = int , default = int ( os . environ . get ( "DURATION" , 999999999 )) )
47+ parser .add_argument ("--consumer_group" , help = "Consumer group name" , default = os . environ . get ( "CONSUMER_GROUP" , " $default") )
4448parser .add_argument ("--auth_timeout" , help = "Authorization Timeout" , type = float , default = 60 )
45- parser .add_argument ("--starting_offset" , help = "Starting offset" , type = str )
49+ parser .add_argument ("--starting_offset" , help = "Starting offset" , type = str , default = os . environ . get ( "STARTING_OFFSET" , "-1" ) )
4650parser .add_argument ("--starting_sequence_number" , help = "Starting sequence number" , type = int )
4751parser .add_argument ("--starting_datetime" , help = "Starting datetime string, should be format of YYYY-mm-dd HH:mm:ss" )
4852parser .add_argument ("--partitions" , help = "Number of partitions. 0 means to get partitions from eventhubs" , type = int , default = 0 )
4953parser .add_argument ("--recv_partition_id" , help = "Receive from a specific partition if this is set" , type = int )
50- parser .add_argument ("--max_batch_size" , type = int , default = 0 ,
54+ parser .add_argument ("--max_batch_size" , type = int , default = int ( os . environ . get ( "MAX_BATCH_SIZE" , 0 )) ,
5155 help = "Call EventHubConsumerClient.receive_batch() if not 0, otherwise call receive()" )
5256parser .add_argument ("--max_wait_time" , type = float , default = 0 ,
5357 help = "max_wait_time of EventHubConsumerClient.receive_batch() or EventHubConsumerClient.receive()" )
5458
5559parser .add_argument ("--track_last_enqueued_event_properties" , action = "store_true" )
5660parser .add_argument ("--load_balancing_interval" , help = "time duration in seconds between two load balance" , type = float , default = 10 )
5761parser .add_argument ("--conn_str" , help = "EventHub connection string" ,
58- default = os .environ .get ('EVENT_HUB_PERF_32_CONN_STR ' ))
59- parser .add_argument ("--eventhub" , help = "Name of EventHub" )
62+ default = os .environ .get ('EVENT_HUB_CONN_STR ' ))
63+ parser .add_argument ("--eventhub" , help = "Name of EventHub" , default = os . environ . get ( 'EVENT_HUB_NAME' ) )
6064parser .add_argument ("--address" , help = "Address URI to the EventHub entity" )
6165parser .add_argument ("--sas-policy" , help = "Name of the shared access policy to authenticate with" )
6266parser .add_argument ("--sas-key" , help = "Shared access key" )
@@ -82,7 +86,14 @@ def parse_starting_position(args):
8286
8387args = parser .parse_args ()
8488starting_position = parse_starting_position (args )
85- LOGGER = get_logger (args .log_filename , "stress_receive_sync" , level = logging .INFO , print_console = args .print_console )
89+ print_console = args .print_console or (os .environ .get ("PRINT_CONSOLE" ) == "1" )
90+
91+ LOGGER = get_logger (
92+ args .log_filename ,
93+ "stress_receive_sync" ,
94+ level = logging .INFO ,
95+ print_console = print_console
96+ )
8697LOG_PER_COUNT = args .output_interval
8798
8899start_time = time .perf_counter ()
@@ -105,7 +116,6 @@ def on_event_received(process_monitor, partition_context, event):
105116 recv_cnt_map [partition_context .partition_id ] += 1 if event else 0
106117 if recv_cnt_map [partition_context .partition_id ] % LOG_PER_COUNT == 0 :
107118 total_time_elapsed = time .perf_counter () - start_time
108-
109119 partition_previous_time = recv_time_map .get (partition_context .partition_id )
110120 partition_current_time = time .perf_counter ()
111121 recv_time_map [partition_context .partition_id ] = partition_current_time
@@ -213,7 +223,11 @@ def create_client(args):
213223
214224def run (args ):
215225
216- with ProcessMonitor ("monitor_{}" .format (args .log_filename ), "consumer_stress_sync" , print_console = args .print_console ) as process_monitor :
226+ with ProcessMonitor (
227+ "monitor_{}" .format (args .log_filename ),
228+ "consumer_stress_sync" ,
229+ print_console = print_console
230+ ) as process_monitor :
217231 kwargs_dict = {
218232 "prefetch" : args .link_credit ,
219233 "partition_id" : str (args .recv_partition_id ) if args .recv_partition_id else None ,
0 commit comments