Skip to content

Commit ac7c0f2

Browse files
authored
[mdatagen] support producing docs for internal telemetry attributes (#12919)
This adds the ability to generate documentation for the internal metrics attributes. --------- Signed-off-by: Alex Boten <[email protected]>
1 parent d020c90 commit ac7c0f2

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
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: 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 support for attributes for telemetry configuration in metadata.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12919]
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: []

cmd/mdatagen/internal/command_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestRunContents(t *testing.T) {
4545
wantGoleakSetup bool
4646
wantGoleakTeardown bool
4747
wantErr bool
48+
wantAttributes []string
4849
}{
4950
{
5051
yml: "invalid.yaml",
@@ -156,6 +157,7 @@ func TestRunContents(t *testing.T) {
156157
wantTelemetryGenerated: true,
157158
wantReadmeGenerated: true,
158159
wantComponentTestGenerated: true,
160+
wantAttributes: []string{"name"},
159161
},
160162
{
161163
yml: "invalid_telemetry_missing_value_type_for_histogram.yaml",
@@ -211,6 +213,13 @@ foo
211213
require.FileExists(t, filepath.Join(tmpdir, generatedPackageDir, "generated_metrics.go"))
212214
require.FileExists(t, filepath.Join(tmpdir, generatedPackageDir, "generated_metrics_test.go"))
213215
require.FileExists(t, filepath.Join(tmpdir, "documentation.md"))
216+
if len(tt.wantAttributes) > 0 {
217+
contents, err = os.ReadFile(filepath.Join(tmpdir, "documentation.md")) //nolint:gosec
218+
require.NoError(t, err)
219+
for _, attr := range tt.wantAttributes {
220+
require.Contains(t, string(contents), attr)
221+
}
222+
}
214223
contents, err = os.ReadFile(filepath.Join(tmpdir, generatedPackageDir, "generated_metrics.go")) //nolint:gosec
215224
require.NoError(t, err)
216225
if tt.wantMetricsContext {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@
5353
| {{ $metric.Unit }} | {{ $metric.Data.Type }} | {{ $metric.Data.MetricValueType }} |
5454
{{- if $metric.Data.HasMonotonic }} {{ $metric.Data.Monotonic }} |{{ end }}
5555

56+
{{- if $metric.Attributes }}
57+
58+
#### Attributes
59+
60+
| Name | Description | Values |
61+
| ---- | ----------- | ------ |
62+
{{- range $metric.Attributes }}
63+
{{- $attribute := . | attributeInfo }}
64+
| {{ $attribute.Name }} | {{ $attribute.Description }} |
65+
{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |
66+
{{- end }}
67+
68+
{{- end }}
5669

5770
{{- end -}}
5871

cmd/mdatagen/internal/testdata/with_telemetry.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ status:
44
class: receiver
55
stability:
66
beta: [traces, logs, metrics]
7+
attributes:
8+
name:
9+
description: Name of sampling decision
10+
type: string
711
telemetry:
812
metrics:
913
sampling_decision_latency:
@@ -14,3 +18,4 @@ telemetry:
1418
level: alpha
1519
histogram:
1620
value_type: int
21+
attributes: [name]

0 commit comments

Comments
 (0)