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