From 299bc49e0a7ac56a985add6eb66df9d6ef1a5243 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 12 Jan 2024 16:38:21 +0100 Subject: [PATCH 1/2] WIP: Add VRF latency metric on CRNs --- aleph_scoring/metrics/__init__.py | 14 ++++++++++++++ aleph_scoring/metrics/models.py | 1 + 2 files changed, 15 insertions(+) diff --git a/aleph_scoring/metrics/__init__.py b/aleph_scoring/metrics/__init__.py index 0898927..88b1468 100644 --- a/aleph_scoring/metrics/__init__.py +++ b/aleph_scoring/metrics/__init__.py @@ -56,7 +56,12 @@ "67705389842a0a1b95eaa408b009741027964edc805997475e95c505d642edd8" ) +VRF_VM_HASH = ( + "f6a734dbc98659f030e1cd9c12d8ffb769deac55d42d5db5285fba099755c779" +) + CRN_DIAGNOSTIC_VM_PATH = "{url}vm/" + CRN_DIAGNOSTIC_VM_HASH +VRF_VM_PATH = "{url}vm/" + VRF_VM_HASH IP4_SERVICE_URL = "https://v4.ident.me/" @@ -469,6 +474,14 @@ async def get_crn_metrics( ) )[0] + vrf_vm_latency = ( + await measure_http_latency( + session, + "".join(VRF_VM_PATH).format(url=url), + timeout_seconds=10, + ) + )[0] + async with aiohttp.ClientSession( timeout=timeout_generator(), connector=aiohttp.TCPConnector( @@ -502,6 +515,7 @@ async def get_crn_metrics( diagnostic_vm_latency=diagnostic_vm_latency, full_check_latency=full_check_latency, vm_ping_latency=vm_ping_latency, + vrf_latency=vrf_vm_latency, ) diff --git a/aleph_scoring/metrics/models.py b/aleph_scoring/metrics/models.py index c408358..fbe1700 100644 --- a/aleph_scoring/metrics/models.py +++ b/aleph_scoring/metrics/models.py @@ -28,6 +28,7 @@ class CrnMetrics(AlephNodeMetrics): diagnostic_vm_latency: Optional[float] full_check_latency: Optional[float] vm_ping_latency: Optional[float] = None + vrf_latency: Optional[float] = None class NodeMetrics(BaseModel): From 41124c087e0cc8898e97de780930926bf27fa03b Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 12 Jan 2024 16:39:41 +0100 Subject: [PATCH 2/2] Fix: Update aleph-sdk-python --- aleph_scoring/__main__.py | 6 +++--- aleph_scoring/metrics/__init__.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/aleph_scoring/__main__.py b/aleph_scoring/__main__.py index d361bd8..003a941 100644 --- a/aleph_scoring/__main__.py +++ b/aleph_scoring/__main__.py @@ -11,7 +11,7 @@ import sentry_sdk import typer from aleph.sdk.chains.ethereum import ETHAccount -from aleph.sdk.client import AuthenticatedAlephClient +from aleph.sdk.client import AuthenticatedAlephHttpClient from aleph.sdk.types import Account from hexbytes import HexBytes @@ -49,7 +49,7 @@ async def publish_metrics_on_aleph(account: Account, node_metrics: NodeMetrics): aleph_api_server = settings.NODE_DATA_HOST metrics_post_data = MetricsPost(tags=["mainnet"], metrics=node_metrics) - async with AuthenticatedAlephClient( + async with AuthenticatedAlephHttpClient( account=account, api_server=aleph_api_server ) as client: metrics_post, status = await client.create_post( @@ -78,7 +78,7 @@ async def publish_scores_on_aleph( # Force datetime conversion to string post_content["period"] = json.loads(period.json()) - async with AuthenticatedAlephClient( + async with AuthenticatedAlephHttpClient( account=account, api_server=aleph_api_server ) as client: scores_post, status = await client.create_post( diff --git a/aleph_scoring/metrics/__init__.py b/aleph_scoring/metrics/__init__.py index 88b1468..632a14c 100644 --- a/aleph_scoring/metrics/__init__.py +++ b/aleph_scoring/metrics/__init__.py @@ -28,7 +28,7 @@ import aiohttp import async_timeout import pyasn -from aleph.sdk import AlephClient +from aleph.sdk import AlephHttpClient from pydantic import BaseModel, validator from urllib3.util import Url, parse_url @@ -552,11 +552,10 @@ async def collect_all_crn_metrics(node_data: Dict[str, Any]) -> Sequence[CrnMetr async def get_aleph_nodes() -> Dict: - async with AlephClient(api_server=settings.NODE_DATA_HOST) as client: + async with AlephHttpClient(api_server=settings.NODE_DATA_HOST) as client: return await client.fetch_aggregate( address=settings.NODE_DATA_ADDR, key="corechannel", - limit=50, )