|
| 1 | +""" |
| 2 | +FIO processor: multi-metric extraction (bandwidth, IOPS, latency). |
| 3 | +
|
| 4 | +Tests that FIO extracts all three coequal metrics as primary_metrics. |
| 5 | +""" |
| 6 | + |
| 7 | +import pytest |
| 8 | +import json |
| 9 | +from pathlib import Path |
| 10 | +from unittest.mock import patch |
| 11 | + |
| 12 | +from chronicler.processors.fio_processor import FioProcessor |
| 13 | +from chronicler.processors.base_processor import ProcessorError |
| 14 | +from chronicler.schema import Run |
| 15 | + |
| 16 | +pytestmark = pytest.mark.unit |
| 17 | + |
| 18 | + |
| 19 | +def test_fio_extracts_all_three_primary_metrics(result_dir): |
| 20 | + """ |
| 21 | + FIO should extract bandwidth, IOPS, and latency as primary_metrics. |
| 22 | +
|
| 23 | + Test validates RPOPC-1304: multi-metric support for FIO. |
| 24 | + """ |
| 25 | + # Create FIO results JSON with multiple runs to test mean calculation |
| 26 | + # Run 0: read-4KiB workload |
| 27 | + fio_data_run0 = { |
| 28 | + "timestamp": 1707004800, # 2024-02-04 00:00:00 UTC |
| 29 | + "jobs": [ |
| 30 | + { |
| 31 | + "jobname": "job0", |
| 32 | + "read": { |
| 33 | + "bw": 500000, |
| 34 | + "iops": 125000, |
| 35 | + "io_bytes": 1024000000, |
| 36 | + "total_ios": 250000, |
| 37 | + "lat_ns": { |
| 38 | + "mean": 120000, |
| 39 | + "min": 100000, |
| 40 | + "max": 150000 |
| 41 | + }, |
| 42 | + "clat_ns": { |
| 43 | + "mean": 118000, |
| 44 | + "min": 98000, |
| 45 | + "max": 148000 |
| 46 | + }, |
| 47 | + "slat_ns": { |
| 48 | + "mean": 2000, |
| 49 | + "min": 1000, |
| 50 | + "max": 3000 |
| 51 | + } |
| 52 | + }, |
| 53 | + "elapsed": 60 |
| 54 | + } |
| 55 | + ] |
| 56 | + } |
| 57 | + |
| 58 | + # Run 1: read-1024KiB workload (different metrics) |
| 59 | + fio_data_run1 = { |
| 60 | + "timestamp": 1707004920, # 2024-02-04 00:02:00 UTC |
| 61 | + "jobs": [ |
| 62 | + { |
| 63 | + "jobname": "job0", |
| 64 | + "read": { |
| 65 | + "bw": 800000, |
| 66 | + "iops": 200000, |
| 67 | + "io_bytes": 2048000000, |
| 68 | + "total_ios": 500000, |
| 69 | + "lat_ns": { |
| 70 | + "mean": 140000, |
| 71 | + "min": 120000, |
| 72 | + "max": 170000 |
| 73 | + }, |
| 74 | + "clat_ns": { |
| 75 | + "mean": 138000, |
| 76 | + "min": 118000, |
| 77 | + "max": 168000 |
| 78 | + }, |
| 79 | + "slat_ns": { |
| 80 | + "mean": 2000, |
| 81 | + "min": 1000, |
| 82 | + "max": 3000 |
| 83 | + } |
| 84 | + }, |
| 85 | + "elapsed": 60 |
| 86 | + } |
| 87 | + ] |
| 88 | + } |
| 89 | + |
| 90 | + # Create directory structure for two workloads |
| 91 | + export_dir = result_dir / "export_fio_data_test" |
| 92 | + export_dir.mkdir() |
| 93 | + |
| 94 | + config_dir = export_dir / "fio_ndisks_1_disksize_10_GiB_njobs_1_ioengine_libaio_iodepth_16_2024.02.04T00.00.00" |
| 95 | + config_dir.mkdir() |
| 96 | + |
| 97 | + # Workload 0 |
| 98 | + workload0_dir = config_dir / "1-read-4KiB" |
| 99 | + workload0_dir.mkdir() |
| 100 | + (workload0_dir / "fio-results.json").write_text(json.dumps(fio_data_run0)) |
| 101 | + |
| 102 | + # Workload 1 |
| 103 | + workload1_dir = config_dir / "2-read-1024KiB" |
| 104 | + workload1_dir.mkdir() |
| 105 | + (workload1_dir / "fio-results.json").write_text(json.dumps(fio_data_run1)) |
| 106 | + |
| 107 | + # Create test_results_report (status) |
| 108 | + (export_dir / "test_results_report").write_text("Ran 2 tests") |
| 109 | + |
| 110 | + # Create dummy zip |
| 111 | + dummy_zip = result_dir / "results_fio.zip" |
| 112 | + dummy_zip.write_bytes(b"") |
| 113 | + |
| 114 | + # Process FIO results |
| 115 | + processor = FioProcessor(str(result_dir)) |
| 116 | + extracted_result = {"files": {}, "extracted_path": str(result_dir)} |
| 117 | + |
| 118 | + # Mock archive extraction and call build_results |
| 119 | + with patch.object(processor.archive_handler, "extract_result_archive") as mock_extract: |
| 120 | + mock_extract.return_value = extracted_result |
| 121 | + results = processor.build_results() |
| 122 | + |
| 123 | + # Verify primary_metrics exists and has 3 metrics |
| 124 | + assert results.primary_metrics is not None, "primary_metrics should not be None" |
| 125 | + assert len(results.primary_metrics) == 3, f"Expected 3 metrics, got {len(results.primary_metrics)}" |
| 126 | + |
| 127 | + # Extract metric names and values |
| 128 | + metrics_by_name = {m.name: m for m in results.primary_metrics} |
| 129 | + |
| 130 | + # Verify all three metrics are present |
| 131 | + assert "bandwidth" in metrics_by_name, "bandwidth metric missing" |
| 132 | + assert "iops" in metrics_by_name, "iops metric missing" |
| 133 | + assert "latency" in metrics_by_name, "latency metric missing" |
| 134 | + |
| 135 | + # Verify units are correct |
| 136 | + assert metrics_by_name["bandwidth"].unit == "KiB/s" |
| 137 | + assert metrics_by_name["iops"].unit == "IOPS" |
| 138 | + assert metrics_by_name["latency"].unit == "nanoseconds" |
| 139 | + |
| 140 | + # Verify values are means across both runs |
| 141 | + # Bandwidth mean: (500000 + 800000) / 2 = 650000 |
| 142 | + assert metrics_by_name["bandwidth"].value == 650000.0 |
| 143 | + |
| 144 | + # IOPS mean: (125000 + 200000) / 2 = 162500 |
| 145 | + assert metrics_by_name["iops"].value == 162500.0 |
| 146 | + |
| 147 | + # Latency mean: (120000 + 140000) / 2 = 130000 |
| 148 | + assert metrics_by_name["latency"].value == 130000.0 |
| 149 | + |
| 150 | + |
| 151 | +def test_fio_handles_single_run(result_dir): |
| 152 | + """ |
| 153 | + FIO should extract metrics correctly from single run. |
| 154 | +
|
| 155 | + No averaging needed when only one run exists. |
| 156 | + """ |
| 157 | + fio_data = { |
| 158 | + "timestamp": 1707004800, |
| 159 | + "jobs": [ |
| 160 | + { |
| 161 | + "jobname": "job0", |
| 162 | + "read": { |
| 163 | + "bw": 600000, |
| 164 | + "iops": 150000, |
| 165 | + "io_bytes": 1024000000, |
| 166 | + "total_ios": 250000, |
| 167 | + "lat_ns": { |
| 168 | + "mean": 125000, |
| 169 | + "min": 110000, |
| 170 | + "max": 160000 |
| 171 | + }, |
| 172 | + "clat_ns": { |
| 173 | + "mean": 123000, |
| 174 | + "min": 108000, |
| 175 | + "max": 158000 |
| 176 | + }, |
| 177 | + "slat_ns": { |
| 178 | + "mean": 2000, |
| 179 | + "min": 1000, |
| 180 | + "max": 3000 |
| 181 | + } |
| 182 | + }, |
| 183 | + "elapsed": 60 |
| 184 | + } |
| 185 | + ] |
| 186 | + } |
| 187 | + |
| 188 | + # Create proper directory structure (needed for operation type detection) |
| 189 | + export_dir = result_dir / "export_fio_data_test" |
| 190 | + export_dir.mkdir() |
| 191 | + |
| 192 | + config_dir = export_dir / "fio_ndisks_1_disksize_10_GiB_njobs_1_ioengine_libaio_iodepth_16_2024.02.04T00.00.00" |
| 193 | + config_dir.mkdir() |
| 194 | + |
| 195 | + workload_dir = config_dir / "1-read-4KiB" |
| 196 | + workload_dir.mkdir() |
| 197 | + (workload_dir / "fio-results.json").write_text(json.dumps(fio_data)) |
| 198 | + |
| 199 | + (export_dir / "test_results_report").write_text("Ran 1 test") |
| 200 | + |
| 201 | + dummy_zip = result_dir / "results_fio.zip" |
| 202 | + dummy_zip.write_bytes(b"") |
| 203 | + |
| 204 | + processor = FioProcessor(str(result_dir)) |
| 205 | + extracted_result = {"files": {}, "extracted_path": str(result_dir)} |
| 206 | + |
| 207 | + with patch.object(processor.archive_handler, "extract_result_archive") as mock_extract: |
| 208 | + mock_extract.return_value = extracted_result |
| 209 | + results = processor.build_results() |
| 210 | + |
| 211 | + # Should have exactly 3 metrics from single run |
| 212 | + assert results.primary_metrics is not None |
| 213 | + assert len(results.primary_metrics) == 3 |
| 214 | + |
| 215 | + metrics_by_name = {m.name: m for m in results.primary_metrics} |
| 216 | + |
| 217 | + # Values should match the single run (no averaging) |
| 218 | + assert metrics_by_name["bandwidth"].value == 600000.0 |
| 219 | + assert metrics_by_name["iops"].value == 150000.0 |
| 220 | + assert metrics_by_name["latency"].value == 125000.0 |
0 commit comments