Pull request #24: Response dict & Prometheus forwarding

Merge in RR/pyinfra from response-dict to master

Squashed commit of the following:

commit aed09653aafe7b9558c542ea0c36a5f072c6ab9e
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Mon Mar 21 15:20:24 2022 +0100

    BLACK

commit d1b76673a22373c32815466c37dcb006fa0d6fb4
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Mon Mar 21 15:19:55 2022 +0100

    change default response dict

commit 82bd48a7545b9b244bdcdebf7ce976947eecf580
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Mon Mar 21 15:19:15 2022 +0100

    fix handling of missing prometheus endpoint
This commit is contained in:
Julius Unverfehrt 2022-03-21 15:22:38 +01:00 committed by Matthias Bisping
parent ea49b001be
commit 1b1da50faf
3 changed files with 14 additions and 7 deletions

View File

@ -50,11 +50,15 @@ def set_up_probing_webserver():
try:
resp = requests.get(f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus")
resp.raise_for_status()
return resp.text
except Exception as err:
if not informed_about_missing_prometheus_endpoint:
logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}")
informed_about_missing_prometheus_endpoint = True
return resp
except ConnectionError:
return ""
except requests.exceptions.HTTPError as err:
if resp.status_code == 404:
if not informed_about_missing_prometheus_endpoint:
logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}")
informed_about_missing_prometheus_endpoint = True
else:
raise err
return resp.text
return app

View File

@ -48,7 +48,8 @@ def build_message_bodies(analyse_container_type):
message_dict.update({"targetFileExtension": "ORIGIN.pdf.gz", "responseFileExtension": "IMAGE_INFO.json.gz"})
if analyse_container_type == "ner":
message_dict.update(
{"targetFileExtension": "TEXT.json.gz", "responseFileExtension": "NER_ENTITIES.json.gz"})
{"targetFileExtension": "TEXT.json.gz", "responseFileExtension": "NER_ENTITIES.json.gz"}
)
return message_dict
storage = get_s3_storage()

View File

@ -31,6 +31,8 @@ def make_callback(analysis_endpoint):
operations = message.get("operations", ["/"])
results = map(perform_operation, operations)
result = dict(zip(operations, results))
if list(result.keys()) == ["/"]:
result = list(result.values())[0]
return result
return callback