iota_aws_orchestrator/protocol/
mod.rs1use std::path::PathBuf;
6
7use crate::{
8 benchmark::{BenchmarkParameters, BenchmarkType},
9 client::Instance,
10 display,
11};
12
13pub mod iota;
14
15pub trait ProtocolCommands<T: BenchmarkType> {
18 fn protocol_dependencies(&self) -> Vec<&'static str>;
20
21 fn db_directories(&self) -> Vec<PathBuf>;
24
25 fn genesis_command<'a, I>(&self, instances: I, parameters: &BenchmarkParameters<T>) -> String
28 where
29 I: Iterator<Item = &'a Instance>;
30
31 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 fullnode_command<I>(
44 &self,
45 instances: I,
46 parameters: &BenchmarkParameters<T>,
47 ) -> Vec<(Instance, String)>
48 where
49 I: IntoIterator<Item = Instance>;
50
51 fn monitor_command<I>(&self, instances: I) -> Vec<(Instance, String)>
52 where
53 I: IntoIterator<Item = Instance>;
54
55 fn client_command<I>(
58 &self,
59 instances: I,
60 parameters: &BenchmarkParameters<T>,
61 ) -> Vec<(Instance, String)>
62 where
63 I: IntoIterator<Item = Instance>;
64}
65
66pub trait ProtocolMetrics {
69 const BENCHMARK_DURATION: &'static str;
72 const TOTAL_TRANSACTIONS: &'static str;
75 const LATENCY_BUCKETS: &'static str;
77 const LATENCY_SUM: &'static str;
80 const LATENCY_SQUARED_SUM: &'static str;
83
84 fn nodes_metrics_path<I, T>(
86 &self,
87 instances: I,
88 parameters: &BenchmarkParameters<T>,
89 ) -> Vec<(Instance, String)>
90 where
91 I: IntoIterator<Item = Instance>,
92 T: BenchmarkType;
93 fn nodes_metrics_command<I, T>(
95 &self,
96 instances: I,
97 parameters: &BenchmarkParameters<T>,
98 ) -> Vec<(Instance, String)>
99 where
100 I: IntoIterator<Item = Instance>,
101 T: BenchmarkType,
102 {
103 self.nodes_metrics_path(instances, parameters)
104 .into_iter()
105 .map(|(instance, path)| {
106 let cmd = format!("curl '{path}'");
107 display::action(format!("\n{cmd}"));
108 (instance, cmd)
109 })
110 .collect()
111 }
112
113 fn nodes_flamegraph_command<I, T>(
115 &self,
116 instances: I,
117 _parameters: &BenchmarkParameters<T>,
118 query: &str,
119 ) -> Vec<(Instance, String)>
120 where
121 I: IntoIterator<Item = Instance>,
122 T: BenchmarkType,
123 {
124 instances
125 .into_iter()
126 .map(|instance| {
127 (instance, {
128 let cmd = format!("curl 'http://localhost:1337/flamegraph{query}'");
129 display::action(format!("\n{cmd}"));
130 cmd.to_string()
131 })
132 })
133 .collect()
134 }
135
136 fn clients_metrics_path<I, T>(
138 &self,
139 instances: I,
140 parameters: &BenchmarkParameters<T>,
141 ) -> Vec<(Instance, String)>
142 where
143 I: IntoIterator<Item = Instance>,
144 T: BenchmarkType;
145 fn clients_metrics_command<I, T>(
147 &self,
148 instances: I,
149 parameters: &BenchmarkParameters<T>,
150 ) -> Vec<(Instance, String)>
151 where
152 I: IntoIterator<Item = Instance>,
153 T: BenchmarkType,
154 {
155 self.clients_metrics_path(instances, parameters)
156 .into_iter()
157 .map(|(instance, path)| (instance, format!("curl '{path}'")))
158 .collect()
159 }
160}
161
162#[cfg(test)]
163pub mod test_protocol_metrics {
164 use super::ProtocolMetrics;
165 use crate::{
166 benchmark::{BenchmarkParameters, BenchmarkType},
167 client::Instance,
168 };
169
170 pub struct TestProtocolMetrics;
171
172 impl ProtocolMetrics for TestProtocolMetrics {
173 const BENCHMARK_DURATION: &'static str = "benchmark_duration";
174 const TOTAL_TRANSACTIONS: &'static str = "latency_s_count";
175 const LATENCY_BUCKETS: &'static str = "latency_s";
176 const LATENCY_SUM: &'static str = "latency_s_sum";
177 const LATENCY_SQUARED_SUM: &'static str = "latency_squared_s";
178
179 fn nodes_metrics_path<I, T>(
180 &self,
181 instances: I,
182 _parameters: &BenchmarkParameters<T>,
183 ) -> Vec<(Instance, String)>
184 where
185 I: IntoIterator<Item = Instance>,
186 T: BenchmarkType,
187 {
188 instances
189 .into_iter()
190 .enumerate()
191 .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 8000 + i as u16)))
192 .collect()
193 }
194
195 fn clients_metrics_path<I, T>(
196 &self,
197 instances: I,
198 _parameters: &BenchmarkParameters<T>,
199 ) -> Vec<(Instance, String)>
200 where
201 I: IntoIterator<Item = Instance>,
202 T: BenchmarkType,
203 {
204 instances
205 .into_iter()
206 .enumerate()
207 .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 9000 + i as u16)))
208 .collect()
209 }
210 }
211}