Skip to content

Commit fce1d46

Browse files
atoulmemx-psi
andauthored
[chore] rely on strict input parsing to error out on invalid unsigned int values (#10609)
This removes a hook for confmap that was used to handle invalid uint values, now that #9532 is fixed. Co-authored-by: Pablo Baeyens <[email protected]>
1 parent e477c3a commit fce1d46

File tree

3 files changed

+3
-17
lines changed

3 files changed

+3
-17
lines changed

confmap/confmap.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ func decodeConfig(m *Conf, result any, errorUnused bool, skipTopLevelUnmarshaler
200200
// we unmarshal the embedded structs if present to merge with the result:
201201
unmarshalerEmbeddedStructsHookFunc(),
202202
zeroSliceHookFunc(),
203-
negativeUintHookFunc(),
204203
),
205204
}
206205
decoder, err := mapstructure.NewDecoder(dc)
@@ -499,19 +498,6 @@ func zeroSliceHookFunc() mapstructure.DecodeHookFuncValue {
499498
}
500499
}
501500

502-
// This hook is used to solve the issue: https://github.com/open-telemetry/opentelemetry-collector/issues/9060
503-
// Decoding should fail when converting a negative integer to any type of unsigned integer. This prevents
504-
// negative values being decoded as large uint values.
505-
// TODO: This should be removed as a part of https://github.com/open-telemetry/opentelemetry-collector/issues/9532
506-
func negativeUintHookFunc() mapstructure.DecodeHookFuncValue {
507-
return func(from reflect.Value, to reflect.Value) (interface{}, error) {
508-
if from.CanInt() && from.Int() < 0 && to.CanUint() {
509-
return nil, fmt.Errorf("cannot convert negative value %v to an unsigned integer", from.Int())
510-
}
511-
return from.Interface(), nil
512-
}
513-
}
514-
515501
type moduleFactory[T any, S any] interface {
516502
Create(s S) T
517503
}

confmap/confmap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func TestUintUnmarshalerFailure(t *testing.T) {
279279
err := conf.Unmarshal(cfg)
280280

281281
assert.Error(t, err)
282-
assert.Contains(t, err.Error(), fmt.Sprintf("decoding failed due to the following error(s):\n\nerror decoding 'uint_test': cannot convert negative value %v to an unsigned integer", testValue))
282+
assert.Contains(t, err.Error(), fmt.Sprintf("decoding failed due to the following error(s):\n\ncannot parse 'uint_test', %d overflows uint", testValue))
283283
}
284284

285285
func TestMapKeyStringToMapKeyTextUnmarshalerHookFuncDuplicateID(t *testing.T) {

internal/memorylimiter/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ func TestUnmarshalInvalidConfig(t *testing.T) {
9999
cfg := &Config{}
100100
err = cm.Unmarshal(&cfg)
101101
require.Error(t, err)
102-
require.Contains(t, err.Error(), "error decoding 'limit_mib': cannot convert negative value -2000 to an unsigned integer")
103-
require.Contains(t, err.Error(), "error decoding 'spike_limit_mib': cannot convert negative value -2300 to an unsigned integer")
102+
require.Contains(t, err.Error(), "cannot parse 'limit_mib', -2000 overflows uint")
103+
require.Contains(t, err.Error(), "cannot parse 'spike_limit_mib', -2300 overflows uint")
104104
}

0 commit comments

Comments
 (0)