blob: dd483cf4ad812085593631d7c1ed61bbf00d2baf [file] [log] [blame]
Alex5cace3b2021-11-10 16:40:37 -06001from cfg_checker.agent.fio_runner import get_fio_options
Alex90ac1532021-12-09 11:13:14 -06002from cfg_checker.agent.fio_runner import seq_modes, mix_modes
Alexdcb792f2021-10-04 14:24:21 -05003from cfg_checker.common import logger_cli
4from cfg_checker.common.settings import ENV_TYPE_KUBE
5from cfg_checker.helpers import args_utils
6from cfg_checker.modules.ceph import info, bench
7
8command_help = "Ceph Storage information and benchmarks"
9supported_envs = [ENV_TYPE_KUBE]
10
11
12# def _selectClass(_env, strClassHint="checker"):
13# _class = None
14# if _env == ENV_TYPE_SALT:
15# if strClassHint == "info":
16# _class = info.SaltCephInfo
17# elif strClassHint == "bench":
18# _class = bench.SaltCephInfo
19# elif _env == ENV_TYPE_KUBE:
20# if strClassHint == "info":
21# _class = info.KubeCephInfo
22# elif strClassHint == "bench":
23# _class = bench.KubeCephBench
24# if not _class:
25# raise CheckerException(
26# "Unknown hint for selecting Ceph handler Class: '{}'".format(
27# strClassHint
28# )
29# )
30# else:
31# return _class
32
Alex90ac1532021-12-09 11:13:14 -060033def _get_param_and_log(arg, param_str):
34 _value = args_utils.get_arg(arg, param_str)
35 logger_cli.info(" {}={}".format(param_str, _value))
36 return _value
37
Alexdcb792f2021-10-04 14:24:21 -050038
39def init_parser(_parser):
40 # network subparser
41 ceph_subparsers = _parser.add_subparsers(dest='type')
42
43 ceph_info_parser = ceph_subparsers.add_parser(
44 'info',
45 help="Gather Ceph Cluster information"
46 )
47
48 ceph_info_parser.add_argument(
49 '--detailed',
50 action="store_true", default=False,
51 help="Print additional details"
52 )
53
54 ceph_info_parser.add_argument(
55 '--tgz',
56 metavar='ceph_tgz_filename',
57 help="HTML filename to save report"
58 )
59
60 ceph_report_parser = ceph_subparsers.add_parser(
61 'report',
62 help="Generate network check report"
63 )
64
65 ceph_report_parser.add_argument(
66 '--html',
67 metavar='ceph_html_filename',
68 help="HTML filename to save report"
69 )
70
71 ceph_bench_parser = ceph_subparsers.add_parser(
72 'bench',
73 help="Run ceph benchmark"
74 )
75
76 ceph_bench_parser.add_argument(
77 '--task-list',
78 metavar='ceph_tasks_filename',
79 help="List file with data for Ceph bench testrun"
80 )
Alex5cace3b2021-11-10 16:40:37 -060081 ceph_bench_parser.add_argument(
82 '--agents',
83 type=int, metavar='agent_count', default=5,
84 help="List file with data for Ceph bench testrun"
85 )
86 ceph_bench_parser.add_argument(
87 '--html',
88 metavar='ceph_html_filename',
89 help="HTML filename to save report"
90 )
91 ceph_bench_parser.add_argument(
92 '--storage-class',
93 metavar='storage_class',
94 help="Storage class to be used in benchmark"
95 )
96 ceph_bench_parser.add_argument(
97 '--task-file',
Alexb2129542021-11-23 15:49:42 -060098 metavar='task_file',
Alex5cace3b2021-11-10 16:40:37 -060099 help="Task file for benchmark"
100 )
Alex2a7657c2021-11-10 20:51:34 -0600101 ceph_bench_parser.add_argument(
102 '--no-cleanup',
103 action="store_true", default=False,
104 help="Do not cleanup services, agents, pvc, and pv"
105 )
Alexb2129542021-11-23 15:49:42 -0600106 ceph_bench_parser.add_argument(
107 '--cleanup-only',
108 action="store_true", default=False,
109 help="Cleanup resources related to benchmark"
110 )
111 ceph_bench_parser.add_argument(
112 '--dump-path',
113 metavar="dump_results", default="/tmp",
114 help="Dump result after each test run to use them later"
115 )
Alex90ac1532021-12-09 11:13:14 -0600116 ceph_bench_parser.add_argument(
117 '--name',
118 metavar="name", default="cephbench",
119 help="Dump result after each test run to use them later"
120 )
121 ceph_bench_parser.add_argument(
122 '--bs',
123 metavar="blocksize", default="16k",
124 help="Block size for single run"
125 )
126 ceph_bench_parser.add_argument(
127 '--iodepth',
128 metavar="iodepth", default="16",
129 help="IO Depth for single run"
130 )
131 ceph_bench_parser.add_argument(
132 '--size',
133 metavar="size", default="10G",
134 help="Persistent volume size (M, G)"
135 )
136 ceph_bench_parser.add_argument(
137 '--readwrite',
138 metavar="readwrite", default="randrw",
139 help="Test mode for single run"
140 )
141 ceph_bench_parser.add_argument(
142 '--rwmixread',
143 metavar="rwmixread", default="50",
144 help="Percent of read in randon mixed mode (randrw)"
145 )
146 ceph_bench_parser.add_argument(
147 '--ramp-time',
148 metavar="ramp_time", default="5s",
149 help="Warmup time before test"
150 )
151 ceph_bench_parser.add_argument(
152 '--runtime',
153 metavar="runtime", default="60s",
154 help="Time based test run longevity"
155 )
156 ceph_bench_parser.add_argument(
157 '--ioengine',
158 metavar="ioengine", default="libaio",
159 help="IO Engine used by fio. See eng-help output in fio for list"
160 )
161 ceph_bench_parser.add_argument(
162 '--offset-increment',
163 metavar="offset_increment", default="500M",
164 help="IO Engine used by fio. See eng-help output in fio for list"
165 )
Alexdcb792f2021-10-04 14:24:21 -0500166
167 return _parser
168
169
170def do_info(args, config):
171 # Ceph info
172 # Gather ceph info and create an archive with data
173 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
174 # check tgz
175 _tgzfile = "ceph_info_archive.tgz" if not args.tgz else args.tgz
176
177 # _class = _selectClass(_env)
178 ceph_info = info.KubeCephInfo(config)
179
180 logger_cli.info("# Collecting Ceph cluster information")
Alexdcb792f2021-10-04 14:24:21 -0500181 ceph_info.gather_info()
182
183 # Debug, enable if needed to debug report generation
184 # without actuall data collecting each time
185 # ceph_info.dump_info()
186 # ceph_info.load_info()
187 # end debug
188
Alexdcb792f2021-10-04 14:24:21 -0500189 ceph_info.generate_archive(_tgzfile)
Alexdf9cc3a2021-10-12 14:37:28 -0500190 ceph_info.print_summary()
Alexdcb792f2021-10-04 14:24:21 -0500191
192 return
193
194
195def do_report(args, config):
196 # Ceph Report
197 # Gather ceph info and create HTML report with all of the data
198 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
199 _filename = args_utils.get_arg(args, 'html')
200 logger_cli.info("# Ceph cluster Configuration report")
Alexdcb792f2021-10-04 14:24:21 -0500201
202 # _class = _selectClass(_env)
203 ceph_info = info.KubeCephInfo(config)
204 # Debug, enable if needed to debug report generation
205 # without actuall data collecting each time
206 # ceph_info.load_info()
207 # end debug
208 ceph_info.gather_info()
209 ceph_info.get_transposed_latency_table()
210 ceph_info.get_latest_health_readout()
211 ceph_info.create_html_report(_filename)
212
213 return
214
215
216def do_bench(args, config):
217 # Ceph Benchmark using multiple pods
Alexb2129542021-11-23 15:49:42 -0600218 # if only cleanup needed do it and exit
219 _cleanup_only = args_utils.get_arg(args, 'cleanup_only')
220 config.resource_prefix = "cfgagent"
221 if _cleanup_only:
222 # Do forced resource cleanup and exit
223 config.bench_mode = "cleanup"
224 config.bench_agent_count = -1
225 ceph_bench = bench.KubeCephBench(config)
226 logger_cli.info(
227 "# Discovering benchmark resources using prefix of '{}'".format(
228 config.resource_prefix
229 )
230 )
231 ceph_bench.prepare_cleanup()
232 ceph_bench.cleanup()
233 return
234
235 # gather Ceph info
236 logger_cli.info("# Collecting Ceph cluster information")
237 ceph_info = info.KubeCephInfo(config)
238
Alex5cace3b2021-11-10 16:40:37 -0600239 # Prepare the tasks and do synced testrun or a single one
Alexb2129542021-11-23 15:49:42 -0600240 logger_cli.info("# Initializing ceph benchmark module")
Alexdcb792f2021-10-04 14:24:21 -0500241 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
Alex90ac1532021-12-09 11:13:14 -0600242 # Report filename
Alex5cace3b2021-11-10 16:40:37 -0600243 _filename = args_utils.get_arg(args, 'html')
244 # agents count option
Alex2a7657c2021-11-10 20:51:34 -0600245 config.bench_agent_count = args_utils.get_arg(args, "agents")
246 logger_cli.info("-> using {} agents".format(config.bench_agent_count))
Alex90ac1532021-12-09 11:13:14 -0600247 # Cleaning option
Alex2a7657c2021-11-10 20:51:34 -0600248 config.no_cleaning_after_benchmark = args_utils.get_arg(args, "no_cleanup")
Alex5cace3b2021-11-10 16:40:37 -0600249 # storage class
250 _storage_class = args_utils.get_arg(args, "storage_class")
251 logger_cli.info("-> using storage class of '{}'".format(_storage_class))
252 config.bench_storage_class = _storage_class
Alexb2129542021-11-23 15:49:42 -0600253 # dump results options
254 _dump_path = args_utils.get_arg(args, "dump_path")
255 if _dump_path:
256 logger_cli.info("# Results will be dumped to '{}'".format(_dump_path))
257 config.bench_results_dump_path = _dump_path
258 else:
259 logger_cli.info(
260 "# No result dump path set. "
261 "Consider setting it if running long task_file based test runs"
262 )
263 config.bench_results_dump_path = _dump_path
Alex5cace3b2021-11-10 16:40:37 -0600264 # Task files or options
Alex90ac1532021-12-09 11:13:14 -0600265 _opts = get_fio_options()
Alex5cace3b2021-11-10 16:40:37 -0600266 _task_file = args_utils.get_arg(args, "task_file", nofail=True)
267 if not _task_file:
Alex90ac1532021-12-09 11:13:14 -0600268 logger_cli.info("-> Running single benchmark run")
Alex5cace3b2021-11-10 16:40:37 -0600269 config.bench_mode = "single"
Alex90ac1532021-12-09 11:13:14 -0600270 # Updating _opts from arguments
271 _params = [
272 "bs",
273 "iodepth",
274 "size",
275 "readwrite",
276 "ramp_time",
277 "runtime",
278 "ioengine"
279 ]
280 for _p in _params:
281 _opts[_p] = _get_param_and_log(args, _p)
282 if _opts["readwrite"] in seq_modes:
283 _p = "offset_increment"
284 _opts[_p] = _get_param_and_log(args, _p)
285 elif _opts["readwrite"] in mix_modes:
286 _p = "rwmixread"
287 _opts[_p] = _get_param_and_log(args, _p)
Alex5cace3b2021-11-10 16:40:37 -0600288 else:
289 logger_cli.info("-> running with tasks from '{}'".format(_task_file))
290 config.bench_task_file = _task_file
291 config.bench_mode = "tasks"
Alex90ac1532021-12-09 11:13:14 -0600292 config.bench_name = args_utils.get_arg(args, "name")
293 _opts["name"] = config.bench_name
294 logger_cli.info(
295 "# Using '{}' as ceph bench jobs name".format(_opts["name"])
296 )
Alex5cace3b2021-11-10 16:40:37 -0600297 logger_cli.debug("... default/selected options for fio:")
298 for _k in _opts.keys():
299 # TODO: Update options for single run
300 logger_cli.debug(" {} = {}".format(_k, _opts[_k]))
Alexdcb792f2021-10-04 14:24:21 -0500301
Alex3034ba52021-11-13 17:06:45 -0600302 # handle option inavailability from command line for single mode
303
304 # init the Bench class
Alexdcb792f2021-10-04 14:24:21 -0500305 ceph_bench = bench.KubeCephBench(config)
Alexb2129542021-11-23 15:49:42 -0600306 ceph_bench.set_ceph_info_class(ceph_info)
Alex90ac1532021-12-09 11:13:14 -0600307 # Preload previous results for this name
308 ceph_bench.preload_results()
Alexdcb792f2021-10-04 14:24:21 -0500309 # Do the testrun
Alex5cace3b2021-11-10 16:40:37 -0600310 ceph_bench.prepare_agents(_opts)
Alexb2129542021-11-23 15:49:42 -0600311 ceph_bench.wait_ceph_cooldown()
312
313 # DEBUG of report in progress
Alex5cace3b2021-11-10 16:40:37 -0600314 if not ceph_bench.run_benchmark(_opts):
Alex2a7657c2021-11-10 20:51:34 -0600315 # No cleaning and/or report if benchmark was not finished
Alexbfa947c2021-11-11 18:14:28 -0600316 logger_cli.info("# Abnormal benchmark run, no cleaning performed")
Alex5cace3b2021-11-10 16:40:37 -0600317 return
Alexb2129542021-11-23 15:49:42 -0600318 # Remove after DEBUG
319 # ceph_bench.collect_results(_opts)
320 # END DEBUG
321
Alex3034ba52021-11-13 17:06:45 -0600322 # Cleaning
Alex2a7657c2021-11-10 20:51:34 -0600323 if not config.no_cleaning_after_benchmark:
324 ceph_bench.cleanup()
Alexbfa947c2021-11-11 18:14:28 -0600325 else:
326 logger_cli.info(
327 "# '--no-cleaning' option set. Cleaning not conducted."
328 )
Alexdcb792f2021-10-04 14:24:21 -0500329
330 # Create report
Alex5cace3b2021-11-10 16:40:37 -0600331 ceph_bench.create_report(_filename)
Alexdcb792f2021-10-04 14:24:21 -0500332
333 return