Skip to content

Commit

Permalink
Remove usages of deprecated service.MustNewDefaultConfigProvider (#9262)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Apr 13, 2022
1 parent 9c214be commit 60b9ca3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
21 changes: 16 additions & 5 deletions receiver/prometheusreceiver/internal/staleness_end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configunmarshaler"
"go.opentelemetry.io/collector/config/mapprovider/filemapprovider"
"go.opentelemetry.io/collector/processor/batchprocessor"
"go.opentelemetry.io/collector/service"
"go.uber.org/zap"
Expand Down Expand Up @@ -113,7 +116,7 @@ jvm_memory_pool_bytes_used{pool="CodeHeap 'non-nmethods'"} %.1f`, float64(i))
defer prweServer.Close()

// 3. Set the OpenTelemetry Prometheus receiver.
config := fmt.Sprintf(`
cfg := fmt.Sprintf(`
receivers:
prometheus:
config:
Expand Down Expand Up @@ -141,7 +144,7 @@ service:
confFile, err := ioutil.TempFile(os.TempDir(), "conf-")
require.Nil(t, err)
defer os.Remove(confFile.Name())
_, err = confFile.Write([]byte(config))
_, err = confFile.Write([]byte(cfg))
require.Nil(t, err)
// 4. Run the OpenTelemetry Collector.
receivers, err := component.MakeReceiverFactoryMap(prometheusreceiver.NewFactory())
Expand All @@ -157,10 +160,18 @@ service:
Processors: processors,
}

fmp := filemapprovider.New()
configProvider, err := service.NewConfigProvider(
service.ConfigProviderSettings{
Locations: []string{confFile.Name()},
MapProviders: map[string]config.MapProvider{fmp.Scheme(): fmp},
Unmarshaler: configunmarshaler.NewDefault(),
})
require.NoError(t, err)

appSettings := service.CollectorSettings{
Factories: factories,
// TODO: Replace with NewConfigProvider
ConfigProvider: service.MustNewDefaultConfigProvider([]string{confFile.Name()}, nil), // nolint:staticcheck
Factories: factories,
ConfigProvider: configProvider,
BuildInfo: component.BuildInfo{
Command: "otelcol",
Description: "OpenTelemetry Collector",
Expand Down
21 changes: 17 additions & 4 deletions testbed/testbed/in_process_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

"github.com/shirou/gopsutil/v3/process"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configunmarshaler"
"go.opentelemetry.io/collector/config/mapprovider/filemapprovider"
"go.opentelemetry.io/collector/service"
)

Expand Down Expand Up @@ -67,11 +70,21 @@ func (ipp *inProcessCollector) Start(args StartParams) error {
}
ipp.configFile = confFile.Name()

fmp := filemapprovider.New()
configProvider, err := service.NewConfigProvider(
service.ConfigProviderSettings{
Locations: []string{ipp.configFile},
MapProviders: map[string]config.MapProvider{fmp.Scheme(): fmp},
Unmarshaler: configunmarshaler.NewDefault(),
})
if err != nil {
return err
}

settings := service.CollectorSettings{
BuildInfo: component.NewDefaultBuildInfo(),
Factories: ipp.factories,
// TODO: Replace with NewConfigProvider
ConfigProvider: service.MustNewDefaultConfigProvider([]string{ipp.configFile}, nil), // nolint:staticcheck
BuildInfo: component.NewDefaultBuildInfo(),
Factories: ipp.factories,
ConfigProvider: configProvider,
}

ipp.svc, err = service.New(settings)
Expand Down

0 comments on commit 60b9ca3

Please sign in to comment.