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

chore: Add eligible voters snapshot metric | NPG-0000 #581

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 5 additions & 13 deletions services/voting-node/voting_node/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,14 @@ def _remaining_intervals_n_seconds_to_next_snapshot(self, current_time: datetime

async def _ideascale_snapshot(self, event_id: int) -> None:
"""Call the 'ideascale-importer ideascale import-all <ARGS..>' command."""
try:
# Initialize external data importer
importer = ExternalDataImporter()
await importer.ideascale_import_all(event_id)
# raise Exception("ideascale import is DISABLED. Skipping...")
except Exception as e:
logger.error(f"snapshot: {e}")
importer = ExternalDataImporter()
await importer.ideascale_import_all(event_id)
# raise Exception("ideascale import is DISABLED. Skipping...")

async def _dbsync_snapshot(self, event_id: int) -> None:
"""Call the 'ideascale-importer snapshot import <ARGS..>' command."""
try:
# Initialize external data importer
importer = ExternalDataImporter()
await importer.snapshot_import(event_id)
except Exception as e:
logger.error(f"snapshot: {e}")
importer = ExternalDataImporter()
await importer.snapshot_import(event_id)

async def take_snapshots(self, event_id: int) -> None:
"""Takes snapshots at regular intervals using ExternalDataImporter.
Expand Down
14 changes: 8 additions & 6 deletions services/voting-node/voting_node/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Main entrypoint for executing the voting node service from the shell command-line.
"""

import json
import logging
import click
import uvicorn
from ideascale_importer.utils import configure_logger
Expand Down Expand Up @@ -30,7 +32,7 @@ def voting_node_cli():
"""Deploy a jormungandr node for voting events."""


@click.command()
@click.command(context_settings={"show_default": True})
@click.option(
"--reloadable",
is_flag=True,
Expand All @@ -50,15 +52,15 @@ def voting_node_cli():
default="0.0.0.0",
help="""Host for the voting node API.

If left unset it will look for envvar `VOTING_HOST`. If no host is found, the default value is: 0.0.0.0""",
If left unset it will look for envvar `VOTING_HOST`.""",
)
@click.option(
"--api-port",
envvar=VOTING_PORT,
default=8000,
help="""Port for the voting node API.

If left unset it will look for envvar `VOTING_PORT`. If no port is found, the default value is: 8000""",
If left unset it will look for envvar `VOTING_PORT`.""",
)
@click.option(
"--log-level",
Expand All @@ -67,16 +69,16 @@ def voting_node_cli():
type=click.Choice(["info", "debug", "warn", "error", "trace"]),
help="""Set the level for logs in the voting node.

If left unset it will look for envvar `VOTING_LOG_LEVEL`. If no level is found, the default value is: info""",
If left unset it will look for envvar `VOTING_LOG_LEVEL`.""",
)
@click.option(
"--log-format",
envvar=VOTING_LOG_FORMAT,
default="text",
default="json",
type=click.Choice(["text", "json"]),
help="""Set the format for logs in the voting node.

If left unset it will look for envvar `VOTING_LOG_FORMAT`. If no format is found, the default value is: text""",
If left unset it will look for envvar `VOTING_LOG_FORMAT`.""",
)
@click.option(
"--database-url",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class SnapshotReport(BaseModel):
registrations_count: int = 0
registered_voting_power: int = 0
unregistered_voting_power: int = 0
eligible_voters_count: int = 0
processed_voting_power: int = 0
cip_15_registration_count: int = 0
cip_36_single_registration_count: int = 0
Expand Down Expand Up @@ -702,6 +703,7 @@ async def _write_db_data(self):
for ctd in network_processed_snapshot:
for snapshot_contribution in ctd.contributions:
network_report.processed_voting_power += snapshot_contribution.value
network_report.eligible_voters_count += 1

voting_key = ctd.hir.voting_key
# This can be removed once it's fixed in catalyst-toolbox
Expand Down Expand Up @@ -746,6 +748,7 @@ async def _write_db_data(self):
total_cip_36_multi_registrations=network_report.cip_36_multi_registration_count,
total_registered_voting_power=network_report.registered_voting_power,
total_unregistered_voting_power=network_report.unregistered_voting_power,
total_eligible_voters=network_report.eligible_voters_count,
total_processed_voting_power=network_report.processed_voting_power,
total_rewards_payable=network_report.rewards_payable,
total_rewards_unpayable=network_report.rewards_unpayable,
Expand Down