Skip to content

Commit 6f1adfa

Browse files
author
Ahmed Hedi
committed
refactor(cmk-crash): port crash reporting library from cmk.ccc
(split into _crash / _fingerprint / _store) The old cmk.ccc.crash_reporting stays until the hard-cut rename. VersionInfo and its shared base are homed in the new cmk.ccc.version_info module (VersionInfoBase + VersionInfo) rather than in cmk.crash: VersionInfo is produced by cmk.ccc.version, so keeping it in the foundational cmk.ccc layer lets cmk.crash depend downward on it and avoids inverting the cmk.ccc layer once the consumers are renamed (CMK-104). cmk.crash re-exports VersionInfo, so its public API surface is unchanged. Change-Id: I5a26c421c8d975f97de63812e429575165f984bc
1 parent 532feb0 commit 6f1adfa

9 files changed

Lines changed: 797 additions & 21 deletions

File tree

module_layers.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,9 @@ allows = [
572572
[components."cmk.core_client"]
573573
allows = ["@ccc", "@trace"]
574574

575+
[components."cmk.crash"]
576+
allows = ["@ccc"]
577+
575578
[components."cmk.crypto"]
576579
allows = ["@ccc"]
577580

packages/cmk-ccc/BUILD

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ py_library(
223223
],
224224
)
225225

226+
py_library(
227+
name = "version-info",
228+
srcs = ["cmk/ccc/version_info.py"],
229+
imports = ["."],
230+
visibility = ["//visibility:public"],
231+
deps = ["_init"],
232+
)
233+
226234
py_library(
227235
name = "timeout",
228236
srcs = ["cmk/ccc/timeout.py"],
@@ -266,6 +274,7 @@ _ALL = [
266274
"tty",
267275
"user",
268276
"version",
277+
"version-info",
269278
]
270279

271280
py_doc_test(
@@ -421,21 +430,6 @@ py_test(
421430
],
422431
)
423432

424-
py_test(
425-
name = "crash-reporting-tests",
426-
size = "small",
427-
srcs = [
428-
"__test__.py",
429-
"tests/test_crash_reporting.py",
430-
],
431-
main = "__test__.py",
432-
deps = [
433-
"__test__",
434-
"crash-reporting",
435-
requirement("pytest"),
436-
],
437-
)
438-
439433
py_test(
440434
name = "archive-tests",
441435
size = "small",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2026 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
"""Environment/version snapshot types shared by the version subsystem and crash reporting.
6+
7+
``VersionInfo`` is produced by :mod:`cmk.ccc.version` (the ``general_version_infos*``
8+
functions) and consumed by the crash-reporting library to build a ``CrashInfo``. It
9+
lives here, in the foundational ``cmk.ccc`` layer alongside its producer, so that higher
10+
layers (``cmk.crash``) depend downward on it rather than the reverse.
11+
"""
12+
13+
from collections.abc import Sequence
14+
from typing import TypedDict
15+
16+
17+
class VersionInfoBase(TypedDict):
18+
"""Environment fields shared between ``VersionInfo`` and the crash-reporting ``CrashInfo``.
19+
20+
``time`` is intentionally absent from this base class. TypedDict inheritance does not
21+
support redefining a key with a different type in a subclass, so each subclass declares
22+
its own ``time`` independently:
23+
24+
- ``VersionInfo.time: float`` — raw timestamp used when *constructing* a new crash
25+
report (see ``collect_crash_info``).
26+
- ``CrashInfo.time: CrashOccurrences`` — structured occurrence data stored on disk and
27+
used wherever the persisted format is read back.
28+
"""
29+
30+
core: str
31+
python_version: str
32+
edition: str
33+
python_paths: Sequence[str]
34+
version: str
35+
os: str
36+
37+
38+
class VersionInfo(VersionInfoBase):
39+
"""Carries the raw construction-time timestamp as a float."""
40+
41+
time: float

packages/cmk-crash/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ py_library(
1414
name = "crash",
1515
srcs = [
1616
"cmk/crash/__init__.py",
17+
"cmk/crash/_crash.py",
18+
"cmk/crash/_fingerprint.py",
19+
"cmk/crash/_store.py",
1720
],
1821
data = [":crash_py_typed"],
1922
imports = ["."],
2023
visibility = ["//visibility:public"],
24+
deps = [
25+
"//packages/cmk-ccc:store",
26+
"//packages/cmk-ccc:version-info",
27+
],
2128
)
2229

2330
py_library(

packages/cmk-crash/cmk/crash/__init__.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,62 @@
44
# conditions defined in the file COPYING, which is part of this source code package.
55
"""Minimal crash-reporting library: dataclasses, on-disk store, and fingerprint helpers.
66
7-
Code is migrated here from ``cmk.ccc.crash_reporting`` later. Write-time
8-
deduplication behavior is preserved. the fingerprint helpers and the
9-
``CrashReportStore.save()`` merge-into-existing logic land in this library
10-
alongside the store.
7+
Ported verbatim from ``cmk.ccc.crash_reporting``. Write-time deduplication
8+
behavior is preserved: the fingerprint helpers and the
9+
``CrashReportStore.save()`` merge-into-existing logic live in this library
10+
alongside the store. The public API surface is unchanged from the old module —
11+
only the import path moves (``cmk.ccc.crash_reporting`` → ``cmk.crash``).
1112
"""
13+
14+
from cmk.ccc.version_info import VersionInfo
15+
16+
from ._crash import (
17+
ABCCrashReport,
18+
BaseDetails,
19+
ContactDetails,
20+
CRASH_INFO_VERSION,
21+
CrashInfo,
22+
CrashOccurrences,
23+
format_var_for_export,
24+
make_crash_report_base_path,
25+
REDACTED_STRING,
26+
RobustJSONEncoder,
27+
SENSITIVE_KEYWORDS,
28+
SerializedCrashReport,
29+
TDetails,
30+
)
31+
from ._fingerprint import (
32+
crash_fingerprint,
33+
fingerprint_hash,
34+
normalize_crash_time,
35+
)
36+
from ._store import (
37+
cleanup_crash_reports,
38+
CrashReportStore,
39+
DEFAULT_MAX_CRASH_AGE,
40+
DEFAULT_MAX_CRASHES_TOTAL_SIZE,
41+
)
42+
43+
__all__ = [
44+
"ABCCrashReport",
45+
"BaseDetails",
46+
"cleanup_crash_reports",
47+
"ContactDetails",
48+
"CRASH_INFO_VERSION",
49+
"CrashInfo",
50+
"CrashOccurrences",
51+
"CrashReportStore",
52+
"DEFAULT_MAX_CRASH_AGE",
53+
"DEFAULT_MAX_CRASHES_TOTAL_SIZE",
54+
"REDACTED_STRING",
55+
"RobustJSONEncoder",
56+
"SENSITIVE_KEYWORDS",
57+
"SerializedCrashReport",
58+
"TDetails",
59+
"VersionInfo",
60+
"crash_fingerprint",
61+
"fingerprint_hash",
62+
"format_var_for_export",
63+
"make_crash_report_base_path",
64+
"normalize_crash_time",
65+
]

0 commit comments

Comments
 (0)