Skip to content

Commit

Permalink
[chore] preallocate configschema components (#24933)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Aug 6, 2023
1 parent 5c1c053 commit ee99f14
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions cmd/configschema/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
extension = "extension"
processor = "processor"
exporter = "exporter"
connector = "connector"
)

// CfgInfo contains a component config instance, as well as its group name and
Expand All @@ -31,34 +32,47 @@ type CfgInfo struct {
// GetAllCfgInfos accepts a Factories struct, then creates and returns a CfgInfo
// for each of its components.
func GetAllCfgInfos(components otelcol.Factories) []CfgInfo {
var out []CfgInfo
out := make([]CfgInfo, len(components.Receivers)+len(components.Extensions)+len(components.Processors)+len(components.Exporters)+len(components.Connectors))
i := 0
for _, f := range components.Receivers {
out = append(out, CfgInfo{
out[i] = CfgInfo{
Type: f.Type(),
Group: receiver,
CfgInstance: f.CreateDefaultConfig(),
})
}
i++
}
for _, f := range components.Extensions {
out = append(out, CfgInfo{
out[i] = CfgInfo{
Type: f.Type(),
Group: extension,
CfgInstance: f.CreateDefaultConfig(),
})
}
i++
}
for _, f := range components.Processors {
out = append(out, CfgInfo{
out[i] = CfgInfo{
Type: f.Type(),
Group: processor,
CfgInstance: f.CreateDefaultConfig(),
})
}
i++
}
for _, f := range components.Exporters {
out = append(out, CfgInfo{
out[i] = CfgInfo{
Type: f.Type(),
Group: exporter,
CfgInstance: f.CreateDefaultConfig(),
})
}
i++
}
for _, f := range components.Connectors {
out[i] = CfgInfo{
Type: f.Type(),
Group: connector,
CfgInstance: f.CreateDefaultConfig(),
}
i++
}
return out
}
Expand Down

0 comments on commit ee99f14

Please sign in to comment.