Skip to content

Commit

Permalink
update mdatagen to support per signal stability (open-telemetry#21153)
Browse files Browse the repository at this point in the history
This will allow us to move more components to using mdatagen. Next steps would be to move mdatagen to the build-tools repo to make it more widely usable.
---------

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed May 5, 2023
1 parent dda09dc commit b2eea6e
Show file tree
Hide file tree
Showing 239 changed files with 679 additions and 615 deletions.
16 changes: 16 additions & 0 deletions .chloggen/codeboten_add-stability-per-signal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support stability level per signal

# One or more tracking issues related to the change
issues: [21153]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
11 changes: 11 additions & 0 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"

Expand Down Expand Up @@ -131,6 +132,16 @@ func templatize(tmplFile string, md metadata) *template.Template {
"distroURL": func(name string) string {
return distros[name]
},
"keys": func(input map[string]string) []string {
keys := []string{}
for k := range input {
keys = append(keys, k)
}
sort.Slice(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
return keys
},
// ParseFS delegates the parsing of the files to `Glob`
// which uses the `\` as a special character.
// Meaning on windows based machines, the `\` needs to be replaced
Expand Down
40 changes: 27 additions & 13 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ metrics:
type: metricreceiver
status:
class: exporter
stability: beta
pipelines: [metrics, logs, traces]
stability:
beta: [traces, metrics, logs]
distributions: [contrib]
`,
wantStatusGenerated: true,
Expand Down Expand Up @@ -141,6 +141,7 @@ func Test_inlineReplace(t *testing.T) {
outputFile string
componentClass string
warnings []string
stability map[string][]string
}{
{
name: "readme with empty status",
Expand Down Expand Up @@ -202,13 +203,28 @@ Some warning there.
outputFile: "readme_with_warnings.md",
warnings: []string{"warning1"},
},
{
name: "readme with multiple signals",
markdown: `# Some component
<!-- status autogenerated section -->
<!-- end autogenerated section -->
Some info about a component
`,
outputFile: "readme_with_multiple_signals.md",
stability: map[string][]string{"beta": {"metrics"}, "alpha": {"logs"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stability := map[string][]string{"beta": {"metrics"}}
if len(tt.stability) > 0 {
stability = tt.stability
}
md := metadata{
Status: Status{
Stability: "beta",
Pipelines: []string{"metrics"},
Stability: stability,
Distributions: []string{"contrib"},
Class: tt.componentClass,
Warnings: tt.warnings,
Expand All @@ -229,7 +245,7 @@ Some warning there.
expected, err := os.ReadFile(filepath.Join("testdata", tt.outputFile))
require.NoError(t, err)
expected = bytes.ReplaceAll(expected, []byte("\r\n"), []byte("\n"))
require.Equal(t, expected, got)
require.Equal(t, expected, got, "got: %s\nexpected: %s", got, expected)
})
}
}
Expand All @@ -246,8 +262,7 @@ func TestGenerateStatusMetadata(t *testing.T) {
md: metadata{
Type: "foo",
Status: Status{
Stability: "beta",
Pipelines: []string{"metrics"},
Stability: map[string][]string{"beta": {"metrics"}},
Distributions: []string{"contrib"},
Class: "receiver",
},
Expand All @@ -261,8 +276,8 @@ import (
)
const (
Type = "foo"
Stability = component.StabilityLevelBeta
Type = "foo"
MetricsStability = component.StabilityLevelBeta
)
`,
},
Expand All @@ -271,8 +286,7 @@ const (
md: metadata{
Type: "foo",
Status: Status{
Stability: "alpha",
Pipelines: []string{"metrics"},
Stability: map[string][]string{"alpha": {"metrics"}},
Distributions: []string{"contrib"},
Class: "receiver",
},
Expand All @@ -286,8 +300,8 @@ import (
)
const (
Type = "foo"
Stability = component.StabilityLevelAlpha
Type = "foo"
MetricsStability = component.StabilityLevelAlpha
)
`,
},
Expand Down
9 changes: 4 additions & 5 deletions cmd/mdatagen/statusdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ var distros = map[string]string{
}

type Status struct {
Stability string `mapstructure:"stability"`
Pipelines []string `mapstructure:"pipelines"`
Distributions []string `mapstructure:"distributions"`
Class string `mapstructure:"class"`
Warnings []string `mapstructure:"warnings"`
Stability map[string][]string `mapstructure:"stability"`
Distributions []string `mapstructure:"distributions"`
Class string `mapstructure:"class"`
Warnings []string `mapstructure:"warnings"`
}
23 changes: 13 additions & 10 deletions cmd/mdatagen/templates/readme.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<!-- status autogenerated section -->
{{- if ne .Status.Stability "" }}
| Status | |
| ------------------------ |-----------|
| Stability | [{{ .Status.Stability }}] |
{{- if ne .Status.Class "extension" }}
| Supported pipeline types | {{ stringsJoin .Status.Pipelines ", " }} |
{{- if len .Status.Stability }}
| Status | |
| ------------- |-----------|
{{- $class := .Status.Class }}
{{- $idx := 0 }}
{{- range $stability, $value := .Status.Stability }}
| {{ if not $idx }}Stability{{ else }} {{ end }} | [{{ $stability }}]{{ if ne $class "extension" }}: {{ stringsJoin $value ", " }} {{ end }} |
{{- $idx = inc $idx }}
{{- end }}
| Distributions | [{{ stringsJoin .Status.Distributions "], [" }}] |
| Distributions | [{{ stringsJoin .Status.Distributions "], [" }}] |
{{- if .Status.Warnings }}
| Warnings | [{{ stringsJoin .Status.Warnings ", " }}](#warnings) |
| Warnings | [{{ stringsJoin .Status.Warnings ", " }}](#warnings) |
{{- end }}
{{range $stability, $val := .Status.Stability}}
[{{ $stability }}]: https://github.com/open-telemetry/opentelemetry-collector#{{ $stability }}
{{- end }}

[{{ .Status.Stability }}]: https://github.com/open-telemetry/opentelemetry-collector#{{ .Status.Stability }}
{{- range .Status.Distributions }}
[{{.}}]: {{ distroURL . }}
{{- end }}
Expand Down
6 changes: 5 additions & 1 deletion cmd/mdatagen/templates/status.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ import (

const (
Type = "{{ .Type }}"
Stability = component.StabilityLevel{{ casesTitle .Status.Stability }}
{{- range $stability, $signals := .Status.Stability }}
{{- range $signal := $signals }}
{{ casesTitle $signal }}Stability = component.StabilityLevel{{ casesTitle $stability }}
{{- end }}
{{- end }}
)
15 changes: 15 additions & 0 deletions cmd/mdatagen/testdata/readme_with_multiple_signals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Some component

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [alpha]: logs |
| | [beta]: metrics |
| Distributions | [contrib] |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
<!-- end autogenerated section -->

Some info about a component
9 changes: 4 additions & 5 deletions cmd/mdatagen/testdata/readme_with_status.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Some component

<!-- status autogenerated section -->
| Status | |
| ------------------------ |-----------|
| Stability | [beta] |
| Supported pipeline types | metrics |
| Distributions | [contrib] |
| Status | |
| ------------- |-----------|
| Stability | [beta]: metrics |
| Distributions | [contrib] |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
8 changes: 4 additions & 4 deletions cmd/mdatagen/testdata/readme_with_status_extension.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Some component

<!-- status autogenerated section -->
| Status | |
| ------------------------ |-----------|
| Stability | [beta] |
| Distributions | [contrib] |
| Status | |
| ------------- |-----------|
| Stability | [beta] |
| Distributions | [contrib] |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
11 changes: 5 additions & 6 deletions cmd/mdatagen/testdata/readme_with_warnings.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Some component

<!-- status autogenerated section -->
| Status | |
| ------------------------ |-----------|
| Stability | [beta] |
| Supported pipeline types | metrics |
| Distributions | [contrib] |
| Warnings | [warning1](#warnings) |
| Status | |
| ------------- |-----------|
| Stability | [beta]: metrics |
| Distributions | [contrib] |
| Warnings | [warning1](#warnings) |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
9 changes: 4 additions & 5 deletions exporter/awss3exporter/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# AWS S3 Exporter for OpenTelemetry Collector

<!-- status autogenerated section -->
| Status | |
| ------------------------ |-----------|
| Stability | [alpha] |
| Supported pipeline types | logs, metrics, traces |
| Distributions | [contrib] |
| Status | |
| ------------- |-----------|
| Stability | [alpha]: traces, metrics, logs |
| Distributions | [contrib] |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
6 changes: 3 additions & 3 deletions exporter/awss3exporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithTraces(createTracesExporter, metadata.Stability),
exporter.WithLogs(createLogsExporter, metadata.Stability),
exporter.WithMetrics(createMetricsExporter, metadata.Stability),
exporter.WithTraces(createTracesExporter, metadata.TracesStability),
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
)
}

Expand Down
6 changes: 4 additions & 2 deletions exporter/awss3exporter/internal/metadata/generated_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions exporter/awss3exporter/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ type: awss3

status:
class: exporter
stability: alpha
pipelines: [logs, metrics, traces]
stability:
alpha: [traces, metrics, logs]
distributions: [contrib]
4 changes: 2 additions & 2 deletions exporter/cassandraexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
func NewFactory() exporter.Factory {
return exporter.NewFactory(metadata.Type,
createDefaultConfig,
exporter.WithTraces(createTracesExporter, metadata.Stability),
exporter.WithLogs(createLogsExporter, metadata.Stability),
exporter.WithTraces(createTracesExporter, metadata.TracesStability),
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
)
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions exporter/cassandraexporter/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type: cassandra

status:
class: exporter
stability: alpha
pipelines: [logs, traces]
stability:
alpha: [traces, logs]
distributions: [contrib]

9 changes: 4 additions & 5 deletions exporter/lokiexporter/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Loki Exporter

<!-- status autogenerated section -->
| Status | |
| ------------------------ |-----------|
| Stability | [beta] |
| Supported pipeline types | logs |
| Distributions | [contrib] |
| Status | |
| ------------- |-----------|
| Stability | [beta]: logs |
| Distributions | [contrib] |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Expand Down
2 changes: 1 addition & 1 deletion exporter/lokiexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithLogs(createLogsExporter, metadata.Stability),
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
)
}

Expand Down
4 changes: 2 additions & 2 deletions exporter/lokiexporter/internal/metadata/generated_status.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions exporter/lokiexporter/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ type: loki

status:
class: exporter
stability: beta
pipelines: [logs]
stability:
beta: [logs]
distributions: [contrib]
Loading

0 comments on commit b2eea6e

Please sign in to comment.