Skip to content

Commit 4a5e154

Browse files
sincejunedmitryax
andauthored
[mdatagen] Add events in generated documentation (#13037)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add events in generated documentation <!-- Issue number if applicable --> #### Link to tracking issue Part of #12571 <!--Describe what testing was performed and which tests were added.--> #### Testing n/a <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Dmitry Anoshin <[email protected]>
1 parent 20600a6 commit 4a5e154

File tree

6 files changed

+147
-4
lines changed

6 files changed

+147
-4
lines changed

.chloggen/mdatagen-events-doc.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: cmd/mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add events in generated documentation
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12571]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

cmd/mdatagen/internal/command.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func run(ymlPath string) error {
158158
}
159159
}
160160

161-
if len(md.Metrics) != 0 || len(md.Telemetry.Metrics) != 0 || len(md.ResourceAttributes) != 0 { // if there's metrics or internal metrics, generate documentation for them
161+
if len(md.Metrics) != 0 || len(md.Telemetry.Metrics) != 0 || len(md.ResourceAttributes) != 0 || len(md.Events) != 0 { // if there's metrics or internal metrics or events, generate documentation for them
162162
toGenerate[filepath.Join(tmplDir, "documentation.md.tmpl")] = filepath.Join(ymlDir, "documentation.md")
163163
}
164164

@@ -220,6 +220,9 @@ func templatize(tmplFile string, md Metadata) *template.Template {
220220
"metricInfo": func(mn MetricName) Metric {
221221
return md.Metrics[mn]
222222
},
223+
"eventInfo": func(en EventName) Event {
224+
return md.Events[en]
225+
},
223226
"telemetryInfo": func(mn MetricName) Metric {
224227
return md.Telemetry.Metrics[mn]
225228
},

cmd/mdatagen/internal/command_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ func TestNewCommand(t *testing.T) {
3131

3232
func TestRunContents(t *testing.T) {
3333
tests := []struct {
34-
yml string
35-
wantMetricsGenerated bool
34+
yml string
35+
wantMetricsGenerated bool
36+
// TODO: we should add one more flag for logs builder
37+
wantEventsGenerated bool
3638
wantMetricsContext bool
3739
wantConfigGenerated bool
3840
wantTelemetryGenerated bool
@@ -179,6 +181,14 @@ func TestRunContents(t *testing.T) {
179181
wantReadmeGenerated: true,
180182
wantComponentTestGenerated: true,
181183
},
184+
{
185+
yml: "events/basic_event.yaml",
186+
wantStatusGenerated: true,
187+
wantReadmeGenerated: true,
188+
wantComponentTestGenerated: true,
189+
wantConfigGenerated: true,
190+
wantEventsGenerated: true,
191+
},
182192
}
183193
for _, tt := range tests {
184194
t.Run(tt.yml, func(t *testing.T) {
@@ -255,7 +265,7 @@ foo
255265
require.NoFileExists(t, filepath.Join(tmpdir, generatedPackageDir, "generated_telemetry.go"))
256266
}
257267

258-
if !tt.wantMetricsGenerated && !tt.wantTelemetryGenerated && !tt.wantResourceAttributesGenerated {
268+
if !tt.wantMetricsGenerated && !tt.wantTelemetryGenerated && !tt.wantResourceAttributesGenerated && !tt.wantEventsGenerated {
259269
require.NoFileExists(t, filepath.Join(tmpdir, "documentation.md"))
260270
}
261271

cmd/mdatagen/internal/samplereceiver/documentation.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,46 @@ metrics:
101101
| string_attr | Attribute with any string value. | Any Str |
102102
| boolean_attr | Attribute with a boolean value. | Any Bool |
103103
104+
## Default Events
105+
106+
The following events are emitted by default. Each of them can be disabled by applying the following configuration:
107+
108+
```yaml
109+
events:
110+
<event_name>:
111+
enabled: false
112+
```
113+
114+
### default.event
115+
116+
Example event enabled by default.
117+
118+
#### Attributes
119+
120+
| Name | Description | Values |
121+
| ---- | ----------- | ------ |
122+
| string_attr | Attribute with any string value. | Any Str |
123+
| state | Integer attribute with overridden name. | Any Int |
124+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
125+
| slice_attr | Attribute with a slice value. | Any Slice |
126+
| map_attr | Attribute with a map value. | Any Map |
127+
128+
### default.event.to_be_removed
129+
130+
[DEPRECATED] Example to-be-removed event enabled by default.
131+
132+
The event will be will be removed soon.
133+
134+
#### Attributes
135+
136+
| Name | Description | Values |
137+
| ---- | ----------- | ------ |
138+
| string_attr | Attribute with any string value. | Any Str |
139+
| state | Integer attribute with overridden name. | Any Int |
140+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` |
141+
| slice_attr | Attribute with a slice value. | Any Slice |
142+
| map_attr | Attribute with a map value. | Any Map |
143+
104144
## Resource Attributes
105145
106146
| Name | Description | Values | Enabled |

cmd/mdatagen/internal/templates/documentation.md.tmpl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@
3434

3535
{{- end -}}
3636

37+
{{- define "event-documentation" -}}
38+
{{- $eventName := . }}
39+
{{- $event := $eventName | eventInfo -}}
40+
41+
### {{ $eventName }}
42+
43+
{{ $event.Description }}
44+
45+
{{- if $event.ExtendedDocumentation }}
46+
47+
{{ $event.ExtendedDocumentation }}
48+
49+
{{- end }}
50+
51+
{{- if $event.Attributes }}
52+
53+
#### Attributes
54+
55+
| Name | Description | Values |
56+
| ---- | ----------- | ------ |
57+
{{- range $event.Attributes }}
58+
{{- $attribute := . | attributeInfo }}
59+
| {{ $attribute.Name }} | {{ $attribute.Description }} |
60+
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |
61+
{{- end }}
62+
63+
{{- end }}
64+
65+
{{- end -}}
66+
3767
{{- define "telemetry-documentation" -}}
3868
{{- $metricName := . }}
3969
{{- $metric := $metricName | telemetryInfo -}}
@@ -123,6 +153,27 @@ metrics:
123153
{{- end }}
124154
{{- end }}
125155

156+
{{- if .Events }}
157+
158+
## Default Events
159+
160+
The following events are emitted by default. Each of them can be disabled by applying the following configuration:
161+
162+
```yaml
163+
events:
164+
<event_name>:
165+
enabled: false
166+
```
167+
168+
{{- range $eventName, $event := .Events }}
169+
{{- if $event.Enabled }}
170+
171+
{{ template "event-documentation" $eventName }}
172+
173+
{{- end }}
174+
{{- end }}
175+
{{- end }}
176+
126177
{{- if .ResourceAttributes }}
127178

128179
## Resource Attributes
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type: receiver
2+
3+
status:
4+
class: receiver
5+
stability:
6+
development: [logs]
7+
distributions: [contrib]
8+
warnings:
9+
- Any additional information that should be brought to the consumer's attention
10+
11+
events:
12+
event:
13+
enabled: true
14+
description: Description.

0 commit comments

Comments
 (0)