Skip to content

Commit

Permalink
Expose the number of the view changes in the current round as the net…
Browse files Browse the repository at this point in the history
…work sanity indicator

Signed-off-by: s8sato <[email protected]>
  • Loading branch information
s8sato committed Apr 20, 2022
1 parent 950feae commit 8fbe8a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 4 additions & 0 deletions core/src/sumeragi/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ impl<G: GenesisNetworkTrait, K: KuraTrait, W: WorldTrait, F: FaultInjection>
self.invalidated_blocks_hashes.push(hash)
}
self.topology.apply_view_change(proof.clone());
self.wsv
.metrics
.view_changes
.set(self.number_of_view_changes());
self.voting_block = None;
error!(
peer_addr = %self.peer_id.address,
Expand Down
28 changes: 7 additions & 21 deletions docs/source/references/api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,19 @@ Also returns current status of peer in json string:
+ Number of committed blocks (block height)
+ Total number of transactions
+ `uptime` since creation of the genesis block in milliseconds.
+ Number of view_changes in the current round

```json
{
"peers": 3,
"blocks": 1,
"txs_accepted": 3,
"txs_rejected": 0,
"uptime": 3200,
"uptime": {
"secs": 5,
"nanos": 937000000
},
"view_changes": 0
}
```

Expand All @@ -251,26 +256,7 @@ Also returns current status of peer in json string:
**Expects**: -

**Responses**:
- 200 OK - currently mirrors status:
+ Number of connected peers, except for the reporting peer itself
+ Number of committed blocks (block height)
+ Total number of transactions
+ `uptime` since creation of the genesis block in milliseconds.

```bash
# HELP block_height Current block height
# TYPE block_height counter
block_height 0
# HELP connected_peers Total number of currently connected peers
# TYPE connected_peers gauge
connected_peers 0
# HELP txs Transactions committed
# TYPE txs counter
txs 0
# HELP uptime_since_genesis_ms Uptime of the network, starting from creation of the genesis block
# TYPE uptime_since_genesis_ms gauge
uptime_since_genesis_ms 0
```
In a typical use case, Prometheus handles the response

## Parity Scale Codec

Expand Down
14 changes: 13 additions & 1 deletion telemetry/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct Status {
pub txs_rejected: u64,
/// Uptime since genesis block creation
pub uptime: Uptime,
/// Number of view changes in the current round
pub view_changes: u64,
}

impl<T: Deref<Target = Metrics>> From<&T> for Status {
Expand All @@ -44,6 +46,7 @@ impl<T: Deref<Target = Metrics>> From<&T> for Status {
txs_accepted: val.txs.with_label_values(&["accepted"]).get(),
txs_rejected: val.txs.with_label_values(&["rejected"]).get(),
uptime: Uptime(Duration::from_millis(val.uptime_since_genesis_ms.get())),
view_changes: val.view_changes.get(),
}
}
}
Expand All @@ -69,6 +72,8 @@ pub struct Metrics {
pub isi: IntCounterVec,
/// Query handle time Histogram
pub isi_times: HistogramVec,
/// Number of view changes in the current round
pub view_changes: GenericGauge<AtomicU64>,
// Internal use only.
registry: Registry,
}
Expand Down Expand Up @@ -112,6 +117,11 @@ impl Default for Metrics {
&["domain"],
)
.expect("Infallible");
let view_changes = GenericGauge::new(
"view_changes",
"Number of view changes in the current round",
)
.expect("Infallible");
let registry = Registry::new();

macro_rules! register {
Expand All @@ -133,7 +143,8 @@ impl Default for Metrics {
domains,
accounts,
isi,
isi_times
isi_times,
view_changes
);

Self {
Expand All @@ -147,6 +158,7 @@ impl Default for Metrics {
tx_amounts,
isi,
isi_times,
view_changes,
}
}
}
Expand Down

0 comments on commit 8fbe8a3

Please sign in to comment.