parameters: (config_path, perf, output_directory)
return_statement: return modified_envoy_config_path, access_log_paths
docstring: Modify Envoy config to support gathering logs, etc.
  
      Args:
          config_path: the command-line specified Envoy config path.
          perf: boolean indicating whether in performance mode.
          output_directory: directory path for additional generated files.
      Returns:
          (modified Envoy config path, list of additional files to collect)
docstring_summary: Modify Envoy config to support gathering logs, etc.
docstring_tokens: Modify Envoy config to support gathering logs etc .
function: def modify_envoy_config(config_path, perf, output_directory):
      """Modify Envoy config to support gathering logs, etc.
  
      Args:
          config_path: the command-line specified Envoy config path.
          perf: boolean indicating whether in performance mode.
          output_directory: directory path for additional generated files.
      Returns:
          (modified Envoy config path, list of additional files to collect)
      """
      # No modifications yet when in performance profiling mode.
      if perf:
          return config_path, []
  
      # Load original Envoy config.
      with open(config_path, 'r') as f:
          envoy_config = json.loads(f.read())
  
      # Add unconditional access logs for all listeners.
      access_log_paths = []
      for n, listener in enumerate(envoy_config['listeners']):
          for network_filter in listener['filters']:
              if network_filter['name'] == 'http_connection_manager':
                  config = network_filter['config']
                  access_log_path = os.path.join(output_directory, 'access_%d.log' % n)
                  access_log_config = {'path': access_log_path}
                  if 'access_log' in config:
                      config['access_log'].append(access_log_config)
                  else:
                      config['access_log'] = [access_log_config]
                  access_log_paths.append(access_log_path)
  
      # Write out modified Envoy config.
      modified_envoy_config_path = os.path.join(output_directory, 'config.json')
      with open(modified_envoy_config_path, 'w') as f:
          f.write(json.dumps(envoy_config, indent=2))
  
      return modified_envoy_config_path, access_log_paths
function_tokens: def modify_envoy_config ( config_path , perf , output_directory ) : # No modifications yet when in performance profiling mode. if perf : return config_path , [ ] # Load original Envoy config. with open ( config_path , 'r' ) as f : envoy_config = json . loads ( f . read ( ) ) # Add unconditional access logs for all listeners. access_log_paths = [ ] for n , listener in enumerate ( envoy_config [ 'listeners' ] ) : for network_filter in listener [ 'filters' ] : if network_filter [ 'name' ] == 'http_connection_manager' : config = network_filter [ 'config' ] access_log_path = os . path . join ( output_directory , 'access_%d.log' % n ) access_log_config = { 'path' : access_log_path } if 'access_log' in config : config [ 'access_log' ] . append ( access_log_config ) else : config [ 'access_log' ] = [ access_log_config ] access_log_paths . append ( access_log_path ) # Write out modified Envoy config. modified_envoy_config_path = os . path . join ( output_directory , 'config.json' ) with open ( modified_envoy_config_path , 'w' ) as f : f . write ( json . dumps ( envoy_config , indent = 2 ) ) return modified_envoy_config_path , access_log_paths