Skip to content

[mdatagen] Add supportsSignal func #12640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/add-supports-signal-func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# 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. otlpreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `supportsSignal` func for `Metadata` type in `mdatagen`.

# One or more tracking issues or pull requests related to the change
issues: [12640]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
132 changes: 12 additions & 120 deletions cmd/mdatagen/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,126 +272,18 @@ func templatize(tmplFile string, md Metadata) *template.Template {
"isCommand": func() bool {
return md.Status.Class == "cmd"
},
"supportsLogs": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "logs" {
return true
}
}
}
return false
},
"supportsMetrics": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "metrics" {
return true
}
}
}
return false
},
"supportsTraces": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "traces" {
return true
}
}
}
return false
},
"supportsLogsToLogs": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "logs_to_logs" {
return true
}
}
}
return false
},
"supportsLogsToMetrics": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "logs_to_metrics" {
return true
}
}
}
return false
},
"supportsLogsToTraces": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "logs_to_traces" {
return true
}
}
}
return false
},
"supportsMetricsToLogs": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "metrics_to_logs" {
return true
}
}
}
return false
},
"supportsMetricsToMetrics": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "metrics_to_metrics" {
return true
}
}
}
return false
},
"supportsMetricsToTraces": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "metrics_to_traces" {
return true
}
}
}
return false
},
"supportsTracesToLogs": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "traces_to_logs" {
return true
}
}
}
return false
},
"supportsTracesToMetrics": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "traces_to_metrics" {
return true
}
}
}
return false
},
"supportsTracesToTraces": func() bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == "traces_to_traces" {
return true
}
}
}
return false
},
"supportsLogs": func() bool { return md.supportsSignal("logs") },
"supportsMetrics": func() bool { return md.supportsSignal("metrics") },
"supportsTraces": func() bool { return md.supportsSignal("traces") },
"supportsLogsToLogs": func() bool { return md.supportsSignal("logs_to_logs") },
"supportsLogsToMetrics": func() bool { return md.supportsSignal("logs_to_metrics") },
"supportsLogsToTraces": func() bool { return md.supportsSignal("logs_to_traces") },
"supportsMetricsToLogs": func() bool { return md.supportsSignal("metrics_to_logs") },
"supportsMetricsToMetrics": func() bool { return md.supportsSignal("metrics_to_metrics") },
"supportsMetricsToTraces": func() bool { return md.supportsSignal("metrics_to_traces") },
"supportsTracesToLogs": func() bool { return md.supportsSignal("traces_to_logs") },
"supportsTracesToMetrics": func() bool { return md.supportsSignal("traces_to_metrics") },
"supportsTracesToTraces": func() bool { return md.supportsSignal("traces_to_traces") },
"expectConsumerError": func() bool {
return md.Tests.ExpectConsumerError
},
Expand Down
12 changes: 12 additions & 0 deletions cmd/mdatagen/internal/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ func (md *Metadata) validateAttributes(usedAttrs map[AttributeName]bool) error {
return errs
}

func (md *Metadata) supportsSignal(signal string) bool {
for _, signals := range md.Status.Stability {
for _, s := range signals {
if s == signal {
return true
}
}
}

return false
}

func validateMetrics(metrics map[MetricName]Metric, attributes map[AttributeName]Attribute, usedAttrs map[AttributeName]bool) error {
var errs error
for mn, m := range metrics {
Expand Down
Loading