Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] relax checks on confmap validation #34068

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[chore] relax checks on confmap validation to avoid running into issu…
…es with mapstructure upgrades
  • Loading branch information
atoulme committed Jul 14, 2024
commit d5f86f965ee24c360075c67b820fade06254706a
10 changes: 5 additions & 5 deletions exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestUnmarshal(t *testing.T) {
},
},
}),
err: "1 error(s) decoding:\n\n* error decoding 'metrics.sums.cumulative_monotonic_mode': invalid cumulative monotonic sum mode \"invalid_mode\"",
err: "invalid cumulative monotonic sum mode \"invalid_mode\"",
atoulme marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "invalid host metadata hostname source",
Expand All @@ -215,7 +215,7 @@ func TestUnmarshal(t *testing.T) {
"hostname_source": "invalid_source",
},
}),
err: "1 error(s) decoding:\n\n* error decoding 'host_metadata.hostname_source': invalid host metadata hostname source \"invalid_source\"",
err: "invalid host metadata hostname source \"invalid_source\"",
},
{
name: "invalid summary mode",
Expand All @@ -226,7 +226,7 @@ func TestUnmarshal(t *testing.T) {
},
},
}),
err: "1 error(s) decoding:\n\n* error decoding 'metrics.summaries.mode': invalid summary mode \"invalid_mode\"",
err: "invalid summary mode \"invalid_mode\"",
},
{
name: "metrics::send_monotonic_counter custom error",
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestUnmarshal(t *testing.T) {
},
},
}),
err: "1 error(s) decoding:\n\n* error decoding 'metrics.sums.initial_cumulative_monotonic_value': invalid initial value mode \"invalid_mode\"",
err: "invalid initial value mode \"invalid_mode\"",
},
{
name: "initial cumulative monotonic value mode set with raw_value",
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestUnmarshal(t *testing.T) {
cfg := f.CreateDefaultConfig().(*Config)
err := cfg.Unmarshal(testInstance.configMap)
if err != nil || testInstance.err != "" {
assert.EqualError(t, err, testInstance.err)
assert.ErrorContains(t, err, testInstance.err)
} else {
assert.Equal(t, testInstance.cfg, cfg)
}
Expand Down
5 changes: 1 addition & 4 deletions exporter/datasetexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ func TestConfigUnmarshalUnknownAttributes(t *testing.T) {
})
err := configMap.Unmarshal(config)

unmarshalErr := fmt.Errorf("1 error(s) decoding:\n\n* '' has invalid keys: unknown_attribute")
expectedError := fmt.Errorf("cannot unmarshal config: %w", unmarshalErr)

assert.Equal(t, expectedError.Error(), err.Error())
assert.ErrorContains(t, err, "has invalid keys: unknown_attribute")
}

func TestConfigUseDefaults(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/logicmonitorexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestUnmarshal(t *testing.T) {
"resource_mapping_op": "invalid_op",
},
}),
err: "1 error(s) decoding:\n\n* error decoding 'logs.resource_mapping_op': unsupported mapping operation \"invalid_op\"",
err: "unsupported mapping operation \"invalid_op\"",
},
}

