blob: e2f00491bfa838a52d60435ceafe0cc74c0dc4a3 [file] [log] [blame]
Alex0989ecf2022-03-29 13:43:21 -05001# Author: Alex Savatieiev (osavatieiev@mirantis.com; a.savex@gmail.com)
2# Copyright 2019-2022 Mirantis, Inc.
Alexeb934de2022-10-06 13:49:30 -05003from datetime import datetime
4
Alex5cace3b2021-11-10 16:40:37 -06005from cfg_checker.agent.fio_runner import get_fio_options
Alex90ac1532021-12-09 11:13:14 -06006from cfg_checker.agent.fio_runner import seq_modes, mix_modes
Alexdcb792f2021-10-04 14:24:21 -05007from cfg_checker.common import logger_cli
8from cfg_checker.common.settings import ENV_TYPE_KUBE
9from cfg_checker.helpers import args_utils
10from cfg_checker.modules.ceph import info, bench
11
Alexeb934de2022-10-06 13:49:30 -050012
Alexdcb792f2021-10-04 14:24:21 -050013command_help = "Ceph Storage information and benchmarks"
14supported_envs = [ENV_TYPE_KUBE]
15
16
17# def _selectClass(_env, strClassHint="checker"):
18# _class = None
19# if _env == ENV_TYPE_SALT:
20# if strClassHint == "info":
21# _class = info.SaltCephInfo
22# elif strClassHint == "bench":
23# _class = bench.SaltCephInfo
24# elif _env == ENV_TYPE_KUBE:
25# if strClassHint == "info":
26# _class = info.KubeCephInfo
27# elif strClassHint == "bench":
28# _class = bench.KubeCephBench
29# if not _class:
30# raise CheckerException(
31# "Unknown hint for selecting Ceph handler Class: '{}'".format(
32# strClassHint
33# )
34# )
35# else:
36# return _class
37
Alex90ac1532021-12-09 11:13:14 -060038def _get_param_and_log(arg, param_str):
39 _value = args_utils.get_arg(arg, param_str)
40 logger_cli.info(" {}={}".format(param_str, _value))
41 return _value
42
Alexdcb792f2021-10-04 14:24:21 -050043
44def init_parser(_parser):
45 # network subparser
46 ceph_subparsers = _parser.add_subparsers(dest='type')
47
48 ceph_info_parser = ceph_subparsers.add_parser(
49 'info',
50 help="Gather Ceph Cluster information"
51 )
52
53 ceph_info_parser.add_argument(
54 '--detailed',
55 action="store_true", default=False,
Alex30a00642021-12-30 14:20:48 -060056 help="Print additional details. (Not implemented yet)"
Alexdcb792f2021-10-04 14:24:21 -050057 )
58
59 ceph_info_parser.add_argument(
Alexeb934de2022-10-06 13:49:30 -050060 '--client-name',
61 metavar='client_name',
62 help="Client name for archive naming"
Alexdcb792f2021-10-04 14:24:21 -050063 )
64
Alexeb934de2022-10-06 13:49:30 -050065 ceph_info_parser.add_argument(
66 '--project-name',
67 metavar='projectname',
68 help="Project name for archive naming"
Alexdcb792f2021-10-04 14:24:21 -050069 )
70
Alexeb934de2022-10-06 13:49:30 -050071 ceph_info_parser.add_argument(
Alexdcb792f2021-10-04 14:24:21 -050072 '--html',
73 metavar='ceph_html_filename',
74 help="HTML filename to save report"
75 )
76
77 ceph_bench_parser = ceph_subparsers.add_parser(
78 'bench',
79 help="Run ceph benchmark"
80 )
81
82 ceph_bench_parser.add_argument(
Alex5cace3b2021-11-10 16:40:37 -060083 '--agents',
84 type=int, metavar='agent_count', default=5,
Alex30a00642021-12-30 14:20:48 -060085 help="Number of agents to use in all test runs. Default: 5"
Alex5cace3b2021-11-10 16:40:37 -060086 )
87 ceph_bench_parser.add_argument(
88 '--html',
89 metavar='ceph_html_filename',
90 help="HTML filename to save report"
91 )
92 ceph_bench_parser.add_argument(
93 '--storage-class',
94 metavar='storage_class',
95 help="Storage class to be used in benchmark"
96 )
97 ceph_bench_parser.add_argument(
98 '--task-file',
Alexb2129542021-11-23 15:49:42 -060099 metavar='task_file',
Alex30a00642021-12-30 14:20:48 -0600100 help="Task file for benchmark with parameters to use"
Alex5cace3b2021-11-10 16:40:37 -0600101 )
Alex2a7657c2021-11-10 20:51:34 -0600102 ceph_bench_parser.add_argument(
103 '--no-cleanup',
104 action="store_true", default=False,
105 help="Do not cleanup services, agents, pvc, and pv"
106 )
Alexb2129542021-11-23 15:49:42 -0600107 ceph_bench_parser.add_argument(
108 '--cleanup-only',
109 action="store_true", default=False,
110 help="Cleanup resources related to benchmark"
111 )
112 ceph_bench_parser.add_argument(
Alex30380a42021-12-20 16:11:20 -0600113 '--report-only',
114 action="store_true", default=False,
Alex30a00642021-12-30 14:20:48 -0600115 help="Just create report using files in '--dump-path' folder"
Alex30380a42021-12-20 16:11:20 -0600116 )
117 ceph_bench_parser.add_argument(
Alexb2129542021-11-23 15:49:42 -0600118 '--dump-path',
Alex30380a42021-12-20 16:11:20 -0600119 metavar="dump_results",
Alex30a00642021-12-30 14:20:48 -0600120 help="Dump result after each test run to use them later. "
121 "Default: '/tmp'"
Alexb2129542021-11-23 15:49:42 -0600122 )
Alex90ac1532021-12-09 11:13:14 -0600123 ceph_bench_parser.add_argument(
124 '--name',
125 metavar="name", default="cephbench",
Alex30a00642021-12-30 14:20:48 -0600126 help="Job name to use for running fio. "
127 "Can be used to grep results. Default: 'cephbench'"
Alex90ac1532021-12-09 11:13:14 -0600128 )
129 ceph_bench_parser.add_argument(
130 '--bs',
131 metavar="blocksize", default="16k",
Alex30a00642021-12-30 14:20:48 -0600132 help="Block size for single run. Default: '16k'"
Alex90ac1532021-12-09 11:13:14 -0600133 )
134 ceph_bench_parser.add_argument(
135 '--iodepth',
136 metavar="iodepth", default="16",
Alex30a00642021-12-30 14:20:48 -0600137 help="IO Depth for single run. Default: '16'"
Alex90ac1532021-12-09 11:13:14 -0600138 )
139 ceph_bench_parser.add_argument(
140 '--size',
141 metavar="size", default="10G",
Alex30a00642021-12-30 14:20:48 -0600142 help="Persistent volume size (M, G). Default: '10G'"
Alex90ac1532021-12-09 11:13:14 -0600143 )
144 ceph_bench_parser.add_argument(
145 '--readwrite',
146 metavar="readwrite", default="randrw",
Alex30a00642021-12-30 14:20:48 -0600147 help="Test mode for single run (read, write, randrw, "
148 "randread, randwrite). Default: 'randrw'"
Alex90ac1532021-12-09 11:13:14 -0600149 )
150 ceph_bench_parser.add_argument(
151 '--rwmixread',
152 metavar="rwmixread", default="50",
Alex30a00642021-12-30 14:20:48 -0600153 help="Percent of read in random mixed mode (randrw). Default: '50'"
Alex90ac1532021-12-09 11:13:14 -0600154 )
155 ceph_bench_parser.add_argument(
156 '--ramp-time',
157 metavar="ramp_time", default="5s",
Alex30a00642021-12-30 14:20:48 -0600158 help="Warmup time before test. Default: '5s'"
Alex90ac1532021-12-09 11:13:14 -0600159 )
160 ceph_bench_parser.add_argument(
161 '--runtime',
162 metavar="runtime", default="60s",
Alex30a00642021-12-30 14:20:48 -0600163 help="How long to run test. Default: '60s'"
Alex90ac1532021-12-09 11:13:14 -0600164 )
165 ceph_bench_parser.add_argument(
166 '--ioengine',
167 metavar="ioengine", default="libaio",
Alex30a00642021-12-30 14:20:48 -0600168 help="IO Engine used by fio. See 'fio eng-help' output for list. "
169 "Default: 'libaio'"
Alex90ac1532021-12-09 11:13:14 -0600170 )
171 ceph_bench_parser.add_argument(
172 '--offset-increment',
173 metavar="offset_increment", default="500M",
Alex41dd0cc2022-02-09 17:33:23 -0600174 help="Offset to be used in 'read' and 'write' modes if multiple jobs "
175 "used"
Alex30a00642021-12-30 14:20:48 -0600176 "Default: '500M'"
Alex90ac1532021-12-09 11:13:14 -0600177 )
Alexdcb792f2021-10-04 14:24:21 -0500178
179 return _parser
180
181
182def do_info(args, config):
183 # Ceph info
184 # Gather ceph info and create an archive with data
185 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
Alexdcb792f2021-10-04 14:24:21 -0500186
Alexeb934de2022-10-06 13:49:30 -0500187 # check client and project names
188 if not args.client_name or not args.project_name:
189 logger_cli.error(
190 "ERROR: Missing '--client-name' or '--project-name' options"
191 )
192 return
Alexdcb792f2021-10-04 14:24:21 -0500193 # _class = _selectClass(_env)
194 ceph_info = info.KubeCephInfo(config)
Alexeb934de2022-10-06 13:49:30 -0500195 _tgzfilename = ceph_info.get_info_archive_filename(
196 args.client_name,
197 args.project_name
198 )
199 logger_cli.info("# Archive will be generated to '{}'".format(_tgzfilename))
200 # get html
201 _htmlfilename = args_utils.get_arg(args, 'html')
Alexdcb792f2021-10-04 14:24:21 -0500202
203 logger_cli.info("# Collecting Ceph cluster information")
Alexdcb792f2021-10-04 14:24:21 -0500204 ceph_info.gather_info()
Alex41dd0cc2022-02-09 17:33:23 -0600205 ceph_info.gather_osd_configs()
Alexdcb792f2021-10-04 14:24:21 -0500206
207 # Debug, enable if needed to debug report generation
208 # without actuall data collecting each time
209 # ceph_info.dump_info()
210 # ceph_info.load_info()
211 # end debug
212
Alexdcb792f2021-10-04 14:24:21 -0500213 ceph_info.get_transposed_latency_table()
214 ceph_info.get_latest_health_readout()
Alexeb934de2022-10-06 13:49:30 -0500215 ceph_info.create_html_report(_htmlfilename)
216
217 # handle cli part
218 ceph_info.generate_archive(_tgzfilename)
219 ceph_info.print_summary()
Alexdcb792f2021-10-04 14:24:21 -0500220
221 return
222
223
224def do_bench(args, config):
225 # Ceph Benchmark using multiple pods
Alexb2129542021-11-23 15:49:42 -0600226 # if only cleanup needed do it and exit
227 _cleanup_only = args_utils.get_arg(args, 'cleanup_only')
Alex30380a42021-12-20 16:11:20 -0600228 _report_only = args_utils.get_arg(args, 'report_only')
Alexb2129542021-11-23 15:49:42 -0600229 config.resource_prefix = "cfgagent"
230 if _cleanup_only:
231 # Do forced resource cleanup and exit
232 config.bench_mode = "cleanup"
233 config.bench_agent_count = -1
234 ceph_bench = bench.KubeCephBench(config)
235 logger_cli.info(
236 "# Discovering benchmark resources using prefix of '{}'".format(
237 config.resource_prefix
238 )
239 )
240 ceph_bench.prepare_cleanup()
241 ceph_bench.cleanup()
242 return
243
Alex30380a42021-12-20 16:11:20 -0600244 # dump results options
245 _dump_path = args_utils.get_arg(args, "dump_path")
246 if _dump_path:
247 logger_cli.info("# Results will be dumped to '{}'".format(_dump_path))
248 config.bench_results_dump_path = _dump_path
249 else:
250 _p = "/tmp"
251 logger_cli.info(
252 "# No result dump path set. Defaulting to {}"
253 "Consider setting it if running long task_file "
254 "based test runs".format(_p)
255 )
256 config.bench_results_dump_path = _p
257
258 # Report filename
259 _filename = args_utils.get_arg(args, 'html')
Alexb2129542021-11-23 15:49:42 -0600260 # gather Ceph info
261 logger_cli.info("# Collecting Ceph cluster information")
262 ceph_info = info.KubeCephInfo(config)
263
Alex30380a42021-12-20 16:11:20 -0600264 # Task files or options
265 _opts = get_fio_options()
266 # Load name and announce it
267 config.bench_name = args_utils.get_arg(args, "name")
268 _opts["name"] = config.bench_name
269 logger_cli.info(
270 "# Using '{}' as ceph bench jobs name".format(_opts["name"])
271 )
272
273 if _report_only:
274 # Do forced report creation and exit
275 config.bench_mode = "report"
276 config.bench_agent_count = -1
277 ceph_bench = bench.KubeCephBench(config)
278 ceph_bench.set_ceph_info_class(ceph_info)
279 logger_cli.info(
280 "# Preparing to generate report '{}'".format(
281 config.resource_prefix
282 )
283 )
284 # Preload previous results for this name
285 ceph_bench.preload_results()
286 # Gather ceph data
287 ceph_bench.wait_ceph_cooldown()
288 # Generate report
289 ceph_bench.create_report(_filename)
290 return
291
Alex5cace3b2021-11-10 16:40:37 -0600292 # Prepare the tasks and do synced testrun or a single one
Alexb2129542021-11-23 15:49:42 -0600293 logger_cli.info("# Initializing ceph benchmark module")
Alexdcb792f2021-10-04 14:24:21 -0500294 args_utils.check_supported_env(ENV_TYPE_KUBE, args, config)
Alex5cace3b2021-11-10 16:40:37 -0600295 # agents count option
Alex2a7657c2021-11-10 20:51:34 -0600296 config.bench_agent_count = args_utils.get_arg(args, "agents")
297 logger_cli.info("-> using {} agents".format(config.bench_agent_count))
Alex90ac1532021-12-09 11:13:14 -0600298 # Cleaning option
Alex2a7657c2021-11-10 20:51:34 -0600299 config.no_cleaning_after_benchmark = args_utils.get_arg(args, "no_cleanup")
Alex5cace3b2021-11-10 16:40:37 -0600300 # storage class
301 _storage_class = args_utils.get_arg(args, "storage_class")
302 logger_cli.info("-> using storage class of '{}'".format(_storage_class))
303 config.bench_storage_class = _storage_class
Alexb2129542021-11-23 15:49:42 -0600304 if _dump_path:
305 logger_cli.info("# Results will be dumped to '{}'".format(_dump_path))
306 config.bench_results_dump_path = _dump_path
307 else:
308 logger_cli.info(
309 "# No result dump path set. "
310 "Consider setting it if running long task_file based test runs"
311 )
312 config.bench_results_dump_path = _dump_path
Alex30380a42021-12-20 16:11:20 -0600313
Alex5cace3b2021-11-10 16:40:37 -0600314 _task_file = args_utils.get_arg(args, "task_file", nofail=True)
315 if not _task_file:
Alex90ac1532021-12-09 11:13:14 -0600316 logger_cli.info("-> Running single benchmark run")
Alex5cace3b2021-11-10 16:40:37 -0600317 config.bench_mode = "single"
Alex90ac1532021-12-09 11:13:14 -0600318 # Updating _opts from arguments
319 _params = [
320 "bs",
321 "iodepth",
322 "size",
323 "readwrite",
324 "ramp_time",
325 "runtime",
326 "ioengine"
327 ]
328 for _p in _params:
329 _opts[_p] = _get_param_and_log(args, _p)
330 if _opts["readwrite"] in seq_modes:
331 _p = "offset_increment"
332 _opts[_p] = _get_param_and_log(args, _p)
333 elif _opts["readwrite"] in mix_modes:
334 _p = "rwmixread"
335 _opts[_p] = _get_param_and_log(args, _p)
Alex5cace3b2021-11-10 16:40:37 -0600336 else:
337 logger_cli.info("-> running with tasks from '{}'".format(_task_file))
338 config.bench_task_file = _task_file
339 config.bench_mode = "tasks"
Alex5cace3b2021-11-10 16:40:37 -0600340 logger_cli.debug("... default/selected options for fio:")
341 for _k in _opts.keys():
342 # TODO: Update options for single run
343 logger_cli.debug(" {} = {}".format(_k, _opts[_k]))
Alexdcb792f2021-10-04 14:24:21 -0500344
Alex3034ba52021-11-13 17:06:45 -0600345 # init the Bench class
Alexdcb792f2021-10-04 14:24:21 -0500346 ceph_bench = bench.KubeCephBench(config)
Alexb2129542021-11-23 15:49:42 -0600347 ceph_bench.set_ceph_info_class(ceph_info)
Alex90ac1532021-12-09 11:13:14 -0600348 # Preload previous results for this name
349 ceph_bench.preload_results()
Alexdcb792f2021-10-04 14:24:21 -0500350 # Do the testrun
Alex5cace3b2021-11-10 16:40:37 -0600351 ceph_bench.prepare_agents(_opts)
Alexb2129542021-11-23 15:49:42 -0600352 ceph_bench.wait_ceph_cooldown()
353
354 # DEBUG of report in progress
Alex5cace3b2021-11-10 16:40:37 -0600355 if not ceph_bench.run_benchmark(_opts):
Alex2a7657c2021-11-10 20:51:34 -0600356 # No cleaning and/or report if benchmark was not finished
Alexbfa947c2021-11-11 18:14:28 -0600357 logger_cli.info("# Abnormal benchmark run, no cleaning performed")
Alex5cace3b2021-11-10 16:40:37 -0600358 return
Alexb2129542021-11-23 15:49:42 -0600359 # Remove after DEBUG
360 # ceph_bench.collect_results(_opts)
361 # END DEBUG
362
Alex3034ba52021-11-13 17:06:45 -0600363 # Cleaning
Alex2a7657c2021-11-10 20:51:34 -0600364 if not config.no_cleaning_after_benchmark:
365 ceph_bench.cleanup()
Alexbfa947c2021-11-11 18:14:28 -0600366 else:
367 logger_cli.info(
368 "# '--no-cleaning' option set. Cleaning not conducted."
369 )
Alexdcb792f2021-10-04 14:24:21 -0500370
371 # Create report
Alex5cace3b2021-11-10 16:40:37 -0600372 ceph_bench.create_report(_filename)
Alexdcb792f2021-10-04 14:24:21 -0500373
374 return