Skip to content

Commit

Permalink
[feature] #1216: Add Prometheus endpoint. (#1656)
Browse files Browse the repository at this point in the history
* [feature] #1216 - initial implementation of metrics endpoint.

Signed-off-by: Aleksandr <a-p-petrosyan@yandex.ru>

* Added last_block metric.

Signed-off-by: Aleksandr <a-p-petrosyan@yandex.ru>

* Refactored and added uptime metric.

Signed-off-by: Aleksandr <a-p-petrosyan@yandex.ru>

* Documentation fix.

Signed-off-by: Aleksandr <a-p-petrosyan@yandex.ru>
  • Loading branch information
appetrosyan authored Dec 3, 2021
1 parent a89815b commit c613d87
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 72 deletions.
64 changes: 64 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ cp configs/client_config.json target/debug/config.json
cd target/debug
./iroha_client_cli --help
```

More details about Iroha Client CLI can be found [here](./client_cli/README.md).

# Integration
Expand Down Expand Up @@ -143,6 +142,14 @@ Optional JSON formatted logging can be saved to the [logging file](./docs/source

The details of the `Health` endpoint can be found [here](./docs/source/references/api_spec.md#health).

Iroha is instrumented to produce both JSON-formatted as well as `prometheus`-readable metrics at the `status` and `metrics` endpoints respectively. More information is found in the [API specifications](./docs/source/references/api_spec.md).

The [`prometheus`](https://prometheus.io/docs/introduction/overview/) monitoring system is the de-factor standard for monitoring long-running services such as an Iroha peer. In order to get started, please [install `prometheus`](https://prometheus.io/docs/introduction/first_steps/), and execute the following in the project root.

```
prometheus --config.file=configs/prometheus.yml
```

## Storage

The blocks are written to the `blocks` sub-folder (created automatically by Iroha) in the working directory of the peer. Additionally, if specified, the logging file must also be stored in a user-specified directory.
Expand Down
5 changes: 2 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Contains the end-point querying logic building on top of
//! [`crate::http_client`]. This is where you need to add any custom
//! end-point related logic.
//! Contains the end-point querying logic. This is where you need to
//! add any custom end-point related logic.
use std::{
collections::HashMap,
convert::TryFrom,
Expand Down
12 changes: 12 additions & 0 deletions configs/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

rule_files:
# - "first.rules"
# - "second.rules"

scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:8180']
13 changes: 12 additions & 1 deletion core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ pub struct Chain {

impl Chain {
/// Constructor.
#[inline]
pub fn new() -> Self {
Chain {
blocks: DashMap::new(),
}
}

/// Put latest block.
/// Push latest block.
pub fn push(&self, block: VersionedCommittedBlock) {
let height = block.as_inner_v1().header.height;
self.blocks.insert(height, block);
Expand All @@ -74,11 +75,13 @@ impl Chain {
}

/// Length of the blockchain.
#[inline]
pub fn len(&self) -> usize {
self.blocks.len()
}

/// Whether blockchain is empty.
#[inline]
pub fn is_empty(&self) -> bool {
self.blocks.is_empty()
}
Expand Down Expand Up @@ -171,6 +174,7 @@ pub struct PendingBlock {

impl PendingBlock {
/// Create a new `PendingBlock` from transactions.
#[inline]
pub fn new(transactions: Vec<VersionedAcceptedTransaction>) -> PendingBlock {
#[allow(clippy::expect_used)]
let timestamp = current_time().as_millis();
Expand Down Expand Up @@ -271,6 +275,7 @@ pub struct BlockHeader {

impl BlockHeader {
/// Checks if it's a header of a genesis block.
#[inline]
pub const fn is_genesis(&self) -> bool {
self.height == 1
}
Expand Down Expand Up @@ -336,27 +341,31 @@ declare_versioned_with_scale!(VersionedValidBlock 1..2, Debug, Clone, iroha_macr

impl VersionedValidBlock {
/// Same as [`as_v1`](`VersionedValidBlock::as_v1()`) but also does conversion
#[inline]
pub const fn as_inner_v1(&self) -> &ValidBlock {
match self {
Self::V1(v1) => &v1.0,
}
}

/// Same as [`as_inner_v1`](`VersionedValidBlock::as_inner_v1()`) but returns mutable reference
#[inline]
pub fn as_mut_inner_v1(&mut self) -> &mut ValidBlock {
match self {
Self::V1(v1) => &mut v1.0,
}
}

/// Same as [`into_v1`](`VersionedValidBlock::into_v1()`) but also does conversion
#[inline]
pub fn into_inner_v1(self) -> ValidBlock {
match self {
Self::V1(v1) => v1.0,
}
}

/// Returns header of valid block
#[inline]
pub const fn header(&self) -> &BlockHeader {
&self.as_inner_v1().header
}
Expand Down Expand Up @@ -713,12 +722,14 @@ impl From<CommittedBlock> for ValidBlock {
}

impl From<VersionedCommittedBlock> for VersionedValidBlock {
#[inline]
fn from(block: VersionedCommittedBlock) -> Self {
ValidBlock::from(block.into_inner_v1()).into()
}
}

impl From<&VersionedCommittedBlock> for Vec<Event> {
#[inline]
fn from(block: &VersionedCommittedBlock) -> Self {
block.as_inner_v1().into()
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Queue {
/// Pushes transaction into queue.
///
/// # Errors
/// See [`Error`]
/// See [`enum@Error`]
#[allow(
clippy::unwrap_in_result,
clippy::expect_used,
Expand Down
2 changes: 1 addition & 1 deletion core/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn get_trusted_peers(public_key: Option<&PublicKey>) -> HashSet<PeerId> {

#[allow(clippy::implicit_hasher)]
/// Get a sample Iroha configuration. Trusted peers must either be
/// specified in this function, including the current peer. Use [`samples::get_trusted_peers`]
/// specified in this function, including the current peer. Use [`get_trusted_peers`]
/// to populate `trusted_peers` if in doubt.
///
/// # Panics
Expand Down
2 changes: 1 addition & 1 deletion core/src/sumeragi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
pub genesis_network: Option<G>,
/// Broker
pub broker: Broker,
/// [`Kura`] actor address
/// [`Kura`](crate::kura) actor address
pub kura: AlwaysAddr<K>,
/// [`iroha_p2p::Network`] actor address
pub network: Addr<IrohaNetwork>,
Expand Down
Loading

0 comments on commit c613d87

Please sign in to comment.