Added some traces
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2021-08-09 16:06:09 +02:00
parent dfa848b1d8
commit 7ef991912c

View File

@ -5,6 +5,7 @@ from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseEr
from marshmallow import ValidationError from marshmallow import ValidationError
from utils import storage from utils import storage
from schemas import DescriptionSchema from schemas import DescriptionSchema
import opentracing
class ObjectView(FlaskView): class ObjectView(FlaskView):
@ -23,40 +24,51 @@ class ObjectView(FlaskView):
def post(self): def post(self):
# get important data from the request # get important data from the request
try: with opentracing.tracer.start_active_span('parseAndValidate'):
description = self.description_schema.loads(request.form.get('description')) try:
except ValidationError as e: description = self.description_schema.loads(request.form.get('description'))
return abort(400, str(e)) except ValidationError as e:
return abort(400, str(e))
# get and validate file # get and validate file
file = request.files['soundFile'] file = request.files['soundFile']
if file.content_type != 'audio/wave': if file.content_type != 'audio/wave':
return abort(400, f"{file.content_type} is not audio/wave") return abort(400, f"{file.content_type} is not audio/wave")
if file.content_length <= 0: if file.content_length <= 0:
return abort(411, f"Content length for soundFile is not a positive integer or missing.") return abort(411, f"Content length for soundFile is not a positive integer or missing.")
# create bucket if necessary with opentracing.tracer.start_active_span('ensureBuckets'):
try: # create bucket if necessary
storage.connection.make_bucket(current_app.config['MINIO_BUCKET_NAME']) try:
storage.connection.make_bucket(current_app.config['MINIO_BUCKET_NAME'])
except BucketAlreadyOwnedByYou as err: except BucketAlreadyOwnedByYou as err:
pass pass
except BucketAlreadyExists as err: except BucketAlreadyExists as err:
pass pass
# Everything else should be raised # Everything else should be raised
# check for conflict with opentracing.tracer.start_active_span('checkExistence'):
if self._check_existance(description['tag']): # check for conflict
return abort(409) if self._check_existance(description['tag']):
return abort(409)
# poot file into bucket with opentracing.tracer.start_active_span(
try: 'minio.putObject',
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file, tags={
file.content_length, content_type=file.content_type) "bucket": current_app.config['MINIO_BUCKET_NAME'],
except ResponseError: # TODO: Check if object already exists... somehow "object_name": description['tag'],
raise "length": file.content_length
}
):
# poot file into bucket
try:
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,
file.content_length, content_type=file.content_type)
except ResponseError: # TODO: Check if object already exists... somehow
raise
return jsonify({"status": "200"}), 200 # TODO: 200 should be OK but that would be inconsistent with the errors return jsonify({"status": "200"}), 200 # TODO: 200 should be OK but that would be inconsistent with the errors