Added tracing to classification
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -18,29 +18,33 @@ class MagicDoer:
|
||||
requests_session = SessionTracing(propagate=True)
|
||||
|
||||
@classmethod
|
||||
def run_everything(cls, parameters: dict) -> dict:
|
||||
def run_everything(cls, parameters: dict, span: opentracing.span.Span) -> dict:
|
||||
tag = parameters['tag']
|
||||
sample_file_handle, sample_file_path = tempfile.mkstemp(prefix=f"{tag}_", suffix=".wav", dir="/dev/shm")
|
||||
span.log_kv({'event': 'sampleFileOpened', 'sampleTag': tag})
|
||||
response = None
|
||||
try:
|
||||
|
||||
# Download Sample
|
||||
object_path = urljoin(Config.STORAGE_SERVICE_URL, f"object/{tag}")
|
||||
with opentracing.tracer.start_span('downloadSample', child_of=span):
|
||||
# Download Sample
|
||||
object_path = urljoin(Config.STORAGE_SERVICE_URL, f"object/{tag}")
|
||||
|
||||
logging.info(f"Downloading sample: {tag} from {object_path}")
|
||||
r = cls.requests_session.get(object_path)
|
||||
with open(sample_file_handle, 'wb') as f:
|
||||
f.write(r.content)
|
||||
logging.info(f"Downloading sample: {tag} from {object_path}")
|
||||
r = cls.requests_session.get(object_path)
|
||||
with open(sample_file_handle, 'wb') as f:
|
||||
f.write(r.content)
|
||||
|
||||
logging.debug(f"Downloaded sample to {sample_file_path}")
|
||||
logging.debug(f"Downloaded sample to {sample_file_path}")
|
||||
|
||||
# Get a classifier that uses the default model
|
||||
model_details, classifier = cls.classifier_cache.get_default_classifier()
|
||||
with opentracing.tracer.start_span('loadClassifier', child_of=span):
|
||||
# Get a classifier that uses the default model
|
||||
model_details, classifier = cls.classifier_cache.get_default_classifier()
|
||||
|
||||
# do the majic
|
||||
classification_start_time = time.time()
|
||||
predicted_class_name, labeled_predictions = classifier.predict(sample_file_path)
|
||||
classification_duration = time.time() - classification_start_time
|
||||
with opentracing.tracer.start_span('runClassifier', child_of=span) as child_span:
|
||||
# do the majic
|
||||
classification_start_time = time.time()
|
||||
predicted_class_name, labeled_predictions = classifier.predict(sample_file_path, child_span)
|
||||
classification_duration = time.time() - classification_start_time
|
||||
|
||||
response = {
|
||||
"tag": tag,
|
||||
@@ -57,6 +61,8 @@ class MagicDoer:
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
span.log_kv({'event': 'sampleFileDeleted', 'sampleTag': tag})
|
||||
|
||||
if not response:
|
||||
logging.error("Something went wrong during classification!")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user