Skip to content

Commit

Permalink
Refactor config sources into provider wrapper and support all service…
Browse files Browse the repository at this point in the history
… providers (#2893)

* refactor config source and its provider

* forward wrapped providers to config source resolver

* support raw confmap.Provider retrieved values

* remove unnecessary previous value merging

* update configsource.Provider for clarity

* exercise both env provider types in vault test
  • Loading branch information
rmfitzpatrick authored Apr 3, 2023
1 parent 534371e commit 70b75c7
Show file tree
Hide file tree
Showing 75 changed files with 1,203 additions and 1,245 deletions.
28 changes: 8 additions & 20 deletions cmd/otelcol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (

"github.com/signalfx/splunk-otel-collector/internal/components"
"github.com/signalfx/splunk-otel-collector/internal/configconverter"
"github.com/signalfx/splunk-otel-collector/internal/configprovider"
"github.com/signalfx/splunk-otel-collector/internal/configsources"
"github.com/signalfx/splunk-otel-collector/internal/confmapprovider/configsource"
"github.com/signalfx/splunk-otel-collector/internal/confmapprovider/discovery"
"github.com/signalfx/splunk-otel-collector/internal/settings"
"github.com/signalfx/splunk-otel-collector/internal/version"
Expand Down Expand Up @@ -72,31 +71,20 @@ func main() {
log.Fatalf("failed to create discovery provider: %v", err)
}

hooks := []configprovider.Hook{configServer, dryRun}
hooks := []configsource.Hook{configServer, dryRun}
envProvider := envprovider.New()
fileProvider := fileprovider.New()
configSourceProvider := configsource.New(zap.NewNop(), hooks)
serviceConfigProvider, err := otelcol.NewConfigProvider(
otelcol.ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: collectorSettings.ResolverURIs(),
Providers: map[string]confmap.Provider{
discovery.PropertyScheme(): configprovider.NewConfigSourceConfigMapProvider(
discovery.PropertyProvider(), zap.NewNop(), info, hooks, configsources.Get()...,
),
discovery.ConfigDScheme(): configprovider.NewConfigSourceConfigMapProvider(
discovery.ConfigDProvider(),
zap.NewNop(), // The service logger is not available yet, setting it to Nop.
info, hooks, configsources.Get()...,
),
discovery.DiscoveryModeScheme(): configprovider.NewConfigSourceConfigMapProvider(
discovery.DiscoveryModeProvider(), zap.NewNop(), info, hooks, configsources.Get()...,
),
envProvider.Scheme(): configprovider.NewConfigSourceConfigMapProvider(
envProvider, zap.NewNop(), info, hooks, configsources.Get()...,
),
fileProvider.Scheme(): configprovider.NewConfigSourceConfigMapProvider(
fileProvider, zap.NewNop(), info, hooks, configsources.Get()...,
),
discovery.PropertyScheme(): configSourceProvider.Wrap(discovery.PropertyProvider()),
discovery.ConfigDScheme(): configSourceProvider.Wrap(discovery.ConfigDProvider()),
discovery.DiscoveryModeScheme(): configSourceProvider.Wrap(discovery.DiscoveryModeProvider()),
envProvider.Scheme(): configSourceProvider.Wrap(envProvider),
fileProvider.Scheme(): configSourceProvider.Wrap(fileProvider),
}, Converters: confMapConverters,
},
})
Expand Down
4 changes: 2 additions & 2 deletions internal/configconverter/config_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"go.opentelemetry.io/collector/confmap"
"gopkg.in/yaml.v2"

"github.com/signalfx/splunk-otel-collector/internal/configprovider"
"github.com/signalfx/splunk-otel-collector/internal/confmapprovider/configsource"
)

const (
Expand All @@ -51,7 +51,7 @@ const (
)

var _ confmap.Converter = (*ConfigServer)(nil)
var _ configprovider.Hook = (*ConfigServer)(nil)
var _ configsource.Hook = (*ConfigServer)(nil)

type ConfigServer struct {
// Use get/set methods instead of direct usage
Expand Down
4 changes: 2 additions & 2 deletions internal/configconverter/dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"go.opentelemetry.io/collector/confmap"
"gopkg.in/yaml.v2"

"github.com/signalfx/splunk-otel-collector/internal/configprovider"
"github.com/signalfx/splunk-otel-collector/internal/confmapprovider/configsource"
)

var _ confmap.Converter = (*DryRun)(nil)
var _ configprovider.Hook = (*DryRun)(nil)
var _ configsource.Hook = (*DryRun)(nil)

type DryRun struct {
*sync.Mutex
Expand Down
49 changes: 0 additions & 49 deletions internal/configprovider/builder.go

This file was deleted.

138 changes: 0 additions & 138 deletions internal/configprovider/builder_test.go

This file was deleted.

51 changes: 0 additions & 51 deletions internal/configprovider/component.go

This file was deleted.

62 changes: 0 additions & 62 deletions internal/configprovider/config.go

This file was deleted.

Loading

0 comments on commit 70b75c7

Please sign in to comment.