Expand All @@ -183,7 +183,7 @@ func TestUnmarshal(t *testing.T) {
cfg := f.CreateDefaultConfig().(*Config)
err := tt.configMap.Unmarshal(cfg)
if err != nil || tt.err != "" {
assert.EqualError(t, err, tt.err)
assert.ErrorContains(t, err, tt.err)
} else {
assert.Equal(t, tt.cfg, cfg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ property_value: '!/property.value/'`,
{
name: "invalid regex",
yaml: "dimension_name: '/(?=not.in.re2)/'",
expectedError: "1 error(s) decoding:\n\n* error decoding 'dimension_name': error parsing regexp: invalid or unsupported Perl syntax: `(?=`",
expectedError: "error parsing regexp: invalid or unsupported Perl syntax: `(?=`",
},
{
name: "invalid glob",
yaml: "dimension_value: '*[c-a]'",
expectedError: "1 error(s) decoding:\n\n* error decoding 'dimension_value': hi character 'a' should be greater than lo 'c'",
expectedError: "hi character 'a' should be greater than lo 'c'",
},
} {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -74,7 +74,7 @@ property_value: '!/property.value/'`,
pf := &PropertyFilter{}
err = cm.Unmarshal(pf)
if test.expectedError != "" {
require.EqualError(t, err, test.expectedError)
require.ErrorContains(t, err, test.expectedError)
} else {
require.NoError(t, err)
require.Equal(t, test.expectedPropertyFilter, *pf)
Expand Down
4 changes: 2 additions & 2 deletions receiver/jaegerreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ func TestFailedLoadConfig(t *testing.T) {
sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "typo_default_proto_config").String())
require.NoError(t, err)
err = sub.Unmarshal(cfg)
assert.EqualError(t, err, "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift_htttp")
assert.ErrorContains(t, err, "'protocols' has invalid keys: thrift_htttp")

sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "bad_proto_config").String())
require.NoError(t, err)
err = sub.Unmarshal(cfg)
assert.EqualError(t, err, "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift_htttp")
assert.ErrorContains(t, err, "'protocols' has invalid keys: thrift_htttp")

sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "empty").String())
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions receiver/otelarrowreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func TestUnmarshalConfigTypoDefaultProtocol(t *testing.T) {
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.EqualError(t, cm.Unmarshal(cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: htttp")
assert.ErrorContains(t, cm.Unmarshal(cfg), "'protocols' has invalid keys: htttp")
}

func TestUnmarshalConfigInvalidProtocol(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "bad_proto_config.yaml"))
require.NoError(t, err)
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.EqualError(t, cm.Unmarshal(cfg), "1 error(s) decoding:\n\n* 'protocols' has invalid keys: thrift")
assert.ErrorContains(t, cm.Unmarshal(cfg), "'protocols' has invalid keys: thrift")
}

func TestUnmarshalConfigNoProtocols(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions receiver/receivercreator/observerhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestOnAddForMetrics(t *testing.T) {
name: "inherits unsupported endpoint",
receiverTemplateID: component.MustNewIDWithName("without_endpoint", "some.name"),
receiverTemplateConfig: userConfigMap{"endpoint": "unsupported.endpoint"},
expectedError: "failed to load \"without_endpoint/some.name\" template config: 1 error(s) decoding:\n\n* '' has invalid keys: endpoint",
expectedError: "'' has invalid keys: endpoint",
},
} {
t.Run(test.name, func(t *testing.T) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestOnAddForMetrics(t *testing.T) {
if test.expectedError != "" {
assert.Equal(t, 0, handler.receiversByEndpointID.Size())
require.Error(t, mr.lastError)
require.EqualError(t, mr.lastError, test.expectedError)
require.ErrorContains(t, mr.lastError, test.expectedError)
require.Nil(t, mr.startedComponent)
return
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestOnAddForLogs(t *testing.T) {
name: "inherits unsupported endpoint",
receiverTemplateID: component.MustNewIDWithName("without_endpoint", "some.name"),
receiverTemplateConfig: userConfigMap{"endpoint": "unsupported.endpoint"},
expectedError: "failed to load \"without_endpoint/some.name\" template config: 1 error(s) decoding:\n\n* '' has invalid keys: endpoint",
expectedError: "'' has invalid keys: endpoint",
},
} {
t.Run(test.name, func(t *testing.T) {
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestOnAddForLogs(t *testing.T) {
if test.expectedError != "" {
assert.Equal(t, 0, handler.receiversByEndpointID.Size())
require.Error(t, mr.lastError)
require.EqualError(t, mr.lastError, test.expectedError)
require.ErrorContains(t, mr.lastError, test.expectedError)
require.Nil(t, mr.startedComponent)
return
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestOnAddForTraces(t *testing.T) {
name: "inherits unsupported endpoint",
receiverTemplateID: component.MustNewIDWithName("without_endpoint", "some.name"),
receiverTemplateConfig: userConfigMap{"endpoint": "unsupported.endpoint"},
expectedError: "failed to load \"without_endpoint/some.name\" template config: 1 error(s) decoding:\n\n* '' has invalid keys: endpoint",
expectedError: "'' has invalid keys: endpoint",
},
} {
t.Run(test.name, func(t *testing.T) {
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestOnAddForTraces(t *testing.T) {
if test.expectedError != "" {
assert.Equal(t, 0, handler.receiversByEndpointID.Size())
require.Error(t, mr.lastError)
require.EqualError(t, mr.lastError, test.expectedError)
require.ErrorContains(t, mr.lastError, test.expectedError)
require.Nil(t, mr.startedComponent)
return
}
Expand Down
Loading