@redpanda-data/docs-extensions-and-macros 4.12.4 → 4.12.5

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.
@@ -1,173 +0,0 @@
1
- # Computed C++ Constants Resolution
2
-
3
- ## Overview
4
-
5
- Some C++ constants in Redpanda are defined with complex compile-time expressions that cannot be easily parsed by the property-extractor. These constants need to be pre-computed and mapped to their actual values.
6
-
7
- ## Problem Statement
8
-
9
- Properties like `log_message_timestamp_before_max_ms` use constants like `max_serializable_ms` as their default values. These constants are defined with complex expressions:
10
-
11
- ```cpp
12
- // From src/v/serde/rw/chrono.h:20
13
- inline constexpr auto max_serializable_ms
14
- = std::chrono::duration_cast<std::chrono::milliseconds>(
15
- std::chrono::nanoseconds::max());
16
- ```
17
-
18
- Without resolution, the extracted schema would show:
19
- ```json
20
- {
21
- "log_message_timestamp_before_max_ms": {
22
- "default": "max_serializable_ms" // ❌ String instead of numeric value
23
- }
24
- }
25
- ```
26
-
27
- ## Solution
28
-
29
- ### 1. COMPUTED_CONSTANTS Dictionary
30
-
31
- Added a dictionary in `transformers.py` that maps constant names to their computed values:
32
-
33
- ```python
34
- COMPUTED_CONSTANTS = {
35
- # From src/v/serde/rw/chrono.h:20
36
- # inline constexpr auto max_serializable_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::nanoseconds::max());
37
- # Calculation: std::numeric_limits<int64_t>::max() / 1,000,000 = 9223372036854775807 / 1000000 = 9223372036854 ms
38
- "max_serializable_ms": 9223372036854, # ~292 years in milliseconds
39
- }
40
- ```
41
-
42
- ### 2. FriendlyDefaultTransformer Enhancement
43
-
44
- Updated the `FriendlyDefaultTransformer` to check the `COMPUTED_CONSTANTS` dictionary before falling back to string normalization:
45
-
46
- ```python
47
- # ------------------------------------------------------------------
48
- # Computed C++ constants (max_serializable_ms, etc.)
49
- # ------------------------------------------------------------------
50
- if d in COMPUTED_CONSTANTS:
51
- property["default"] = COMPUTED_CONSTANTS[d]
52
- return property
53
- ```
54
-
55
- ### 3. Test Coverage
56
-
57
- Added comprehensive test in `tests/test_known_values.py`:
58
-
59
- ```python
60
- def test_max_serializable_ms_constant_resolution(self):
61
- """Test that max_serializable_ms constant is resolved to actual numeric value"""
62
- info = create_complete_property_info(
63
- name="log_message_timestamp_before_max_ms",
64
- description="Maximum timestamp difference for record validation",
65
- declaration="property<std::chrono::milliseconds> log_message_timestamp_before_max_ms;",
66
- metadata="meta{.needs_restart = needs_restart::no, .visibility = visibility::user}",
67
- default_value="max_serializable_ms"
68
- )
69
-
70
- property = apply_transformer_pipeline(info)
71
-
72
- self.assertEqual(property["name"], "log_message_timestamp_before_max_ms")
73
- self.assertEqual(property["type"], "integer")
74
- # max_serializable_ms = std::numeric_limits<int64_t>::max() / 1,000,000 = 9223372036854 ms
75
- self.assertEqual(property["default"], 9223372036854)
76
- self.assertFalse(property["needs_restart"])
77
- self.assertEqual(property["visibility"], "user")
78
- ```
79
-
80
- ## Calculation Details
81
-
82
- ### max_serializable_ms
83
-
84
- **Definition Location:** `src/v/serde/rw/chrono.h:20`
85
-
86
- **C++ Expression:**
87
- ```cpp
88
- std::chrono::duration_cast<std::chrono::milliseconds>(
89
- std::chrono::nanoseconds::max()
90
- )
91
- ```
92
-
93
- **Calculation:**
94
- 1. `std::chrono::nanoseconds::max()` = `std::numeric_limits<int64_t>::max()` = `9223372036854775807` nanoseconds
95
- 2. Convert to milliseconds (truncating division): `9223372036854775807 / 1000000` = `9223372036854` milliseconds
96
- 3. This is approximately **292.47 years**
97
-
98
- **Verification:**
99
- ```python
100
- import sys
101
-
102
- # std::chrono::nanoseconds uses int64_t for rep
103
- max_int64 = 9223372036854775807
104
-
105
- # Convert nanoseconds to milliseconds (duration_cast truncates)
106
- max_ms = max_int64 // 1000000
107
-
108
- print(f'max_serializable_ms = {max_ms} ms')
109
- print(f'Which is approximately {max_ms / (1000 * 60 * 60 * 24 * 365):.2f} years')
110
- ```
111
-
112
- Output:
113
- ```
114
- max_serializable_ms = 9223372036854 ms
115
- Which is approximately 292.47 years
116
- ```
117
-
118
- ## Result
119
-
120
- After the fix, the extracted schema correctly shows:
121
- ```json
122
- {
123
- "log_message_timestamp_before_max_ms": {
124
- "default": 9223372036854, // ✅ Correct numeric value
125
- "type": "integer"
126
- }
127
- }
128
- ```
129
-
130
- ## Adding New Computed Constants
131
-
132
- To add support for new computed constants:
133
-
134
- 1. **Find the definition** in the Redpanda source code
135
- 2. **Compute the value** - either manually or with a Python/C++ test
136
- 3. **Add to COMPUTED_CONSTANTS** dictionary in `transformers.py`:
137
- ```python
138
- COMPUTED_CONSTANTS = {
139
- "existing_constant": 12345,
140
- "new_constant_name": computed_value, # Add comment with source location
141
- }
142
- ```
143
- 4. **Add a test** in `tests/test_known_values.py` to verify resolution
144
- 5. **Document the calculation** with comments including:
145
- - Source file location
146
- - C++ expression
147
- - Calculation steps
148
- - Human-readable interpretation
149
-
150
- ## Test Coverage
151
-
152
- All 53 tests pass, including the new test for `max_serializable_ms` resolution:
153
-
154
- ```bash
155
- cd tools/property-extractor
156
- python -m pytest tests/ -v --tb=short
157
- # ================================================= 53 passed =================================================
158
- ```
159
-
160
- ## Benefits
161
-
162
- ✅ **Accurate defaults** - Properties show actual numeric values instead of symbolic names
163
- ✅ **Type safety** - Numeric properties have numeric defaults, not strings
164
- ✅ **Documentation quality** - Users see real values they can use
165
- ✅ **Maintainability** - Centralized mapping makes updates easy
166
- ✅ **Test coverage** - Ensures constants resolve correctly
167
-
168
- ## Related Files
169
-
170
- - `tools/property-extractor/transformers.py` - COMPUTED_CONSTANTS dictionary and resolution logic
171
- - `tools/property-extractor/tests/test_known_values.py` - Test for constant resolution
172
- - `src/v/serde/rw/chrono.h` - Source definition of max_serializable_ms
173
- - `tools/property-extractor/CI_INTEGRATION.md` - Updated test count documentation