Skip to content

Commit 584ddbf

Browse files
ebeahanwebmat
andauthored
Beta label support (#1051)
Co-authored-by: Mathieu Martin <webmat@gmail.com>
1 parent d427fb6 commit 584ddbf

File tree

8 files changed

+61
-5
lines changed

8 files changed

+61
-5
lines changed

CHANGELOG.next.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Thanks, you're awesome :-) -->
3737
* Added support for `scaled_float`'s mandatory parameter `scaling_factor`. #1042
3838
* Added ability for --oss flag to fall back `constant_keyword` to `keyword`. #1046
3939
* Added support in the generated Go source go for `wildcard`, `version`, and `constant_keyword` data types. #1050
40+
* Added support for marking fields, field sets, or field reuse as beta in the documentation. #1051
4041
* Added support for `constant_keyword`'s optional parameter `value`. #1112
4142

4243
#### Improvements

schemas/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Optional field set attributes:
3232
- type (ignored): at this level, should always be `group`
3333
- reusable (optional): Used to identify which field sets are expected to be reused in multiple places.
3434
See "Field set reuse" for details.
35+
- beta: Adds a beta marker for the entire fieldset. The text provided in this attribute is used as content of the beta marker in the documentation.
36+
Beta notices should not have newlines.
3537

3638
### Field set reuse
3739

@@ -104,6 +106,18 @@ The above defines all process fields in both places:
104106
}
105107
```
106108

109+
The `beta` marker can optionally be used along with `at` and `as` to include a beta marker in the field reuses section, marking specific reuse locations as beta.
110+
Beta notices should not have newlines.
111+
112+
```
113+
reusable:
114+
top_level: true
115+
expected:
116+
- at: user
117+
as: target
118+
beta: Reusing these fields in this location is currently considered beta.
119+
```
120+
107121
### List of fields
108122
109123
Array of YAML objects:
@@ -134,6 +148,7 @@ Supported keys to describe fields
134148
- format: Field format that can be used in a Kibana index template.
135149
- normalize: Normalization steps that should be applied at ingestion time. Supported values:
136150
- array: the content of the field should be an array (even when there's only one value).
151+
- beta (optional): Adds a beta marker for the field to the description. The text provided in this attribute is used as content of the beta marker in the documentation. Note that when a whole field set is marked as beta, it is not necessary nor recommended to mark all fields in the field set as beta. Beta notices should not have newlines.
137152

138153
Supported keys to describe expected values for a field
139154

scripts/generators/asciidoc_fields.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def render_nestings_reuse_section(fieldset):
3939
rows.append({
4040
'flat_nesting': "{}.*".format(reused_here_entry['full']),
4141
'name': reused_here_entry['schema_name'],
42-
'short': reused_here_entry['short']
42+
'short': reused_here_entry['short'],
43+
'beta': reused_here_entry.get('beta', '')
4344
})
4445

4546
return sorted(rows, key=lambda x: x['flat_nesting'])

scripts/generators/ecs_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,5 @@ def strict_warning(msg):
189189
:param msg: custom text which will be displayed with wrapped boilerplate
190190
for strict warning messages.
191191
"""
192-
warn_message = f"{msg}\n\nThis will cause an exception when running in strict mode."
193-
warnings.warn(warn_message)
192+
warn_message = f"{msg}\n\nThis will cause an exception when running in strict mode.\nWarning check:"
193+
warnings.warn(warn_message, stacklevel=3)

scripts/schema/cleaner.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def schema_mandatory_attributes(schema):
7676
def schema_assertions_and_warnings(schema):
7777
'''Additional checks on a fleshed out schema'''
7878
single_line_short_description(schema, strict=strict_mode)
79+
if 'beta' in schema['field_details']:
80+
single_line_beta_description(schema, strict=strict_mode)
7981

8082

8183
def normalize_reuse_notation(schema):
@@ -181,6 +183,8 @@ def field_assertions_and_warnings(field):
181183
# check short description length if in strict mode
182184
single_line_short_description(field, strict=strict_mode)
183185
check_example_value(field, strict=strict_mode)
186+
if 'beta' in field['field_details']:
187+
single_line_beta_description(field, strict=strict_mode)
184188
if field['field_details']['level'] not in ACCEPTABLE_FIELD_LEVELS:
185189
msg = "Invalid level for field '{}'.\nValue: {}\nAcceptable values: {}".format(
186190
field['field_details']['name'], field['field_details']['level'],
@@ -220,3 +224,13 @@ def check_example_value(field, strict=True):
220224
raise ValueError(msg)
221225
else:
222226
ecs_helpers.strict_warning(msg)
227+
228+
229+
def single_line_beta_description(schema_or_field, strict=True):
230+
if "\n" in schema_or_field['field_details']['beta']:
231+
msg = "Beta descriptions must be single line.\n"
232+
msg += f"Offending field or field set: {schema_or_field['field_details']['name']}"
233+
if strict:
234+
raise ValueError(msg)
235+
else:
236+
ecs_helpers.strict_warning(msg)

scripts/schema/finalizer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def append_reused_here(reused_schema, reuse_entry, destination_schema):
128128
'full': reuse_entry['full'],
129129
'short': reused_schema['field_details']['short'],
130130
}
131+
# Check for beta attribute
132+
if 'beta' in reuse_entry:
133+
reused_here_entry['beta'] = reuse_entry['beta']
131134
destination_schema['schema_details']['reused_here'].extend([reused_here_entry])
132135

133136

scripts/templates/field_details.j2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Find additional usage and examples in the {{ fieldset['name'] }} fields <<ecs-{{
1010

1111
{% endif %}
1212

13+
{# Fieldset label beta header -#}
14+
{% if fieldset['beta'] -%}
15+
16+
beta::[ {{ fieldset['beta'] }}]
17+
18+
{% endif -%}
19+
1320
{# Field Details Table Header -#}
1421
[discrete]
1522
==== {{ fieldset['title'] }} Field Details
@@ -27,7 +34,14 @@ Find additional usage and examples in the {{ fieldset['name'] }} fields <<ecs-{{
2734
{# `Field` column -#}
2835
| {{ field['flat_name'] }}
2936
{# `Description` column -#}
37+
{#- Beta fields will add the `beta` label -#}
38+
{% if field['beta'] -%}
39+
| beta:[ {{ field['beta'] }} ]
40+
41+
{{ field['description']|replace("\n", "\n\n") }}
42+
{%- else -%}
3043
| {{ field['description']|replace("\n", "\n\n") }}
44+
{%- endif %}
3145

3246
type: {{ field['type'] }}
3347

@@ -108,8 +122,16 @@ Note also that the `{{ fieldset['name'] }}` fields are not expected to be used d
108122

109123
{% for entry in render_nestings_reuse_section -%}
110124

125+
{#- Beta marker on nested fields -#}
111126
| <<ecs-{{ entry['name'] }},{{ entry['flat_nesting'] }}>>
127+
{#- Beta marker on nested fields -#}
128+
{%- if entry['beta'] -%}
129+
| beta:[ {{ entry['beta'] }}]
130+
131+
{{ entry['short'] }}
132+
{%- else %}
112133
| {{ entry['short'] }}
134+
{%- endif %}
113135

114136
// ===============================================================
115137

scripts/tests/unit/test_schema_finalizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def schema_user(self):
9292
'order': 2,
9393
'expected': [
9494
{'full': 'server.user', 'at': 'server', 'as': 'user'},
95-
{'full': 'user.target', 'at': 'user', 'as': 'target'},
95+
{'full': 'user.target', 'at': 'user', 'as': 'target', 'beta': 'Some beta notice'},
9696
{'full': 'user.effective', 'at': 'user', 'as': 'effective'},
9797
]
9898
}
@@ -211,7 +211,7 @@ def test_perform_reuse_with_foreign_reuse_and_self_reuse(self):
211211
fields['process']['schema_details']['reused_here'])
212212
self.assertIn({'full': 'user.effective', 'schema_name': 'user', 'short': 'short desc'},
213213
fields['user']['schema_details']['reused_here'])
214-
self.assertIn({'full': 'user.target', 'schema_name': 'user', 'short': 'short desc'},
214+
self.assertIn({'full': 'user.target', 'schema_name': 'user', 'short': 'short desc', 'beta': 'Some beta notice'},
215215
fields['user']['schema_details']['reused_here'])
216216
self.assertIn({'full': 'server.user', 'schema_name': 'user', 'short': 'short desc'},
217217
fields['server']['schema_details']['reused_here'])

0 commit comments

Comments
 (0)