Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pub key label in metrics #3

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions eth_jit_exiter/webhook_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: ")
Expand All @@ -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(
Expand All @@ -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, {
Expand Down