Skip to content

Commit 6d82b55

Browse files
authored
[mdatagen] Add supportsSignal func (#12640)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR added `supportsSignal` func to `Metadata` type to reduce duplicated code blocks for checking supported signals. <!-- Issue number if applicable --> #### Link to tracking issue n/a <!--Describe what testing was performed and which tests were added.--> #### Testing Already covered <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 0e9e259 commit 6d82b55

File tree

3 files changed

+49
-120
lines changed

3 files changed

+49
-120
lines changed
+25
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 `supportsSignal` func for `Metadata` type in `mdatagen`.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12640]
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

+12-120
Original file line numberDiff line numberDiff line change
@@ -272,126 +272,18 @@ func templatize(tmplFile string, md Metadata) *template.Template {
272272
"isCommand": func() bool {
273273
return md.Status.Class == "cmd"
274274
},
275-
"supportsLogs": func() bool {
276-
for _, signals := range md.Status.Stability {
277-
for _, s := range signals {
278-
if s == "logs" {
279-
return true
280-
}
281-
}
282-
}
283-
return false
284-
},
285-
"supportsMetrics": func() bool {
286-
for _, signals := range md.Status.Stability {
287-
for _, s := range signals {
288-
if s == "metrics" {
289-
return true
290-
}
291-
}
292-
}
293-
return false
294-
},
295-
"supportsTraces": func() bool {
296-
for _, signals := range md.Status.Stability {
297-
for _, s := range signals {
298-
if s == "traces" {
299-
return true
300-
}
301-
}
302-
}
303-
return false
304-
},
305-
"supportsLogsToLogs": func() bool {
306-
for _, signals := range md.Status.Stability {
307-
for _, s := range signals {
308-
if s == "logs_to_logs" {
309-
return true
310-
}
311-
}
312-
}
313-
return false
314-
},
315-
"supportsLogsToMetrics": func() bool {
316-
for _, signals := range md.Status.Stability {
317-
for _, s := range signals {
318-
if s == "logs_to_metrics" {
319-
return true
320-
}
321-
}
322-
}
323-
return false
324-
},
325-
"supportsLogsToTraces": func() bool {
326-
for _, signals := range md.Status.Stability {
327-
for _, s := range signals {
328-
if s == "logs_to_traces" {
329-
return true
330-
}
331-
}
332-
}
333-
return false
334-
},
335-
"supportsMetricsToLogs": func() bool {
336-
for _, signals := range md.Status.Stability {
337-
for _, s := range signals {
338-
if s == "metrics_to_logs" {
339-
return true
340-
}
341-
}
342-
}
343-
return false
344-
},
345-
"supportsMetricsToMetrics": func() bool {
346-
for _, signals := range md.Status.Stability {
347-
for _, s := range signals {
348-
if s == "metrics_to_metrics" {
349-
return true
350-
}
351-
}
352-
}
353-
return false
354-
},
355-
"supportsMetricsToTraces": func() bool {
356-
for _, signals := range md.Status.Stability {
357-
for _, s := range signals {
358-
if s == "metrics_to_traces" {
359-
return true
360-
}
361-
}
362-
}
363-
return false
364-
},
365-
"supportsTracesToLogs": func() bool {
366-
for _, signals := range md.Status.Stability {
367-
for _, s := range signals {
368-
if s == "traces_to_logs" {
369-
return true
370-
}
371-
}
372-
}
373-
return false
374-
},
375-
"supportsTracesToMetrics": func() bool {
376-
for _, signals := range md.Status.Stability {
377-
for _, s := range signals {
378-
if s == "traces_to_metrics" {
379-
return true
380-
}
381-
}
382-
}
383-
return false
384-
},
385-
"supportsTracesToTraces": func() bool {
386-
for _, signals := range md.Status.Stability {
387-
for _, s := range signals {
388-
if s == "traces_to_traces" {
389-
return true
390-
}
391-
}
392-
}
393-
return false
394-
},
275+
"supportsLogs": func() bool { return md.supportsSignal("logs") },
276+
"supportsMetrics": func() bool { return md.supportsSignal("metrics") },
277+
"supportsTraces": func() bool { return md.supportsSignal("traces") },
278+
"supportsLogsToLogs": func() bool { return md.supportsSignal("logs_to_logs") },
279+
"supportsLogsToMetrics": func() bool { return md.supportsSignal("logs_to_metrics") },
280+
"supportsLogsToTraces": func() bool { return md.supportsSignal("logs_to_traces") },
281+
"supportsMetricsToLogs": func() bool { return md.supportsSignal("metrics_to_logs") },
282+
"supportsMetricsToMetrics": func() bool { return md.supportsSignal("metrics_to_metrics") },
283+
"supportsMetricsToTraces": func() bool { return md.supportsSignal("metrics_to_traces") },
284+
"supportsTracesToLogs": func() bool { return md.supportsSignal("traces_to_logs") },
285+
"supportsTracesToMetrics": func() bool { return md.supportsSignal("traces_to_metrics") },
286+
"supportsTracesToTraces": func() bool { return md.supportsSignal("traces_to_traces") },
395287
"expectConsumerError": func() bool {
396288
return md.Tests.ExpectConsumerError
397289
},

cmd/mdatagen/internal/metadata.go

+12
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ func (md *Metadata) validateAttributes(usedAttrs map[AttributeName]bool) error {
135135
return errs
136136
}
137137

138+
func (md *Metadata) supportsSignal(signal string) bool {
139+
for _, signals := range md.Status.Stability {
140+
for _, s := range signals {
141+
if s == signal {
142+
return true
143+
}
144+
}
145+
}
146+
147+
return false
148+
}
149+
138150
func validateMetrics(metrics map[MetricName]Metric, attributes map[AttributeName]Attribute, usedAttrs map[AttributeName]bool) error {
139151
var errs error
140152
for mn, m := range metrics {

0 commit comments

Comments
 (0)