Skip to content

Commit

Permalink
Rename config.NewID to config.NewComponentID and `config.NewIDFro…
Browse files Browse the repository at this point in the history
…mString` to `config.NewComponentIDFromString` (#4137)

This PR is to rename `config.NewID` to `config.NewComponentID` and `config.NewIDFromString` to `config.NewComponentIDFromString` for naming consistency.  

**Link to tracking Issue:** 
Fixes #4105
  • Loading branch information
JamesJHPark authored Sep 29, 2021
1 parent 6ecb0bd commit 85b8094
Show file tree
Hide file tree
Showing 75 changed files with 222 additions and 221 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Rename `configparser.Parser` as `config.Map` (#4075)
- Rename `component.DefaultBuildInfo()` to `component.NewDefaultBuildInfo()` (#4129)
- Rename consumererror.Permanent to consumererror.NewPermanent (#4118)
- Rename `config.NewID` to `config.NewComponentID` and `config.NewIDFromString` to `config.NewComponentIDFromString` (#4137)

## 💡 Enhancements 💡

Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (f *nopExporterFactory) Type() config.Type {
// CreateDefaultConfig creates the default configuration for the Exporter.
func (f *nopExporterFactory) CreateDefaultConfig() config.Exporter {
return &nopExporterConfig{
ExporterSettings: config.NewExporterSettings(config.NewID("nop")),
ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNewNopExporterFactory(t *testing.T) {
require.NotNil(t, factory)
assert.Equal(t, config.Type("nop"), factory.Type())
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(config.NewID("nop"))}, cfg)
assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop"))}, cfg)

traces, err := factory.CreateTracesExporter(context.Background(), NewNopExporterCreateSettings(), cfg)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *nopExtensionFactory) Type() config.Type {
// CreateDefaultConfig creates the default configuration for the Extension.
func (f *nopExtensionFactory) CreateDefaultConfig() config.Extension {
return &nopExtensionConfig{
ExtensionSettings: config.NewExtensionSettings(config.NewID("nop")),
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestNewNopExtensionFactory(t *testing.T) {
require.NotNil(t, factory)
assert.Equal(t, config.Type("nop"), factory.Type())
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(config.NewID("nop"))}, cfg)
assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop"))}, cfg)

traces, err := factory.CreateExtension(context.Background(), NewNopExtensionCreateSettings(), cfg)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (f *nopProcessorFactory) Type() config.Type {
// CreateDefaultConfig creates the default configuration for the Processor.
func (f *nopProcessorFactory) CreateDefaultConfig() config.Processor {
return &nopProcessorConfig{
ProcessorSettings: config.NewProcessorSettings(config.NewID("nop")),
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewNopProcessorFactory(t *testing.T) {
require.NotNil(t, factory)
assert.Equal(t, config.Type("nop"), factory.Type())
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(config.NewID("nop"))}, cfg)
assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop"))}, cfg)

traces, err := factory.CreateTracesProcessor(context.Background(), NewNopProcessorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions component/componenttest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func NewNopReceiverFactory() component.ReceiverFactory {

// Type gets the type of the Receiver config created by this factory.
func (f *nopReceiverFactory) Type() config.Type {
return config.NewID("nop").Type()
return config.NewComponentID("nop").Type()
}

// CreateDefaultConfig creates the default configuration for the Receiver.
func (f *nopReceiverFactory) CreateDefaultConfig() config.Receiver {
return &nopReceiverConfig{
ReceiverSettings: config.NewReceiverSettings(config.NewID("nop")),
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNewNopReceiverFactory(t *testing.T) {
require.NotNil(t, factory)
assert.Equal(t, config.Type("nop"), factory.Type())
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(config.NewID("nop"))}, cfg)
assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop"))}, cfg)

traces, err := factory.CreateTracesReceiver(context.Background(), NewNopReceiverCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion component/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestBaseProcessorFactory(t *testing.T) {
bpf.CreateDefaultConfig()
})
assert.NotPanics(t, bpf.unexportedProcessor)
defaultCfg := config.NewProcessorSettings(config.NewID("nop"))
defaultCfg := config.NewProcessorSettings(config.NewComponentID("nop"))
_, err := bpf.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, consumertest.NewNop())
assert.ErrorIs(t, err, componenterror.ErrDataTypeIsNotSupported)
_, err = bpf.CreateMetricsProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, consumertest.NewNop())
Expand Down
48 changes: 24 additions & 24 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type nopRecvConfig struct {
}

func (nc *nopRecvConfig) Validate() error {
if nc.ID() != NewID("nop") {
if nc.ID() != NewComponentID("nop") {
return errInvalidRecvConfig
}
return nil
Expand All @@ -44,7 +44,7 @@ type nopExpConfig struct {
}

func (nc *nopExpConfig) Validate() error {
if nc.ID() != NewID("nop") {
if nc.ID() != NewComponentID("nop") {
return errInvalidExpConfig
}
return nil
Expand All @@ -55,7 +55,7 @@ type nopProcConfig struct {
}

func (nc *nopProcConfig) Validate() error {
if nc.ID() != NewID("nop") {
if nc.ID() != NewComponentID("nop") {
return errInvalidProcConfig
}
return nil
Expand All @@ -66,7 +66,7 @@ type nopExtConfig struct {
}

func (nc *nopExtConfig) Validate() error {
if nc.ID() != NewID("nop") {
if nc.ID() != NewComponentID("nop") {
return errInvalidExtConfig
}
return nil
Expand Down Expand Up @@ -173,8 +173,8 @@ func TestConfigValidate(t *testing.T) {
name: "invalid-receiver-config",
cfgFn: func() *Config {
cfg := generateConfig()
cfg.Receivers[NewID("nop")] = &nopRecvConfig{
ReceiverSettings: NewReceiverSettings(NewID("invalid_rec_type")),
cfg.Receivers[NewComponentID("nop")] = &nopRecvConfig{
ReceiverSettings: NewReceiverSettings(NewComponentID("invalid_rec_type")),
}
return cfg
},
Expand All @@ -184,8 +184,8 @@ func TestConfigValidate(t *testing.T) {
name: "invalid-exporter-config",
cfgFn: func() *Config {
cfg := generateConfig()
cfg.Exporters[NewID("nop")] = &nopExpConfig{
ExporterSettings: NewExporterSettings(NewID("invalid_rec_type")),
cfg.Exporters[NewComponentID("nop")] = &nopExpConfig{
ExporterSettings: NewExporterSettings(NewComponentID("invalid_rec_type")),
}
return cfg
},
Expand All @@ -195,8 +195,8 @@ func TestConfigValidate(t *testing.T) {
name: "invalid-processor-config",
cfgFn: func() *Config {
cfg := generateConfig()
cfg.Processors[NewID("nop")] = &nopProcConfig{
ProcessorSettings: NewProcessorSettings(NewID("invalid_rec_type")),
cfg.Processors[NewComponentID("nop")] = &nopProcConfig{
ProcessorSettings: NewProcessorSettings(NewComponentID("invalid_rec_type")),
}
return cfg
},
Expand All @@ -206,8 +206,8 @@ func TestConfigValidate(t *testing.T) {
name: "invalid-extension-config",
cfgFn: func() *Config {
cfg := generateConfig()
cfg.Extensions[NewID("nop")] = &nopExtConfig{
ExtensionSettings: NewExtensionSettings(NewID("invalid_rec_type")),
cfg.Extensions[NewComponentID("nop")] = &nopExtConfig{
ExtensionSettings: NewExtensionSettings(NewComponentID("invalid_rec_type")),
}
return cfg
},
Expand Down Expand Up @@ -235,35 +235,35 @@ func TestConfigValidate(t *testing.T) {
func generateConfig() *Config {
return &Config{
Receivers: map[ComponentID]Receiver{
NewID("nop"): &nopRecvConfig{
ReceiverSettings: NewReceiverSettings(NewID("nop")),
NewComponentID("nop"): &nopRecvConfig{
ReceiverSettings: NewReceiverSettings(NewComponentID("nop")),
},
},
Exporters: map[ComponentID]Exporter{
NewID("nop"): &nopExpConfig{
ExporterSettings: NewExporterSettings(NewID("nop")),
NewComponentID("nop"): &nopExpConfig{
ExporterSettings: NewExporterSettings(NewComponentID("nop")),
},
},
Processors: map[ComponentID]Processor{
NewID("nop"): &nopProcConfig{
ProcessorSettings: NewProcessorSettings(NewID("nop")),
NewComponentID("nop"): &nopProcConfig{
ProcessorSettings: NewProcessorSettings(NewComponentID("nop")),
},
},
Extensions: map[ComponentID]Extension{
NewID("nop"): &nopExtConfig{
ExtensionSettings: NewExtensionSettings(NewID("nop")),
NewComponentID("nop"): &nopExtConfig{
ExtensionSettings: NewExtensionSettings(NewComponentID("nop")),
},
},
Service: Service{
Telemetry: ServiceTelemetry{Logs: ServiceTelemetryLogs{Level: zapcore.DebugLevel, Development: true, Encoding: "console"}},
Extensions: []ComponentID{NewID("nop")},
Extensions: []ComponentID{NewComponentID("nop")},
Pipelines: map[string]*Pipeline{
"traces": {
Name: "traces",
InputType: TracesDataType,
Receivers: []ComponentID{NewID("nop")},
Processors: []ComponentID{NewID("nop")},
Exporters: []ComponentID{NewID("nop")},
Receivers: []ComponentID{NewComponentID("nop")},
Processors: []ComponentID{NewComponentID("nop")},
Exporters: []ComponentID{NewComponentID("nop")},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions config/configauth/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func TestGetAuthenticator(t *testing.T) {
AuthenticatorName: "mock",
}
ext := map[config.ComponentID]component.Extension{
config.NewID("mock"): &MockAuthenticator{},
config.NewComponentID("mock"): &MockAuthenticator{},
}

// test
componentID, err := config.NewIDFromString(cfg.AuthenticatorName)
componentID, err := config.NewComponentIDFromString(cfg.AuthenticatorName)
assert.NoError(t, err)

authenticator, err := GetServerAuthenticator(ext, componentID)
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestGetAuthenticatorFails(t *testing.T) {
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
componentID, err := config.NewIDFromString(tC.cfg.AuthenticatorName)
componentID, err := config.NewComponentIDFromString(tC.cfg.AuthenticatorName)
assert.NoError(t, err)
authenticator, err := GetServerAuthenticator(tC.ext, componentID)
assert.ErrorIs(t, err, tC.expected)
Expand Down
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (gcs *GRPCClientSettings) ToDialOptions(host component.Host) ([]grpc.DialOp
return nil, fmt.Errorf("no extensions configuration available")
}

componentID, cperr := config.NewIDFromString(gcs.Auth.AuthenticatorName)
componentID, cperr := config.NewComponentIDFromString(gcs.Auth.AuthenticatorName)
if cperr != nil {
return nil, cperr
}
Expand Down Expand Up @@ -333,7 +333,7 @@ func (gss *GRPCServerSettings) ToServerOption(host component.Host, settings comp
sInterceptors := []grpc.StreamServerInterceptor{}

if gss.Auth != nil {
componentID, cperr := config.NewIDFromString(gss.Auth.AuthenticatorName)
componentID, cperr := config.NewComponentIDFromString(gss.Auth.AuthenticatorName)
if cperr != nil {
return nil, cperr
}
Expand Down
6 changes: 3 additions & 3 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestAllGrpcClientSettings(t *testing.T) {

host := &mockHost{
ext: map[config.ComponentID]component.Extension{
config.NewID("testauth"): &configauth.MockClientAuthenticator{},
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{},
},
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestGrpcServerAuthSettings(t *testing.T) {
}
host := &mockHost{
ext: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockAuthenticator{},
config.NewComponentID("mock"): &configauth.MockAuthenticator{},
},
}
opts, err := gss.ToServerOption(host, componenttest.NewNopTelemetrySettings())
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
Auth: &configauth.Authentication{},
},
host: &mockHost{ext: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockClientAuthenticator{},
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{},
}},
},
{
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext
return nil, fmt.Errorf("extensions configuration not found")
}

componentID, cperr := config.NewIDFromString(hcs.Auth.AuthenticatorName)
componentID, cperr := config.NewComponentIDFromString(hcs.Auth.AuthenticatorName)
if cperr != nil {
return nil, cperr
}
Expand Down
10 changes: 5 additions & 5 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *customRoundTripper) RoundTrip(request *http.Request) (*http.Response, e

func TestAllHTTPClientSettings(t *testing.T) {
ext := map[config.ComponentID]component.Extension{
config.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
}
tests := []struct {
name string
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: false,
extensionMap: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockClientAuthenticator{
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{
ResultRoundTripper: &customRoundTripper{},
},
},
Expand All @@ -178,7 +178,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: true,
extensionMap: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
},
{
Expand All @@ -197,7 +197,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: false,
extensionMap: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
},
},
{
Expand All @@ -208,7 +208,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
shouldErr: true,
extensionMap: map[config.ComponentID]component.Extension{
config.NewID("mock"): &configauth.MockClientAuthenticator{
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{
ResultRoundTripper: &customRoundTripper{}, MustError: true},
},
},
Expand Down
16 changes: 8 additions & 8 deletions config/configtest/configtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ func TestLoadConfig(t *testing.T) {

// Verify extensions.
require.Len(t, cfg.Extensions, 2)
assert.Contains(t, cfg.Extensions, config.NewID("nop"))
assert.Contains(t, cfg.Extensions, config.NewComponentID("nop"))
assert.Contains(t, cfg.Extensions, config.NewIDWithName("nop", "myextension"))

// Verify receivers
require.Len(t, cfg.Receivers, 2)
assert.Contains(t, cfg.Receivers, config.NewID("nop"))
assert.Contains(t, cfg.Receivers, config.NewComponentID("nop"))
assert.Contains(t, cfg.Receivers, config.NewIDWithName("nop", "myreceiver"))

// Verify exporters
assert.Len(t, cfg.Exporters, 2)
assert.Contains(t, cfg.Exporters, config.NewID("nop"))
assert.Contains(t, cfg.Exporters, config.NewComponentID("nop"))
assert.Contains(t, cfg.Exporters, config.NewIDWithName("nop", "myexporter"))

// Verify Processors
assert.Len(t, cfg.Processors, 2)
assert.Contains(t, cfg.Processors, config.NewID("nop"))
assert.Contains(t, cfg.Processors, config.NewComponentID("nop"))
assert.Contains(t, cfg.Processors, config.NewIDWithName("nop", "myprocessor"))

// Verify service.
require.Len(t, cfg.Service.Extensions, 1)
assert.Contains(t, cfg.Service.Extensions, config.NewID("nop"))
assert.Contains(t, cfg.Service.Extensions, config.NewComponentID("nop"))
require.Len(t, cfg.Service.Pipelines, 1)
assert.Equal(t,
&config.Pipeline{
Name: "traces",
InputType: config.TracesDataType,
Receivers: []config.ComponentID{config.NewID("nop")},
Processors: []config.ComponentID{config.NewID("nop")},
Exporters: []config.ComponentID{config.NewID("nop")},
Receivers: []config.ComponentID{config.NewComponentID("nop")},
Processors: []config.ComponentID{config.NewComponentID("nop")},
Exporters: []config.ComponentID{config.NewComponentID("nop")},
},
cfg.Service.Pipelines["traces"],
"Did not load pipeline config correctly")
Expand Down
Loading

0 comments on commit 85b8094

Please sign in to comment.