埋点采集部分接口调整
This commit is contained in:
parent
c62f1ab976
commit
6dc7e86e8e
36
util/api.py
36
util/api.py
@ -6,6 +6,7 @@ import requests
|
|||||||
|
|
||||||
import util.system
|
import util.system
|
||||||
from telemetry import get_tracer
|
from telemetry import get_tracer
|
||||||
|
from util import oss
|
||||||
|
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -35,10 +36,10 @@ def sync_center():
|
|||||||
TEMPLATES.values()]
|
TEMPLATES.values()]
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
req_span.set_attribute("api.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
req_span.set_attribute("api.error", str(e))
|
req_span.set_attribute("http.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
return []
|
return []
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -76,8 +77,8 @@ def get_template_info(template_id):
|
|||||||
'accessKey': os.getenv('ACCESS_KEY'),
|
'accessKey': os.getenv('ACCESS_KEY'),
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
req_span.set_attribute("api.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
req_span.set_attribute("api.error", str(e))
|
req_span.set_attribute("api.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
@ -155,8 +156,8 @@ def report_task_success(task_info, **kwargs):
|
|||||||
**kwargs
|
**kwargs
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
req_span.set_attribute("api.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
req_span.set_attribute("api.error", str(e))
|
req_span.set_attribute("api.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
@ -175,8 +176,8 @@ def report_task_start(task_info):
|
|||||||
'accessKey': os.getenv('ACCESS_KEY'),
|
'accessKey': os.getenv('ACCESS_KEY'),
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
req_span.set_attribute("api.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
req_span.set_attribute("api.error", str(e))
|
req_span.set_attribute("api.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
@ -186,7 +187,7 @@ def report_task_start(task_info):
|
|||||||
def report_task_failed(task_info, reason=''):
|
def report_task_failed(task_info, reason=''):
|
||||||
tracer = get_tracer(__name__)
|
tracer = get_tracer(__name__)
|
||||||
with tracer.start_as_current_span("report_task_failed"):
|
with tracer.start_as_current_span("report_task_failed"):
|
||||||
with tracer.start_as_current_span("report_task_failed.request") as req_span:
|
with get_tracer("api").start_as_current_span("report_task_failed.request") as req_span:
|
||||||
try:
|
try:
|
||||||
req_span.set_attribute("http.method", "POST")
|
req_span.set_attribute("http.method", "POST")
|
||||||
req_span.set_attribute("http.url",
|
req_span.set_attribute("http.url",
|
||||||
@ -196,8 +197,8 @@ def report_task_failed(task_info, reason=''):
|
|||||||
'reason': reason
|
'reason': reason
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
req_span.set_attribute("api.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
req_span.set_attribute("api.error", str(e))
|
req_span.set_attribute("api.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
@ -206,7 +207,7 @@ def report_task_failed(task_info, reason=''):
|
|||||||
|
|
||||||
def upload_task_file(task_info, ffmpeg_task):
|
def upload_task_file(task_info, ffmpeg_task):
|
||||||
tracer = get_tracer(__name__)
|
tracer = get_tracer(__name__)
|
||||||
with tracer.start_as_current_span("upload_task_file") as span:
|
with get_tracer("api").start_as_current_span("upload_task_file") as span:
|
||||||
logger.info("开始上传文件: %s", task_info.get("id"))
|
logger.info("开始上传文件: %s", task_info.get("id"))
|
||||||
span.set_attribute("file.id", task_info.get("id"))
|
span.set_attribute("file.id", task_info.get("id"))
|
||||||
try:
|
try:
|
||||||
@ -218,8 +219,9 @@ def upload_task_file(task_info, ffmpeg_task):
|
|||||||
json={
|
json={
|
||||||
'accessKey': os.getenv('ACCESS_KEY'),
|
'accessKey': os.getenv('ACCESS_KEY'),
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
response.raise_for_status()
|
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
|
req_span.set_attribute("http.response", response.text)
|
||||||
|
response.raise_for_status()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
span.set_attribute("api.error", str(e))
|
span.set_attribute("api.error", str(e))
|
||||||
logger.error("请求失败!", e)
|
logger.error("请求失败!", e)
|
||||||
@ -227,18 +229,4 @@ def upload_task_file(task_info, ffmpeg_task):
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
url = data.get('data', "")
|
url = data.get('data', "")
|
||||||
logger.info("开始上传文件: %s 至 %s", task_info.get("id"), url)
|
logger.info("开始上传文件: %s 至 %s", task_info.get("id"), url)
|
||||||
try:
|
return oss.upload_to_oss(url, ffmpeg_task.get_output_file())
|
||||||
with tracer.start_as_current_span("upload_task_file.start_upload_file") as upload_span:
|
|
||||||
upload_span.set_attribute("http.method", "PUT")
|
|
||||||
upload_span.set_attribute("http.url", url)
|
|
||||||
with open(ffmpeg_task.get_output_file(), 'rb') as f:
|
|
||||||
response = requests.put(url, data=f, headers={"Content-Type": "video/mp4"})
|
|
||||||
upload_span.set_attribute("http.status_code", response.status_code)
|
|
||||||
upload_span.set_attribute("http.response", response.text)
|
|
||||||
except requests.RequestException as e:
|
|
||||||
span.set_attribute("api.error", str(e))
|
|
||||||
logger.error("上传失败!", e)
|
|
||||||
return False
|
|
||||||
finally:
|
|
||||||
logger.info("上传文件结束: %s", task_info.get("id"))
|
|
||||||
return True
|
|
||||||
|
@ -28,10 +28,11 @@ def upload_to_oss(url, file_path):
|
|||||||
req_span.set_attribute("http.method", "PUT")
|
req_span.set_attribute("http.method", "PUT")
|
||||||
req_span.set_attribute("http.url", url)
|
req_span.set_attribute("http.url", url)
|
||||||
with open(file_path, 'rb') as f:
|
with open(file_path, 'rb') as f:
|
||||||
response = requests.put(url, data=f, timeout=60) # 设置超时时间为1分钟
|
response = requests.put(url, data=f, timeout=60, headers={"Content-Type": "video/mp4"})
|
||||||
req_span.set_attribute("http.status_code", response.status_code)
|
req_span.set_attribute("http.status_code", response.status_code)
|
||||||
if response.status_code == 200:
|
req_span.set_attribute("http.response", response.text)
|
||||||
return True
|
response.raise_for_status()
|
||||||
|
return True
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
req_span.set_attribute("http.error", "Timeout")
|
req_span.set_attribute("http.error", "Timeout")
|
||||||
retries += 1
|
retries += 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user