2424import os
2525import pprint
2626
27- import requests
28- from flask import jsonify , make_response
27+ from flask import Request , jsonify , make_response
2928
3029from slo_generator .compute import compute , export
3130from slo_generator .utils import get_exporters , load_config , setup_logging
3433LOGGER = logging .getLogger (__name__ )
3534TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
3635API_SIGNATURE_TYPE = os .environ ["GOOGLE_FUNCTION_SIGNATURE_TYPE" ]
36+ BATCH_REQUEST_PARAMETER = "batch"
3737setup_logging ()
3838
3939
@@ -53,7 +53,7 @@ def run_compute(request):
5353
5454 # Process request
5555 data = process_req (request )
56- batch_mode = request .args .get ("batch" , False )
56+ batch_mode = request .args .get (BATCH_REQUEST_PARAMETER , False )
5757 if batch_mode :
5858 if not API_SIGNATURE_TYPE == "http" :
5959 raise ValueError (
@@ -203,11 +203,6 @@ def process_batch_req(request, data, config):
203203 "requests separately."
204204 )
205205 urls = data .split (";" )
206- service_url = request .base_url
207- headers = {"User-Agent" : "slo-generator" }
208- if "Authorization" in request .headers :
209- headers ["Authorization" ] = request .headers ["Authorization" ]
210- service_url = service_url .replace ("http:" , "https:" ) # force HTTPS auth
211206 for url in urls :
212207 if "pubsub_batch_handler" in config :
213208 LOGGER .info (f"Sending { url } to pubsub batch handler." )
@@ -228,4 +223,8 @@ def process_batch_req(request, data, config):
228223 client .publish (topic_path , data = data ).result ()
229224 else : # http
230225 LOGGER .info (f"Sending { url } to HTTP batch handler." )
231- requests .post (service_url , headers = headers , data = url , timeout = 10 )
226+ args = request .args .copy ()
227+ args [BATCH_REQUEST_PARAMETER ] = False
228+ req = Request .from_values (data = url )
229+ req .args = args
230+ run_compute (req )
0 commit comments