Skip to content

Commit

Permalink
mdatagen: Add parent field to metadata.yaml file for subcomponents
Browse files Browse the repository at this point in the history
This PR adds a `parent` field to the `metadata.yaml`. This is used in subcomponents, and the field contains the type of their parent component.

Issue: open-telemetry#23430
  • Loading branch information
mackjmr committed Jun 22, 2023
1 parent 4e082f4 commit f7af147
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .chloggen/add-parent-field-metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# 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: Adds a parent field to metadata.yaml for subcomponents.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: []

# (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:
2 changes: 2 additions & 0 deletions cmd/mdatagen/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (attr *attribute) Unmarshal(parser *confmap.Conf) error {
type metadata struct {
// Type of the component.
Type string `mapstructure:"type"`
// Type of the parent component (applicable to subcomponents).
Parent string `mapstructure:"parent"`
// Status information for the component.
Status *Status `mapstructure:"status"`
// SemConvVersion is a version number of OpenTelemetry semantic conventions applied to the scraped metrics.
Expand Down
8 changes: 8 additions & 0 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ func Test_loadMetadata(t *testing.T) {
ScopeName: "otelcol",
},
},
{
name: "testdata/parent.yaml",
want: metadata{
Type: "subcomponent",
Parent: "parentComponent",
ScopeName: "otelcol",
},
},
{
name: "testdata/unknown_metric_attribute.yaml",
want: metadata{},
Expand Down
3 changes: 3 additions & 0 deletions cmd/mdatagen/metadata-schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Required: The type of the component - Usually the name. The type and class combined uniquely identify the component (eg. receiver/otlp) or subcomponent (eg. receiver/hostmetricsreceiver/cpu)
type:

# Required for subcomponents: The type of the parent component.
parent: string

# Required for components (Optional for subcomponents): A high-level view of the development status and use of this component
status:
# Required: The class of the component (For example receiver)
Expand Down
4 changes: 4 additions & 0 deletions cmd/mdatagen/templates/documentation.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

# {{ .Type }}

{{- if .Parent }}
**Parent Component:** {{ .Parent }}
{{- end }}

## Default Metrics

The following metrics are emitted by default. Each of them can be disabled by applying the following configuration:
Expand Down
3 changes: 3 additions & 0 deletions cmd/mdatagen/testdata/parent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type: subcomponent

parent: parentComponent

0 comments on commit f7af147

Please sign in to comment.