mirror of https://github.com/nucypher/nucypher.git
Use prometheus Summary metric for decryption request count/sum instead of Counter for richer metrics including time taken.
parent
c974b94b18
commit
931cdde08e
|
@ -15,7 +15,7 @@ from nucypher_core import (
|
|||
MetadataResponsePayload,
|
||||
ReencryptionRequest,
|
||||
)
|
||||
from prometheus_client import REGISTRY, Counter
|
||||
from prometheus_client import REGISTRY, Counter, Summary
|
||||
|
||||
from nucypher.config.constants import MAX_UPLOAD_CONTENT_LENGTH
|
||||
from nucypher.crypto.keypairs import DecryptingKeypair
|
||||
|
@ -28,11 +28,6 @@ from nucypher.policy.conditions.utils import (
|
|||
)
|
||||
from nucypher.utilities.logging import Logger
|
||||
|
||||
DECRYPTION_REQUESTS = Counter(
|
||||
"threshold_decryption_num_requests",
|
||||
"Number of threshold decryption requests",
|
||||
registry=REGISTRY,
|
||||
)
|
||||
DECRYPTION_REQUESTS_SUCCESSES = Counter(
|
||||
"threshold_decryption_num_successes",
|
||||
"Number of threshold decryption successes",
|
||||
|
@ -44,6 +39,13 @@ DECRYPTION_REQUESTS_FAILURES = Counter(
|
|||
registry=REGISTRY,
|
||||
)
|
||||
|
||||
# Summary provides both `count` (num of calls), and `sum` (time taken in method)
|
||||
DECRYPTION_REQUEST_SUMMARY = Summary(
|
||||
"decryption_request_processing",
|
||||
"Summary of decryption request processing",
|
||||
registry=REGISTRY,
|
||||
)
|
||||
|
||||
HERE = BASE_DIR = Path(__file__).parent
|
||||
TEMPLATES_DIR = HERE / "templates"
|
||||
|
||||
|
@ -166,8 +168,8 @@ def _make_rest_app(this_node, log: Logger) -> Flask:
|
|||
return Response(json.dumps(payload), mimetype="application/json")
|
||||
|
||||
@rest_app.route('/decrypt', methods=["POST"])
|
||||
@DECRYPTION_REQUEST_SUMMARY.time()
|
||||
def threshold_decrypt():
|
||||
DECRYPTION_REQUESTS.inc()
|
||||
try:
|
||||
with DECRYPTION_REQUESTS_FAILURES.count_exceptions():
|
||||
encrypted_request = EncryptedThresholdDecryptionRequest.from_bytes(
|
||||
|
|
|
@ -297,7 +297,7 @@ def test_ursula_ritualist(
|
|||
"threshold_decryption_num_successes_total"
|
||||
)
|
||||
num_decryption_requests = REGISTRY.get_sample_value(
|
||||
"threshold_decryption_num_requests_total"
|
||||
"decryption_request_processing_count"
|
||||
)
|
||||
assert num_decryption_requests == (
|
||||
num_decryption_successes + num_decryption_failures
|
||||
|
|
Loading…
Reference in New Issue