From 483be233ad539fa53510412058d2f91337ee2a22 Mon Sep 17 00:00:00 2001 From: concentricspheres <107502292+concentricspheres@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:00:38 -0600 Subject: [PATCH] use pub key label in metrics --- eth_jit_exiter/webhook_server.py | 40 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/eth_jit_exiter/webhook_server.py b/eth_jit_exiter/webhook_server.py index 6e53241..871237a 100644 --- a/eth_jit_exiter/webhook_server.py +++ b/eth_jit_exiter/webhook_server.py @@ -20,10 +20,11 @@ LIMITER = None # Define all metrics -EXIT_REQUESTS_COUNTER = Counter('exit_requests', 'Number of times an exit has been requested') -EXIT_REQUESTS_LIMITED = Counter('exit_requests_rate_limited', 'Number of times an exit request has been rate limited') -EXIT_REQUESTS_SUCCESSFUL = Counter('exit_requests_successful', 'Number of times an exit request has been submitted successfully') -EXIT_REQUESTS_FAILED = Counter('exit_requests_failed', 'Number of times an exit request failed') +EXIT_REQUESTS_COUNTER = Counter('exit_requests', 'Number of times an exit has been requested', ['validator_pub_key']) +EXIT_REQUESTS_LIMITED = Counter('exit_requests_rate_limited', 'Number of times an exit request has been rate limited', ['validator_pub_key']) +EXIT_REQUESTS_SUCCESSFUL = Counter('exit_requests_successful', 'Number of times an exit request has been submitted successfully', ['validator_pub_key']) +EXIT_REQUESTS_FAILED = Counter('exit_requests_failed', 'Number of times an exit request failed', ['validator_pub_key']) +EXIT_REQUESTS_INVALID = Counter('exit_requests_invalid', 'Number of invalid exit requests') async def make_request(session, method, url, payload): try: @@ -56,17 +57,6 @@ async def async_requests(method, path, payload=None): # { "validatorIndex": "123", "validatorPubkey": "0x123" } @app.route("/webhook", methods=["POST"]) def exit_webhook(): - EXIT_REQUESTS_COUNTER.inc() - - try: - LIMITER.try_acquire('webhook') - except BucketFullException as err: - volume = LIMITER.get_current_volume('webhook') - LOGGER.error(err.meta_info) - LOGGER.error(f"Current rate volume: {volume}") - EXIT_REQUESTS_LIMITED.inc() - return {"status": "RATE_LIMIT_EXCEEDED"}, 429 - data = request.json LOGGER.info("Request body: ") @@ -76,6 +66,17 @@ def exit_webhook(): validator_pub_key = data.get('validatorPubkey', None) if validator_index and validator_pub_key: + try: + LIMITER.try_acquire('webhook') + except BucketFullException as err: + volume = LIMITER.get_current_volume('webhook') + LOGGER.error(err.meta_info) + LOGGER.error(f"Current rate volume: {volume}") + EXIT_REQUESTS_LIMITED.labels(validator_pub_key=validator_pub_key).inc() + return {"status": "RATE_LIMIT_EXCEEDED"}, 429 + + EXIT_REQUESTS_COUNTER.labels(validator_pub_key=validator_pub_key).inc() + # Asynchronously request every client to sign and submit the exit message # if they find the public key on their dirk instances sign_requests = async_requests( @@ -95,11 +96,14 @@ def exit_webhook(): reponse_body = response['body'] if reponse_body.get('status', None) == 'SUCCEEDED': - EXIT_REQUESTS_SUCCESSFUL.inc() + EXIT_REQUESTS_SUCCESSFUL.labels(validator_pub_key=validator_pub_key).inc() return {"status": "SUCCEEDED"}, 200 - EXIT_REQUESTS_FAILED.inc() - return {"status": "FAILED"}, 418 + EXIT_REQUESTS_FAILED.labels(validator_pub_key=validator_pub_key).inc() + return {"status": "FAILED"}, 418 + else: + EXIT_REQUESTS_INVALID.inc() + return {"status": "INVALID"}, 400 # Add prometheus wsgi middleware to route /metrics requests app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {