def __init__(self, config): num_success = 0 num_fail = 0 for i in range(config["num_requests"]): if i > 0: time.sleep(config["sleep"]) response = requests.post(config["endpoint"], json=config["data"]) if response.status_code == 200: num_success += 1 else: num_fail += 1 cortex_logger.error( "ERROR", extra={ "error": True, "code": response.status_code, "body": response.text }, ) cortex_logger.warn( "FINISHED", extra={ "finished": True, "num_success": num_success, "num_fail": num_fail }, )
def __init__(self, config): num_success = 0 num_fail = 0 for i in range(config["num_requests"]): if i > 0: time.sleep(config["sleep"]) try: # response = requests.get(config["endpoint"]) response = requests.post(config["endpoint"], json=config["data"]) except Exception as e: num_fail += 1 cortex_logger.error( e, extra={ "error": True, "request_number": i, }, ) continue if response.status_code == 200: num_success += 1 cortex_logger.info("successful request", extra={ "request_success": True, "request_number": i }) else: num_fail += 1 cortex_logger.error( response.text, extra={ "error": True, "code": response.status_code, "request_number": i, }, ) cortex_logger.warn( "FINISHED", extra={ "finished": True, "num_success": num_success, "num_fail": num_fail }, )
def post_metrics(self, metrics): try: if self.statsd is None: raise CortexException( "statsd client not initialized") # unexpected for metric in metrics: tags = [ "{}:{}".format(dim["Name"], dim["Value"]) for dim in metric["Dimensions"] ] if metric.get("Unit") == "Count": self.statsd.increment(metric["MetricName"], value=metric["Value"], tags=tags) else: self.statsd.histogram(metric["MetricName"], value=metric["Value"], tags=tags) except: logger.warn("failure encountered while publishing metrics", exc_info=True)