Skip to content
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
27 changes: 27 additions & 0 deletions .chloggen/builder-telemetry-factories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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. receiver/otlp)
component: cmd/builder

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add "telemetry" field to allow configuring telemetry providers

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

# (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: |
Most users should not need to use this, this field should only be set if you
intend to provide your own OpenTelemetry SDK.

# 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: []
9 changes: 7 additions & 2 deletions cmd/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ The configuration file is composed of two main parts: `dist` and module types. A
ocb --config=config.yaml
```

The module types are specified at the top-level, and might be: `extensions`, `exporters`, `receivers` and `processors`. They all accept a list of components, and each component is required to have at least the `gomod` entry. When not specified, the `import` value is inferred from the `gomod`. When not specified, the `name` is inferred from the `import`.
The module types are specified at the top-level. Available options are `extensions`, `exporters`, `receivers`, `processors`, `providers`, and `converters`. They all accept a list of components, and each component is required to have at least the `gomod` entry. The telemetry provider for the Collector binary can also be specified through the `telemetry` key, which can be set to a single module, also requiring a `gomod` entry at a minimum.

When not specified, the `import` value is inferred from the `gomod`. When not specified, the `name` is inferred from the `import`.

The `import` might specify a more specific path than what is specified in the `gomod`. For instance, your Go module might be `gitlab.com/myorg/myrepo` and the `import` might be `gitlab.com/myorg/myrepo/myexporter`.

Expand All @@ -159,10 +161,13 @@ dist:
go: "/usr/bin/go" # which Go binary to use to compile the generated sources. Optional.
debug_compilation: false # enabling this causes the builder to keep the debug symbols in the resulting binary. Optional.
exporters:
- gomod: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.129.0" # the Go module for the component. Required.
- gomod: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.146.0" # the Go module for the component. Required.
import: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter" # the import path for the component. Optional.
name: "alibabacloudlogserviceexporter" # package name to use in the generated sources. Optional.
path: "./alibabacloudlogserviceexporter" # in case a local version should be used for the module, the path relative to the current dir, or a full path can be specified. Optional.
telemetry:
gomod: go.opentelemetry.io/collector/service v0.146.0
import: go.opentelemetry.io/collector/service/telemetry/otelconftelemetry
replaces:
# a list of "replaces" directives that will be part of the resulting go.mod
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.128.0
Expand Down
29 changes: 28 additions & 1 deletion cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
Receivers []Module `mapstructure:"receivers"`
Processors []Module `mapstructure:"processors"`
Connectors []Module `mapstructure:"connectors"`
Telemetry Module `mapstructure:"telemetry"`
ConfmapProviders []Module `mapstructure:"providers"`
ConfmapConverters []Module `mapstructure:"converters"`
Replaces []string `mapstructure:"replaces"`
Expand Down Expand Up @@ -144,6 +145,7 @@ func (c *Config) Validate() error {
validateModules("connector", c.Connectors),
validateModules("provider", c.ConfmapProviders),
validateModules("converter", c.ConfmapConverters),
validateTelemetry(c),
)
}

Expand Down Expand Up @@ -193,6 +195,12 @@ func (c *Config) ParseModules() error {
return err
}

telemetry, err := parseModules([]Module{c.Telemetry}, usedNames)
if err != nil {
return err
}
c.Telemetry = telemetry[0]

c.ConfmapProviders, err = parseModules(c.ConfmapProviders, usedNames)
if err != nil {
return err
Expand All @@ -205,7 +213,7 @@ func (c *Config) ParseModules() error {
}

func (c *Config) allComponents() []Module {
return slices.Concat[[]Module](c.Exporters, c.Receivers, c.Processors, c.Extensions, c.Connectors, c.ConfmapProviders, c.ConfmapConverters)
return slices.Concat(c.Exporters, c.Receivers, c.Processors, c.Extensions, c.Connectors, []Module{c.Telemetry}, c.ConfmapProviders, c.ConfmapConverters)
}

func validateModules(name string, mods []Module) error {
Expand All @@ -217,6 +225,25 @@ func validateModules(name string, mods []Module) error {
return nil
}

// validateTelemetry ensures there is a valid telemetry module specified.
// If the field is not set, it is defaulted to otelconftelemetry.
func validateTelemetry(c *Config) error {
// We cannot set this in createDefaultConfig, since koanf merges maps and we
// would get a blend of this value and user-provided values. Once
// otelconftelemetry is its own module (that is, the `Import` field is not
Comment thread
evan-bradley marked this conversation as resolved.
// set), we can likely move the default to createDefaultConfig.
if c.Telemetry.Name == "" && c.Telemetry.Import == "" && c.Telemetry.GoMod == "" && c.Telemetry.Path == "" {
c.Telemetry = Module{
GoMod: "go.opentelemetry.io/collector/service " + DefaultBetaOtelColVersion,
Import: "go.opentelemetry.io/collector/service/telemetry/otelconftelemetry",
}
} else if c.Telemetry.GoMod == "" {
return fmt.Errorf("telemetry module: %w", errMissingGoMod)
}

return nil
}

func parseModules(mods []Module, usedNames map[string]int) ([]Module, error) {
var parsedModules []Module
for _, mod := range mods {
Expand Down
29 changes: 23 additions & 6 deletions cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func TestAliases(t *testing.T) {
GoMod: "github.com/another3/module v0.1.2",
},
},
Telemetry: Module{
GoMod: "github.com/another3/module v0.1.2",
},
}

// test
Expand Down Expand Up @@ -128,6 +131,10 @@ func TestAliases(t *testing.T) {
assert.Equal(t, "github.com/another3/module v0.1.2", cfg.Connectors[2].GoMod)
assert.Equal(t, "github.com/another3/module", cfg.Connectors[2].Import)
assert.Equal(t, "module5", cfg.Connectors[2].Name)

assert.Equal(t, "github.com/another3/module v0.1.2", cfg.Telemetry.GoMod)
assert.Equal(t, "github.com/another3/module", cfg.Telemetry.Import)
assert.Equal(t, "module6", cfg.Telemetry.Name)
}

func TestParseModules(t *testing.T) {
Expand Down Expand Up @@ -275,6 +282,15 @@ func TestMissingModule(t *testing.T) {
},
err: errMissingGoMod,
},
{
cfg: Config{
Logger: zap.NewNop(),
Telemetry: Module{
Import: "go.opentelemetry.io/collector/service/telemetry/otelconftelemetry",
},
},
err: errMissingGoMod,
},
}

for _, test := range configurations {
Expand All @@ -285,10 +301,11 @@ func TestMissingModule(t *testing.T) {
func TestNewDefaultConfig(t *testing.T) {
cfg, err := NewDefaultConfig()
require.NoError(t, err)
require.NoError(t, cfg.ParseModules())
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
assert.Empty(t, cfg.Telemetry.GoMod)
require.NoError(t, cfg.Validate())
require.NoError(t, cfg.SetGoPath())
require.NoError(t, cfg.ParseModules())
Comment thread
evan-bradley marked this conversation as resolved.
assert.NotEmpty(t, cfg.Telemetry.GoMod)
assert.False(t, cfg.Distribution.DebugCompilation)
assert.Empty(t, cfg.Distribution.BuildTags)
assert.False(t, cfg.LDSet)
Expand All @@ -305,9 +322,9 @@ func TestNewBuiltinConfig(t *testing.T) {
cfg := Config{Logger: zaptest.NewLogger(t)}

require.NoError(t, k.UnmarshalWithConf("", &cfg, koanf.UnmarshalConf{Tag: "mapstructure"}))
assert.NoError(t, cfg.ParseModules())
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
require.NoError(t, cfg.Validate())
require.NoError(t, cfg.SetGoPath())
require.NoError(t, cfg.ParseModules())

// Unlike the config initialized in NewDefaultConfig(), we expect
// the builtin default to be practically useful, so there must be
Expand Down
4 changes: 2 additions & 2 deletions cmd/builder/internal/builder/templates/components.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.opentelemetry.io/collector/otelcol"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/service/telemetry/otelconftelemetry"
{{.Telemetry.Name}} "{{.Telemetry.Import}}"
{{- range .Connectors}}
{{.Name}} "{{.Import}}"
{{- end}}
Expand Down Expand Up @@ -45,7 +45,7 @@ func makeModulesMap[T component.Factory](factories map[component.Type]T, modules
func components() (otelcol.Factories, error) {
var err error
factories := otelcol.Factories{
Telemetry: otelconftelemetry.NewFactory(),
Telemetry: {{.Telemetry.Name}}.NewFactory(),
}

factories.Extensions, err = otelcol.MakeFactoryMap[extension.Factory](
Expand Down
2 changes: 2 additions & 0 deletions cmd/builder/internal/builder/templates/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
{{- range .Processors}}
{{if .GoMod}}{{.GoMod}}{{end}}
{{- end}}
{{if .Telemetry.GoMod}}{{.Telemetry.GoMod}}{{end}}
go.opentelemetry.io/collector/otelcol {{.OtelColVersion}}
)

Expand Down Expand Up @@ -55,6 +56,7 @@ require (
{{- range .Processors}}
{{if ne .Path ""}}replace {{.GoMod}} => {{.Path}}{{end}}
{{- end}}
{{if ne .Telemetry.Path ""}}replace {{.Telemetry.GoMod}} => {{.Telemetry.Path}}{{end}}
{{- range .Replaces}}
replace {{.}}
{{- end}}
Expand Down
4 changes: 4 additions & 0 deletions cmd/builder/internal/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ providers:
- gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.51.0
- gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.51.0

telemetry:
gomod: go.opentelemetry.io/collector/service v0.145.0
import: go.opentelemetry.io/collector/service/telemetry/otelconftelemetry

4 changes: 4 additions & 0 deletions cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ providers:
- gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.51.0
- gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.51.0

telemetry:
gomod: go.opentelemetry.io/collector/service v0.145.0
import: go.opentelemetry.io/collector/service/telemetry/otelconftelemetry

replaces:
- go.opentelemetry.io/collector => ../../
- go.opentelemetry.io/collector/client => ../../client
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcorecol/components.go

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

Loading