Skip to content

Commit

Permalink
[DO NOT MERGE] Disable WeaklyTypedInput
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Apr 8, 2024
1 parent c6d1482 commit ceb4939
Show file tree
Hide file tree
Showing 64 changed files with 204 additions and 59 deletions.
2 changes: 2 additions & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
Expand All @@ -44,6 +45,7 @@ require (
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.97.0 // indirect
go.opentelemetry.io/collector/featuregate v0.0.0-00010101000000-000000000000 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.46.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cmd/mdatagen/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/mdatagen/internal/samplereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ metrics:
optional.metric:
enabled: false
description: "[DEPRECATED] Gauge double metric disabled by default."
unit: 1
unit: "1"
gauge:
value_type: double
attributes: [string_attr, boolean_attr]
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/testdata/invalid_type_attr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ metrics:
metric:
enabled: true
description: Metric.
unit: 1
unit: "1"
gauge:
value_type: double
attributes: [used_attr]
2 changes: 1 addition & 1 deletion cmd/mdatagen/testdata/no_type_attr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ metrics:
metric:
enabled: true
description: Metric.
unit: 1
unit: "1"
gauge:
value_type: double
attributes: [used_attr]
2 changes: 1 addition & 1 deletion cmd/mdatagen/testdata/unused_attribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metrics:
metric:
enabled: true
description: Metric.
unit: 1
unit: "1"
gauge:
value_type: double
attributes: [used_attr]
2 changes: 2 additions & 0 deletions component/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ require (
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions component/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/configauth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
Expand All @@ -23,6 +24,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.97.0 // indirect
go.opentelemetry.io/collector/confmap v0.97.0 // indirect
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
go.opentelemetry.io/collector/pdata v1.4.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions config/configauth/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions config/configopaque/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

replace go.opentelemetry.io/collector/confmap => ../../confmap
10 changes: 4 additions & 6 deletions config/configopaque/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/configtls/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 5 additions & 9 deletions config/configtls/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/knadh/koanf/v2"

encoder "go.opentelemetry.io/collector/confmap/internal/mapstructure"
"go.opentelemetry.io/collector/featuregate"
)

const (
Expand Down Expand Up @@ -139,6 +140,16 @@ func (l *Conf) ToStringMap() map[string]any {
return maps.Unflatten(l.k.All(), KeyDelimiter)
}

const DisableWeaklyTyped = "confmap.DisableWeaklyTypedInput"

// DisableWeaklyTypedfeatureGate is the feature gate that disables weakly typed input option in confmap.
var DisableWeaklyTypedfeatureGate = featuregate.GlobalRegistry().MustRegister(
DisableWeaklyTyped,
featuregate.StageBeta,
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector/issues/9532"),
featuregate.WithRegisterDescription("disables weakly typed input option in confmap"),
)

// decodeConfig decodes the contents of the Conf into the result argument, using a
// mapstructure decoder with the following notable behaviors. Ensures that maps whose
// values are nil pointer structs resolved to the zero value of the target struct (see
Expand All @@ -148,11 +159,10 @@ func (l *Conf) ToStringMap() map[string]any {
// encoding.TextUnmarshaler. Allows custom unmarshaling for structs implementing confmap.Unmarshaler.
func decodeConfig(m *Conf, result any, errorUnused bool) error {
dc := &mapstructure.DecoderConfig{
ErrorUnused: errorUnused,
Result: result,
TagName: "mapstructure",
WeaklyTypedInput: true,
MatchName: caseSensitiveMatchName,
ErrorUnused: errorUnused,
Result: result,
TagName: "mapstructure",
MatchName: caseSensitiveMatchName,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
expandNilStructPointersHookFunc(),
mapstructure.StringToSliceHookFunc(","),
Expand All @@ -166,6 +176,9 @@ func decodeConfig(m *Conf, result any, errorUnused bool) error {
zeroSliceHookFunc(),
),
}
if !DisableWeaklyTypedfeatureGate.IsEnabled() {
dc.WeaklyTypedInput = true
}
decoder, err := mapstructure.NewDecoder(dc)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions confmap/converter/expandconverter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/featuregate v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit ceb4939

Please sign in to comment.