Skip to content

Commit

Permalink
Registry: Simplify and improve stats
Browse files Browse the repository at this point in the history
As was done for the block stats in 009b7e1,
we now always provide block stats no matter if we received
a record or not. We also provide different values for flash
and validators entry, and let the handler make the addition.
  • Loading branch information
Geod24 committed Sep 16, 2021
1 parent 69aa790 commit a8d1065
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
25 changes: 17 additions & 8 deletions source/agora/node/Registry.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public class NameRegistry: NameRegistryAPI
/// The `flash` zone
private ZoneData flash;

/// Validator count stats
private RegistryStats registry_stats;

///
private FullNodeAPI agora_node;

Expand All @@ -73,7 +70,7 @@ public class NameRegistry: NameRegistryAPI
this.config = config;
this.log = Logger(__MODULE__);
this.agora_node = agora_node;
Utils.getCollectorRegistry().addCollector(&this.collectRegistryStats);
Utils.getCollectorRegistry().addCollector(&this.collectStats);

const vname = "validators." ~ realm;
const fname = "flash." ~ realm;
Expand All @@ -95,8 +92,22 @@ public class NameRegistry: NameRegistryAPI
this.flash.fill(fname, this.config.flash, serial);
}

///
mixin DefineCollectorForStats!("registry_stats", "collectRegistryStats");
/***************************************************************************
Collect registry stats
Params:
collector = the Collector to collect the stats into
***************************************************************************/

private void collectStats (Collector collector)
{
RegistryStats stats;
stats.registry_validator_record_count = this.validators.map.length;
stats.registry_flash_record_count = this.flash.map.length;
collector.collect(stats);
}

/// Returns: throws if payload is not valid
protected void ensureValidPayload (in RegistryPayload registry_payload,
Expand Down Expand Up @@ -184,7 +195,6 @@ public class NameRegistry: NameRegistryAPI
registry_payload.data.addresses, registry_payload.data.public_key);
this.validators.map[registry_payload.data.public_key] =
TypedPayload(payload_type, registry_payload);
this.registry_stats.setMetricTo!"registry_record_count"(this.validators.map.length + this.flash.map.length);
}

/***************************************************************************
Expand Down Expand Up @@ -245,7 +255,6 @@ public class NameRegistry: NameRegistryAPI
registry_payload.data.public_key.toString());
this.flash.map[registry_payload.data.public_key] =
TypedPayload(payload_type, registry_payload);
this.registry_stats.setMetricTo!"registry_record_count"(this.validators.map.length + this.flash.map.length);
}

///
Expand Down
10 changes: 5 additions & 5 deletions source/agora/stats/Registry.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module agora.stats.Registry;
import agora.stats.Stats;

///
public struct RegistryStatsValue
public struct RegistryStats
{
public ulong registry_record_count;
/// Number of records in the 'validators' zone
public ulong registry_validator_record_count;
/// Number of records in the 'flash' zone
public ulong registry_flash_record_count;
}

///
public alias RegistryStats = Stats!(RegistryStatsValue, NoLabel);

0 comments on commit a8d1065

Please sign in to comment.