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
2 changes: 1 addition & 1 deletion config/config.go → config/configparser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Package config implements loading of configuration from Viper configuration.
// The implementation relies on registered factories that allow creating
// default configuration for each type of receiver/exporter/processor.
package config
package configparser

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package config
package configparser

import (
"os"
Expand Down
6 changes: 3 additions & 3 deletions config/configtest/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configparser"
)

// NewViperFromYamlFile creates a viper instance that reads the given fileName as yaml config
// and can then be used to unmarshal the file contents to objects.
// Example usage for testing can be found in configtest_test.go
func NewViperFromYamlFile(t *testing.T, fileName string) *viper.Viper {
// Read yaml config from file
v := config.NewViper()
v := configparser.NewViper()
v.SetConfigFile(fileName)
require.NoErrorf(t, v.ReadInConfig(), "unable to read the file %v", fileName)

Expand All @@ -42,7 +42,7 @@ func LoadConfigFile(t *testing.T, fileName string, factories component.Factories
v := NewViperFromYamlFile(t, fileName)

// Load the config from viper using the given factories.
cfg, err := config.Load(v, factories)
cfg, err := configparser.Load(v, factories)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions receiver/hostmetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configparser"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal"
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/scraper/cpuscraper"
Expand Down Expand Up @@ -93,7 +93,7 @@ func customUnmarshaler(componentViperSection *viper.Viper, intoCfg interface{})

cfg.Scrapers = map[string]internal.Config{}

scrapersViperSection, err := config.ViperSubExact(componentViperSection, scrapersKey)
scrapersViperSection, err := configparser.ViperSubExact(componentViperSection, scrapersKey)
if err != nil {
return err
}
Expand All @@ -108,7 +108,7 @@ func customUnmarshaler(componentViperSection *viper.Viper, intoCfg interface{})
}

collectorCfg := factory.CreateDefaultConfig()
collectorViperSection, err := config.ViperSubExact(scrapersViperSection, key)
collectorViperSection, err := configparser.ViperSubExact(scrapersViperSection, key)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions receiver/jaegerreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configparser"
"go.opentelemetry.io/collector/config/configtest"
"go.opentelemetry.io/collector/config/configtls"
)
Expand Down Expand Up @@ -344,9 +344,9 @@ func TestCustomUnmarshalErrors(t *testing.T) {
fu, ok := factory.(component.ConfigUnmarshaler)
assert.True(t, ok)

err := fu.Unmarshal(config.NewViper(), nil)
err := fu.Unmarshal(configparser.NewViper(), nil)
assert.Error(t, err, "should not have been able to marshal to a nil config")

err = fu.Unmarshal(config.NewViper(), &RemoteSamplingConfig{})
err = fu.Unmarshal(configparser.NewViper(), &RemoteSamplingConfig{})
assert.Error(t, err, "should not have been able to marshal to a non-jaegerreceiver config")
}
6 changes: 3 additions & 3 deletions service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configparser"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/internal/collector/telemetry"
Expand Down Expand Up @@ -116,7 +116,7 @@ func FileLoaderConfigFactory(v *viper.Viper, cmd *cobra.Command, factories compo
if err := AddSetFlagProperties(v, cmd); err != nil {
return nil, fmt.Errorf("failed to process set flag: %v", err)
}
return config.Load(v, factories)
return configparser.Load(v, factories)
}

// New creates and returns a new instance of Application.
Expand Down Expand Up @@ -236,7 +236,7 @@ func (app *Application) setupConfigurationComponents(ctx context.Context, factor

app.logger.Info("Loading configuration...")

cfg, err := factory(config.NewViper(), app.rootCmd, app.factories)
cfg, err := factory(configparser.NewViper(), app.rootCmd, app.factories)
if err != nil {
return fmt.Errorf("cannot load configuration: %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions service/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configparser"
"go.opentelemetry.io/collector/processor/attributesprocessor"
"go.opentelemetry.io/collector/processor/batchprocessor"
"go.opentelemetry.io/collector/receiver/jaegerreceiver"
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestSetFlag(t *testing.T) {
"--set=processors.doesnotexist.timeout=2s",
})
require.NoError(t, err)
cfg, err := FileLoaderConfigFactory(config.NewViper(), app.rootCmd, factories)
cfg, err := FileLoaderConfigFactory(configparser.NewViper(), app.rootCmd, factories)
require.Error(t, err)
require.Nil(t, cfg)

Expand All @@ -247,7 +247,7 @@ func TestSetFlag(t *testing.T) {
"--set=processors.batch/foo.timeout=2s",
})
require.NoError(t, err)
cfg, err := FileLoaderConfigFactory(config.NewViper(), app.rootCmd, factories)
cfg, err := FileLoaderConfigFactory(configparser.NewViper(), app.rootCmd, factories)
require.NoError(t, err)
assert.NotNil(t, cfg)
err = cfg.Validate()
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestSetFlag(t *testing.T) {
"--set=extensions.health_check.port=8080",
})
require.NoError(t, err)
cfg, err := FileLoaderConfigFactory(config.NewViper(), app.rootCmd, factories)
cfg, err := FileLoaderConfigFactory(configparser.NewViper(), app.rootCmd, factories)
require.NoError(t, err)
require.NotNil(t, cfg)
err = cfg.Validate()
Expand All @@ -299,7 +299,7 @@ func TestSetFlag_component_does_not_exist(t *testing.T) {
factories, err := defaultcomponents.Components()
require.NoError(t, err)

v := config.NewViper()
v := configparser.NewViper()
cmd := &cobra.Command{}
addSetFlag(cmd.Flags())
fs := &flag.FlagSet{}
Expand Down Expand Up @@ -340,10 +340,10 @@ service:
processors: [batch]
exporters: [logging]
`
v := config.NewViper()
v := configparser.NewViper()
v.SetConfigType("yaml")
v.ReadConfig(strings.NewReader(configStr))
cfg, err := config.Load(v, factories)
cfg, err := configparser.Load(v, factories)
assert.NoError(t, err)
err = cfg.Validate()
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions service/set_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configparser"
)

const (
Expand Down Expand Up @@ -53,7 +53,7 @@ func AddSetFlagProperties(v *viper.Viper, cmd *cobra.Command) error {
return err
}
}
viperFlags := config.NewViper()
viperFlags := configparser.NewViper()
viperFlags.SetConfigType(setFlagFileType)
if err := viperFlags.ReadConfig(b); err != nil {
return fmt.Errorf("failed to read set flag config: %v", err)
Expand All @@ -78,7 +78,7 @@ func AddSetFlagProperties(v *viper.Viper, cmd *cobra.Command) error {

rootKeys := map[string]struct{}{}
for _, k := range viperFlags.AllKeys() {
keys := strings.Split(k, config.ViperDelimiter)
keys := strings.Split(k, configparser.ViperDelimiter)
if len(keys) > 0 {
rootKeys[keys[0]] = struct{}{}
}
Expand Down
6 changes: 3 additions & 3 deletions testbed/testbed/otelcol_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/config/configparser"
"go.opentelemetry.io/collector/internal/version"
"go.opentelemetry.io/collector/service"
)
Expand Down Expand Up @@ -82,10 +82,10 @@ func (ipp *InProcessCollector) PrepareConfig(configStr string) (configCleanup fu
return configCleanup, err
}
ipp.logger = logger
v := config.NewViper()
v := configparser.NewViper()
v.SetConfigType("yaml")
v.ReadConfig(strings.NewReader(configStr))
cfg, err := config.Load(v, ipp.factories)
cfg, err := configparser.Load(v, ipp.factories)
if err != nil {
return configCleanup, err
}
Expand Down