iota_aws_orchestrator/protocol/
mod.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::path::PathBuf;
6
7use crate::{
8    benchmark::{BenchmarkParameters, BenchmarkType},
9    client::Instance,
10};
11
12pub mod iota;
13
14/// The minimum interface that the protocol should implement to allow benchmarks
15/// from the orchestrator.
16pub trait ProtocolCommands<T: BenchmarkType> {
17    /// The list of dependencies to install (e.g., through apt-get).
18    fn protocol_dependencies(&self) -> Vec<&'static str>;
19
20    /// The directories of all databases (that should be erased before each
21    /// run).
22    fn db_directories(&self) -> Vec<PathBuf>;
23
24    /// The command to generate the genesis and all configuration files. This
25    /// command is run on each remote machine.
26    fn genesis_command<'a, I>(&self, instances: I) -> String
27    where
28        I: Iterator<Item = &'a Instance>;
29
30    /// The command to run a node. The function returns a vector of commands
31    /// along with the associated instance on which to run the command.
32    fn node_command<I>(
33        &self,
34        instances: I,
35        parameters: &BenchmarkParameters<T>,
36    ) -> Vec<(Instance, String)>
37    where
38        I: IntoIterator<Item = Instance>;
39
40    fn monitor_command<I>(&self, instances: I) -> Vec<(Instance, String)>
41    where
42        I: IntoIterator<Item = Instance>;
43
44    /// The command to run a client. The function returns a vector of commands
45    /// along with the associated instance on which to run the command.
46    fn client_command<I>(
47        &self,
48        instances: I,
49        parameters: &BenchmarkParameters<T>,
50    ) -> Vec<(Instance, String)>
51    where
52        I: IntoIterator<Item = Instance>;
53}
54
55/// The names of the minimum metrics exposed by the load generators that are
56/// required to compute performance.
57pub trait ProtocolMetrics {
58    /// The name of the metric reporting the total duration of the benchmark (in
59    /// seconds).
60    const BENCHMARK_DURATION: &'static str;
61    /// The name of the metric reporting the total number of finalized
62    /// transactions
63    const TOTAL_TRANSACTIONS: &'static str;
64    /// The name of the metric reporting the latency buckets.
65    const LATENCY_BUCKETS: &'static str;
66    /// The name of the metric reporting the sum of the end-to-end latency of
67    /// all finalized transactions.
68    const LATENCY_SUM: &'static str;
69    /// The name of the metric reporting the square of the sum of the end-to-end
70    /// latency of all finalized transactions.
71    const LATENCY_SQUARED_SUM: &'static str;
72
73    /// The network path where the nodes expose prometheus metrics.
74    fn nodes_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
75    where
76        I: IntoIterator<Item = Instance>;
77    /// The command to retrieve the metrics from the nodes.
78    fn nodes_metrics_command<I>(&self, instances: I) -> Vec<(Instance, String)>
79    where
80        I: IntoIterator<Item = Instance>,
81    {
82        self.nodes_metrics_path(instances)
83            .into_iter()
84            .map(|(instance, path)| (instance, format!("curl {path}")))
85            .collect()
86    }
87
88    /// The network path where the clients expose prometheus metrics.
89    fn clients_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
90    where
91        I: IntoIterator<Item = Instance>;
92    /// The command to retrieve the metrics from the clients.
93    fn clients_metrics_command<I>(&self, instances: I) -> Vec<(Instance, String)>
94    where
95        I: IntoIterator<Item = Instance>,
96    {
97        self.clients_metrics_path(instances)
98            .into_iter()
99            .map(|(instance, path)| (instance, format!("curl {path}")))
100            .collect()
101    }
102}
103
104#[cfg(test)]
105pub mod test_protocol_metrics {
106    use super::ProtocolMetrics;
107    use crate::client::Instance;
108
109    pub struct TestProtocolMetrics;
110
111    impl ProtocolMetrics for TestProtocolMetrics {
112        const BENCHMARK_DURATION: &'static str = "benchmark_duration";
113        const TOTAL_TRANSACTIONS: &'static str = "latency_s_count";
114        const LATENCY_BUCKETS: &'static str = "latency_s";
115        const LATENCY_SUM: &'static str = "latency_s_sum";
116        const LATENCY_SQUARED_SUM: &'static str = "latency_squared_s";
117
118        fn nodes_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
119        where
120            I: IntoIterator<Item = Instance>,
121        {
122            instances
123                .into_iter()
124                .enumerate()
125                .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 8000 + i as u16)))
126                .collect()
127        }
128
129        fn clients_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
130        where
131            I: IntoIterator<Item = Instance>,
132        {
133            instances
134                .into_iter()
135                .enumerate()
136                .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 9000 + i as u16)))
137                .collect()
138        }
139    }
140}