mdbkit 0.5.2__tar.gz → 0.5.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mdbkit-0.5.2 → mdbkit-0.5.5}/PKG-INFO +51 -21
- {mdbkit-0.5.2 → mdbkit-0.5.5}/README.md +50 -20
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/__init__.py +1 -1
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/render.py +14 -7
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/PKG-INFO +51 -21
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/SOURCES.txt +1 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/pyproject.toml +1 -1
- mdbkit-0.5.5/tests/test_render_e2e.py +237 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/LICENSE +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/advisor.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/analysis.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/cli.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/compare.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/demo.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/explain.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/filtering.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/ftdc.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/lab.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/oslog.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/parser.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/rebuild.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/report.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/scripts.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/serverstatus.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit/triage.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/dependency_links.txt +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/entry_points.txt +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/requires.txt +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/mdbkit.egg-info/top_level.txt +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/setup.cfg +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_demo_lab.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_explain.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_ftdc.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_mdbkit.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_oslog_serverstatus.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_rebuild_report.py +0 -0
- {mdbkit-0.5.2 → mdbkit-0.5.5}/tests/test_triage.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdbkit
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.5
|
|
4
4
|
Summary: Offline toolkit for MongoDB 4.4+ structured logs: log analysis, slow-query shapes, connection churn, and deterministic index advice. A spiritual successor to mtools' log tools.
|
|
5
5
|
Author: Saqib Ameen Subhan
|
|
6
6
|
License: MIT
|
|
@@ -135,6 +135,25 @@ Full detail: [SECURITY.md](SECURITY.md).
|
|
|
135
135
|
|
|
136
136
|
## Install
|
|
137
137
|
|
|
138
|
+
### Linux
|
|
139
|
+
|
|
140
|
+
**Most distributions:**
|
|
141
|
+
```bash
|
|
142
|
+
pip install mdbkit
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
146
|
+
```bash
|
|
147
|
+
sudo apt install pipx # or: sudo dnf install pipx
|
|
148
|
+
pipx install mdbkit
|
|
149
|
+
pipx ensurepath && source ~/.bashrc
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
153
|
+
```bash
|
|
154
|
+
pip install mdbkit --break-system-packages
|
|
155
|
+
```
|
|
156
|
+
|
|
138
157
|
### macOS
|
|
139
158
|
|
|
140
159
|
macOS ships no `pip` and no `pipx`, so `pip install` fails out of the box.
|
|
@@ -173,25 +192,6 @@ problem entirely.
|
|
|
173
192
|
Do not install with `sudo`. mdbkit is a user-level CLI and needs no
|
|
174
193
|
elevated privileges — not to install, and not to run.
|
|
175
194
|
|
|
176
|
-
### Linux
|
|
177
|
-
|
|
178
|
-
**Most distributions:**
|
|
179
|
-
```bash
|
|
180
|
-
pip install mdbkit
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
184
|
-
```bash
|
|
185
|
-
sudo apt install pipx # or: sudo dnf install pipx
|
|
186
|
-
pipx install mdbkit
|
|
187
|
-
pipx ensurepath && source ~/.bashrc
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
191
|
-
```bash
|
|
192
|
-
pip install mdbkit --break-system-packages
|
|
193
|
-
```
|
|
194
|
-
|
|
195
195
|
### Windows
|
|
196
196
|
|
|
197
197
|
```powershell
|
|
@@ -215,11 +215,41 @@ resolve.
|
|
|
215
215
|
|
|
216
216
|
### Upgrading
|
|
217
217
|
|
|
218
|
+
Use whichever matches how you installed it.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Linux — installed with pip
|
|
222
|
+
pip install --upgrade mdbkit
|
|
223
|
+
|
|
224
|
+
# Linux — installed with pipx
|
|
225
|
+
pipx upgrade mdbkit
|
|
226
|
+
|
|
227
|
+
# macOS — installed with pipx (Homebrew route)
|
|
228
|
+
pipx upgrade mdbkit
|
|
229
|
+
|
|
230
|
+
# macOS — installed with python3 -m pip --user
|
|
231
|
+
python3 -m pip install --user --upgrade mdbkit
|
|
232
|
+
|
|
233
|
+
# macOS / Linux — installed with uv
|
|
234
|
+
uv tool upgrade mdbkit
|
|
235
|
+
|
|
236
|
+
# Windows
|
|
237
|
+
py -m pip install --upgrade mdbkit
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Then confirm:
|
|
218
241
|
```bash
|
|
219
|
-
pip install --upgrade mdbkit # or: pipx upgrade mdbkit
|
|
220
242
|
mdbkit --version
|
|
221
243
|
```
|
|
222
244
|
|
|
245
|
+
**If the version has not changed**, pip is serving a cached index. Force it:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
pipx install --force mdbkit # pipx
|
|
249
|
+
pip install --upgrade --no-cache-dir mdbkit # pip
|
|
250
|
+
py -m pip install --upgrade --no-cache-dir mdbkit # Windows
|
|
251
|
+
```
|
|
252
|
+
|
|
223
253
|
Requires Python 3.8+. mdbkit never updates itself and never checks for
|
|
224
254
|
updates — upgrades are always explicit.
|
|
225
255
|
|
|
@@ -108,6 +108,25 @@ Full detail: [SECURITY.md](SECURITY.md).
|
|
|
108
108
|
|
|
109
109
|
## Install
|
|
110
110
|
|
|
111
|
+
### Linux
|
|
112
|
+
|
|
113
|
+
**Most distributions:**
|
|
114
|
+
```bash
|
|
115
|
+
pip install mdbkit
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
119
|
+
```bash
|
|
120
|
+
sudo apt install pipx # or: sudo dnf install pipx
|
|
121
|
+
pipx install mdbkit
|
|
122
|
+
pipx ensurepath && source ~/.bashrc
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
126
|
+
```bash
|
|
127
|
+
pip install mdbkit --break-system-packages
|
|
128
|
+
```
|
|
129
|
+
|
|
111
130
|
### macOS
|
|
112
131
|
|
|
113
132
|
macOS ships no `pip` and no `pipx`, so `pip install` fails out of the box.
|
|
@@ -146,25 +165,6 @@ problem entirely.
|
|
|
146
165
|
Do not install with `sudo`. mdbkit is a user-level CLI and needs no
|
|
147
166
|
elevated privileges — not to install, and not to run.
|
|
148
167
|
|
|
149
|
-
### Linux
|
|
150
|
-
|
|
151
|
-
**Most distributions:**
|
|
152
|
-
```bash
|
|
153
|
-
pip install mdbkit
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
157
|
-
```bash
|
|
158
|
-
sudo apt install pipx # or: sudo dnf install pipx
|
|
159
|
-
pipx install mdbkit
|
|
160
|
-
pipx ensurepath && source ~/.bashrc
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
164
|
-
```bash
|
|
165
|
-
pip install mdbkit --break-system-packages
|
|
166
|
-
```
|
|
167
|
-
|
|
168
168
|
### Windows
|
|
169
169
|
|
|
170
170
|
```powershell
|
|
@@ -188,11 +188,41 @@ resolve.
|
|
|
188
188
|
|
|
189
189
|
### Upgrading
|
|
190
190
|
|
|
191
|
+
Use whichever matches how you installed it.
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# Linux — installed with pip
|
|
195
|
+
pip install --upgrade mdbkit
|
|
196
|
+
|
|
197
|
+
# Linux — installed with pipx
|
|
198
|
+
pipx upgrade mdbkit
|
|
199
|
+
|
|
200
|
+
# macOS — installed with pipx (Homebrew route)
|
|
201
|
+
pipx upgrade mdbkit
|
|
202
|
+
|
|
203
|
+
# macOS — installed with python3 -m pip --user
|
|
204
|
+
python3 -m pip install --user --upgrade mdbkit
|
|
205
|
+
|
|
206
|
+
# macOS / Linux — installed with uv
|
|
207
|
+
uv tool upgrade mdbkit
|
|
208
|
+
|
|
209
|
+
# Windows
|
|
210
|
+
py -m pip install --upgrade mdbkit
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Then confirm:
|
|
191
214
|
```bash
|
|
192
|
-
pip install --upgrade mdbkit # or: pipx upgrade mdbkit
|
|
193
215
|
mdbkit --version
|
|
194
216
|
```
|
|
195
217
|
|
|
218
|
+
**If the version has not changed**, pip is serving a cached index. Force it:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
pipx install --force mdbkit # pipx
|
|
222
|
+
pip install --upgrade --no-cache-dir mdbkit # pip
|
|
223
|
+
py -m pip install --upgrade --no-cache-dir mdbkit # Windows
|
|
224
|
+
```
|
|
225
|
+
|
|
196
226
|
Requires Python 3.8+. mdbkit never updates itself and never checks for
|
|
197
227
|
updates — upgrades are always explicit.
|
|
198
228
|
|
|
@@ -230,13 +230,20 @@ def render_recommendations(recs: List[Recommendation], stats: ParseStats,
|
|
|
230
230
|
|
|
231
231
|
# ----------------------------------------------------------------- FTDC ----
|
|
232
232
|
|
|
233
|
-
def _human(n
|
|
233
|
+
def _human(n, label: str = "") -> str:
|
|
234
234
|
"""Format an FTDC value, honouring the unit implied by its label.
|
|
235
235
|
|
|
236
236
|
Only byte-valued metrics get binary-prefix formatting; a metric already
|
|
237
237
|
expressed in KB or MB must not be re-scaled as if it were bytes.
|
|
238
|
+
|
|
239
|
+
Tolerant of odd input on purpose: a display helper must never be the
|
|
240
|
+
thing that takes down a whole command.
|
|
238
241
|
"""
|
|
239
|
-
|
|
242
|
+
if n is None:
|
|
243
|
+
return "-"
|
|
244
|
+
if not isinstance(n, (int, float)):
|
|
245
|
+
return str(n)
|
|
246
|
+
low = str(label).lower()
|
|
240
247
|
if low.endswith("bytes"):
|
|
241
248
|
if n >= 2 ** 30:
|
|
242
249
|
return "%.1f GiB" % (n / 2 ** 30)
|
|
@@ -286,13 +293,13 @@ def render_ftdc_summary(reader, file_count: int) -> str:
|
|
|
286
293
|
rate = reader.rate(label)
|
|
287
294
|
counters.append((
|
|
288
295
|
label,
|
|
289
|
-
_human(
|
|
296
|
+
_human(st.get("change"), label) if st.get("change") is not None else "-",
|
|
290
297
|
("%.1f/s" % rate) if rate is not None else "-",
|
|
291
|
-
_human(
|
|
298
|
+
_human(st.get("last"), label)))
|
|
292
299
|
else:
|
|
293
|
-
gauges.append((label, _human(
|
|
294
|
-
_human(
|
|
295
|
-
_human(
|
|
300
|
+
gauges.append((label, _human(st["min"], label),
|
|
301
|
+
_human(st["avg"], label), _human(st["max"], label),
|
|
302
|
+
_human(st["last"], label)))
|
|
296
303
|
|
|
297
304
|
if gauges:
|
|
298
305
|
parts.append("current values (min / average / max over the window)")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdbkit
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.5
|
|
4
4
|
Summary: Offline toolkit for MongoDB 4.4+ structured logs: log analysis, slow-query shapes, connection churn, and deterministic index advice. A spiritual successor to mtools' log tools.
|
|
5
5
|
Author: Saqib Ameen Subhan
|
|
6
6
|
License: MIT
|
|
@@ -135,6 +135,25 @@ Full detail: [SECURITY.md](SECURITY.md).
|
|
|
135
135
|
|
|
136
136
|
## Install
|
|
137
137
|
|
|
138
|
+
### Linux
|
|
139
|
+
|
|
140
|
+
**Most distributions:**
|
|
141
|
+
```bash
|
|
142
|
+
pip install mdbkit
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
146
|
+
```bash
|
|
147
|
+
sudo apt install pipx # or: sudo dnf install pipx
|
|
148
|
+
pipx install mdbkit
|
|
149
|
+
pipx ensurepath && source ~/.bashrc
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
153
|
+
```bash
|
|
154
|
+
pip install mdbkit --break-system-packages
|
|
155
|
+
```
|
|
156
|
+
|
|
138
157
|
### macOS
|
|
139
158
|
|
|
140
159
|
macOS ships no `pip` and no `pipx`, so `pip install` fails out of the box.
|
|
@@ -173,25 +192,6 @@ problem entirely.
|
|
|
173
192
|
Do not install with `sudo`. mdbkit is a user-level CLI and needs no
|
|
174
193
|
elevated privileges — not to install, and not to run.
|
|
175
194
|
|
|
176
|
-
### Linux
|
|
177
|
-
|
|
178
|
-
**Most distributions:**
|
|
179
|
-
```bash
|
|
180
|
-
pip install mdbkit
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**Ubuntu 20.04 / Debian / Amazon Linux 2 (Python 3.8 hosts):**
|
|
184
|
-
```bash
|
|
185
|
-
sudo apt install pipx # or: sudo dnf install pipx
|
|
186
|
-
pipx install mdbkit
|
|
187
|
-
pipx ensurepath && source ~/.bashrc
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**Modern Ubuntu/Debian complaining about "externally-managed-environment":**
|
|
191
|
-
```bash
|
|
192
|
-
pip install mdbkit --break-system-packages
|
|
193
|
-
```
|
|
194
|
-
|
|
195
195
|
### Windows
|
|
196
196
|
|
|
197
197
|
```powershell
|
|
@@ -215,11 +215,41 @@ resolve.
|
|
|
215
215
|
|
|
216
216
|
### Upgrading
|
|
217
217
|
|
|
218
|
+
Use whichever matches how you installed it.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Linux — installed with pip
|
|
222
|
+
pip install --upgrade mdbkit
|
|
223
|
+
|
|
224
|
+
# Linux — installed with pipx
|
|
225
|
+
pipx upgrade mdbkit
|
|
226
|
+
|
|
227
|
+
# macOS — installed with pipx (Homebrew route)
|
|
228
|
+
pipx upgrade mdbkit
|
|
229
|
+
|
|
230
|
+
# macOS — installed with python3 -m pip --user
|
|
231
|
+
python3 -m pip install --user --upgrade mdbkit
|
|
232
|
+
|
|
233
|
+
# macOS / Linux — installed with uv
|
|
234
|
+
uv tool upgrade mdbkit
|
|
235
|
+
|
|
236
|
+
# Windows
|
|
237
|
+
py -m pip install --upgrade mdbkit
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Then confirm:
|
|
218
241
|
```bash
|
|
219
|
-
pip install --upgrade mdbkit # or: pipx upgrade mdbkit
|
|
220
242
|
mdbkit --version
|
|
221
243
|
```
|
|
222
244
|
|
|
245
|
+
**If the version has not changed**, pip is serving a cached index. Force it:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
pipx install --force mdbkit # pipx
|
|
249
|
+
pip install --upgrade --no-cache-dir mdbkit # pip
|
|
250
|
+
py -m pip install --upgrade --no-cache-dir mdbkit # Windows
|
|
251
|
+
```
|
|
252
|
+
|
|
223
253
|
Requires Python 3.8+. mdbkit never updates itself and never checks for
|
|
224
254
|
updates — upgrades are always explicit.
|
|
225
255
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mdbkit"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.5"
|
|
8
8
|
description = "Offline toolkit for MongoDB 4.4+ structured logs: log analysis, slow-query shapes, connection churn, and deterministic index advice. A spiritual successor to mtools' log tools."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"""End-to-end rendering tests.
|
|
2
|
+
|
|
3
|
+
A user hit `AttributeError: 'int' object has no attribute 'lower'` running
|
|
4
|
+
`mdbkit ftdc summary` on a real diagnostic.data. The cause was swapped
|
|
5
|
+
arguments in `render_ftdc_summary`, and 139 tests missed it because every
|
|
6
|
+
FTDC test stopped at the decoder and never rendered anything.
|
|
7
|
+
|
|
8
|
+
So these tests deliberately run each command the way a user does — through
|
|
9
|
+
the CLI, all the way to printed output — rather than testing internals. The
|
|
10
|
+
decoder was the hard part and it was thoroughly covered; the bug was in the
|
|
11
|
+
formatting nobody thought worth testing.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import struct
|
|
16
|
+
import zlib
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
from mdbkit.cli import main
|
|
21
|
+
from mdbkit.demo import DemoLog, write_extras
|
|
22
|
+
from mdbkit.render import _human
|
|
23
|
+
|
|
24
|
+
from test_ftdc import enc_doc, rle_varint
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# --------------------------------------------------------------- fixtures ---
|
|
28
|
+
|
|
29
|
+
def make_ftdc(tmp_path, samples=4):
|
|
30
|
+
"""A small but structurally realistic diagnostic.data directory."""
|
|
31
|
+
from mdbkit.ftdc import numeric_metrics, parse_document
|
|
32
|
+
ref = enc_doc([
|
|
33
|
+
("start", 0),
|
|
34
|
+
("serverStatus", {
|
|
35
|
+
"connections": {"current": 42, "available": 900,
|
|
36
|
+
"totalCreated": 5000},
|
|
37
|
+
"opcounters": {"query": 1000, "insert": 50, "update": 7,
|
|
38
|
+
"delete": 2, "getmore": 9, "command": 300},
|
|
39
|
+
"globalLock": {"currentQueue": {"readers": 0, "writers": 0}},
|
|
40
|
+
"wiredTiger": {
|
|
41
|
+
"cache": {"bytes currently in the cache": 2000000000,
|
|
42
|
+
"maximum bytes configured": 8589934592,
|
|
43
|
+
"tracked dirty bytes in the cache": 100000000},
|
|
44
|
+
"transaction": {
|
|
45
|
+
"transaction checkpoint most recent time (msecs)": 900},
|
|
46
|
+
},
|
|
47
|
+
"mem": {"resident": 4096, "virtual": 9000},
|
|
48
|
+
}),
|
|
49
|
+
("systemMetrics", {
|
|
50
|
+
"cpu": {"user_ms": 1000, "system_ms": 500, "iowait_ms": 20},
|
|
51
|
+
"disks": {"sda": {"io_time_ms": 100, "reads": 40, "writes": 12,
|
|
52
|
+
"read_time_ms": 80, "write_time_ms": 30}},
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
55
|
+
parsed, _ = parse_document(ref)
|
|
56
|
+
leaves = numeric_metrics(parsed)
|
|
57
|
+
deltas = [1] * (len(leaves) * (samples - 1))
|
|
58
|
+
payload = ref + struct.pack("<II", len(leaves), samples - 1) \
|
|
59
|
+
+ rle_varint(deltas)
|
|
60
|
+
blob = struct.pack("<I", len(payload)) + zlib.compress(payload)
|
|
61
|
+
d = tmp_path / "diagnostic.data"
|
|
62
|
+
d.mkdir()
|
|
63
|
+
(d / "metrics.2026-08-29T00-00-00Z-00000").write_bytes(
|
|
64
|
+
enc_doc([("_id", 1788000000000), ("type", 1), ("data", blob)]))
|
|
65
|
+
return str(d)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@pytest.fixture
|
|
69
|
+
def demo_log(tmp_path):
|
|
70
|
+
p = tmp_path / "demo.log"
|
|
71
|
+
p.write_text("\n".join(DemoLog(minutes=30).build()) + "\n")
|
|
72
|
+
return str(p)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# ------------------------------------------------------- the reported bug ---
|
|
76
|
+
|
|
77
|
+
def _row(out, label):
|
|
78
|
+
"""The cells of one metric row, label stripped off the front."""
|
|
79
|
+
for line in out.splitlines():
|
|
80
|
+
if line.startswith(label + " ") or line.strip() == label:
|
|
81
|
+
return line[len(label):].split()
|
|
82
|
+
raise AssertionError("no row for %s in:\n%s" % (label, out))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_ftdc_summary_renders(tmp_path, capsys):
|
|
86
|
+
"""The exact command that crashed for a user."""
|
|
87
|
+
path = make_ftdc(tmp_path)
|
|
88
|
+
assert main(["ftdc", "summary", path, "--all"]) == 0
|
|
89
|
+
out = capsys.readouterr().out
|
|
90
|
+
assert "mdbkit ftdc summary" in out
|
|
91
|
+
assert "cache.usedBytes" in out
|
|
92
|
+
assert "conns.current" in out
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_ftdc_summary_every_cell_is_a_value_not_a_label(tmp_path, capsys):
|
|
96
|
+
"""Swapping _human's arguments does not crash now that it is hardened,
|
|
97
|
+
it silently prints the metric name where a number belongs. So assert on
|
|
98
|
+
the cells, not just on the absence of an exception."""
|
|
99
|
+
path = make_ftdc(tmp_path)
|
|
100
|
+
main(["ftdc", "summary", path, "--all"])
|
|
101
|
+
out = capsys.readouterr().out
|
|
102
|
+
|
|
103
|
+
cache = _row(out, "cache.usedBytes")
|
|
104
|
+
assert cache[:2] == ["1.9", "GiB"], cache # min column, formatted
|
|
105
|
+
assert cache.count("GiB") == 4 # min, avg, max, last
|
|
106
|
+
|
|
107
|
+
conns = _row(out, "conns.current")
|
|
108
|
+
assert conns[0] == "42", conns # a number, not a label
|
|
109
|
+
for cell in conns:
|
|
110
|
+
assert "conns" not in cell
|
|
111
|
+
assert "GiB" not in cell
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_ftdc_summary_separates_gauges_from_counters(tmp_path, capsys):
|
|
115
|
+
path = make_ftdc(tmp_path)
|
|
116
|
+
main(["ftdc", "summary", path, "--all"])
|
|
117
|
+
out = capsys.readouterr().out
|
|
118
|
+
assert "current values" in out
|
|
119
|
+
assert "cumulative since server start" in out
|
|
120
|
+
assert "change in window" in out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_ftdc_summary_does_not_rescale_non_byte_metrics(tmp_path, capsys):
|
|
124
|
+
"""conns.current is a count, not bytes; it must never read as GiB."""
|
|
125
|
+
path = make_ftdc(tmp_path)
|
|
126
|
+
main(["ftdc", "summary", path, "--all"])
|
|
127
|
+
for line in capsys.readouterr().out.splitlines():
|
|
128
|
+
if line.startswith("conns.current"):
|
|
129
|
+
assert "GiB" not in line and "MiB" not in line
|
|
130
|
+
break
|
|
131
|
+
else:
|
|
132
|
+
pytest.fail("conns.current row missing")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_ftdc_timeline_and_export_render(tmp_path, capsys):
|
|
136
|
+
path = make_ftdc(tmp_path)
|
|
137
|
+
assert main(["ftdc", "timeline", path, "--all",
|
|
138
|
+
"--metric", "conns.current"]) == 0
|
|
139
|
+
assert "conns.current" in capsys.readouterr().out
|
|
140
|
+
assert main(["ftdc", "export", path, "--all",
|
|
141
|
+
"--metric", "conns.current"]) == 0
|
|
142
|
+
assert capsys.readouterr().out.strip()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_ftdc_json_is_valid(tmp_path, capsys):
|
|
146
|
+
path = make_ftdc(tmp_path)
|
|
147
|
+
assert main(["ftdc", "summary", path, "--all", "--json"]) == 0
|
|
148
|
+
data = json.loads(capsys.readouterr().out)
|
|
149
|
+
assert data["chunks"] >= 1
|
|
150
|
+
assert "series" in data
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# ------------------------------------------- _human, the function that broke ---
|
|
154
|
+
|
|
155
|
+
def test_human_argument_order_and_tolerance():
|
|
156
|
+
# value first, label second — the order that was swapped
|
|
157
|
+
assert "GiB" in _human(2 * 1024 ** 3, "cache.usedBytes")
|
|
158
|
+
assert "GiB" not in _human(42, "conns.current")
|
|
159
|
+
# a display helper must never raise, whatever it is handed
|
|
160
|
+
assert _human(None) == "-"
|
|
161
|
+
assert _human("already a string") == "already a string"
|
|
162
|
+
assert _human(0, "") == "0"
|
|
163
|
+
assert _human(1234.5, None)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# ------------------------------------ every other command renders end to end ---
|
|
167
|
+
|
|
168
|
+
def test_all_commands_render(tmp_path, demo_log, capsys):
|
|
169
|
+
"""Run each command through the CLI to printed output. This is the test
|
|
170
|
+
that would have caught the ftdc crash."""
|
|
171
|
+
write_extras(str(tmp_path))
|
|
172
|
+
idx = str(tmp_path / "indexes.json")
|
|
173
|
+
sch = str(tmp_path / "schema.json")
|
|
174
|
+
exp = str(tmp_path / "explain.json")
|
|
175
|
+
|
|
176
|
+
commands = [
|
|
177
|
+
["loginfo", demo_log],
|
|
178
|
+
["queries", demo_log],
|
|
179
|
+
["queries", demo_log, "--shape", "1"],
|
|
180
|
+
["connections", demo_log],
|
|
181
|
+
["advise", demo_log, "--indexes", idx, "--schema", sch],
|
|
182
|
+
["explain", exp],
|
|
183
|
+
["triage", demo_log, "--window", "0", "--no-sysprobe"],
|
|
184
|
+
["filter", demo_log, "--severity", "E"],
|
|
185
|
+
["compare", demo_log, "--after", demo_log],
|
|
186
|
+
["export-script", "indexes"],
|
|
187
|
+
["export-script", "schema"],
|
|
188
|
+
["export-script", "serverstatus"],
|
|
189
|
+
]
|
|
190
|
+
for argv in commands:
|
|
191
|
+
assert main(argv) == 0, argv
|
|
192
|
+
out = capsys.readouterr().out
|
|
193
|
+
assert out.strip(), "%s printed nothing" % argv
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_all_json_modes_are_valid_json(tmp_path, demo_log, capsys):
|
|
197
|
+
write_extras(str(tmp_path))
|
|
198
|
+
for argv in (
|
|
199
|
+
["loginfo", demo_log, "--json"],
|
|
200
|
+
["queries", demo_log, "--json"],
|
|
201
|
+
["connections", demo_log, "--json"],
|
|
202
|
+
["advise", demo_log, "--indexes", str(tmp_path / "indexes.json"),
|
|
203
|
+
"--json"],
|
|
204
|
+
["explain", str(tmp_path / "explain.json"), "--json"],
|
|
205
|
+
["triage", demo_log, "--window", "0", "--no-sysprobe", "--json"],
|
|
206
|
+
["compare", demo_log, "--after", demo_log, "--json"],
|
|
207
|
+
):
|
|
208
|
+
assert main(argv) == 0, argv
|
|
209
|
+
json.loads(capsys.readouterr().out)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def test_reports_render(tmp_path, demo_log, capsys):
|
|
213
|
+
for ext in ("md", "html"):
|
|
214
|
+
out = tmp_path / ("r." + ext)
|
|
215
|
+
assert main(["triage", demo_log, "--window", "0", "--no-sysprobe",
|
|
216
|
+
"--report", str(out)]) == 0
|
|
217
|
+
assert out.exists() and out.stat().st_size > 200
|
|
218
|
+
capsys.readouterr()
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_serverstatus_and_oslog_render(tmp_path, capsys):
|
|
222
|
+
ss = tmp_path / "s.json"
|
|
223
|
+
ss.write_text(json.dumps({
|
|
224
|
+
"host": "h", "version": "7.0", "uptime": 3600,
|
|
225
|
+
"connections": {"current": 5, "available": 100, "totalCreated": 9},
|
|
226
|
+
"opcounters": {"query": 10, "insert": 2},
|
|
227
|
+
"wiredTiger": {"cache": {"bytes currently in the cache": 1 << 20,
|
|
228
|
+
"maximum bytes configured": 1 << 30}},
|
|
229
|
+
"mem": {"resident": 100}}))
|
|
230
|
+
assert main(["serverstatus", str(ss)]) == 0
|
|
231
|
+
assert "mdbkit serverstatus" in capsys.readouterr().out
|
|
232
|
+
|
|
233
|
+
sl = tmp_path / "syslog"
|
|
234
|
+
sl.write_text("Aug 29 09:14:03 h kernel: Out of memory: "
|
|
235
|
+
"Killed process 1 (mongod)\n")
|
|
236
|
+
assert main(["oslog", str(sl)]) == 0
|
|
237
|
+
assert "oom-kill" in capsys.readouterr().out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|