Skip to content

Commit

Permalink
[confmap] Mark confmap.strictlyTypedInput as stable (#10793)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

<!-- Issue number if applicable -->

Marks `confmap.strictlyTypedInput` as stable.

#### Link to tracking issue

Fixes #10552

Blocked by:
- #10794
- #10795
  • Loading branch information
mx-psi authored Aug 20, 2024
1 parent d2ed276 commit e477c3a
Show file tree
Hide file tree
Showing 80 changed files with 50 additions and 902 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_strict-typing-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confmap

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Mark `confmap.strictlyTypedInput` as stable

# One or more tracking issues or pull requests related to the change
issues: [10552]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
5 changes: 0 additions & 5 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.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 @@ -48,8 +47,6 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.107.0 // indirect
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.107.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
Expand Down Expand Up @@ -95,8 +92,6 @@ retract (

replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile

replace go.opentelemetry.io/collector/internal/globalgates => ../../internal/globalgates

replace go.opentelemetry.io/collector/consumer/consumerprofiles => ../../consumer/consumerprofiles

replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/consumertest
Expand Down
2 changes: 0 additions & 2 deletions cmd/mdatagen/go.sum

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

7 changes: 0 additions & 7 deletions config/configauth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/hashicorp/go-version v1.7.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.1 // indirect
Expand All @@ -23,8 +22,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.107.0 // indirect
go.opentelemetry.io/collector/confmap v0.107.0 // indirect
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata v1.13.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
Expand Down Expand Up @@ -52,8 +49,4 @@ replace go.opentelemetry.io/collector/extension => ../../extension

replace go.opentelemetry.io/collector/extension/auth => ../../extension/auth

replace go.opentelemetry.io/collector/featuregate => ../../featuregate

replace go.opentelemetry.io/collector/internal/globalgates => ../../internal/globalgates

replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus
2 changes: 0 additions & 2 deletions config/configauth/go.sum

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

3 changes: 0 additions & 3 deletions config/configgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/collector/confmap v0.107.0 // indirect
go.opentelemetry.io/collector/extension v0.107.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.107.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
Expand All @@ -73,8 +72,6 @@ require (

replace go.opentelemetry.io/collector => ../../

replace go.opentelemetry.io/collector/internal/globalgates => ../../internal/globalgates

replace go.opentelemetry.io/collector/client => ../../client

replace go.opentelemetry.io/collector/config/configauth => ../configauth
Expand Down
3 changes: 0 additions & 3 deletions config/confighttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/collector/confmap v0.107.0 // indirect
go.opentelemetry.io/collector/extension v0.107.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
Expand All @@ -68,8 +67,6 @@ require (

replace go.opentelemetry.io/collector => ../../

replace go.opentelemetry.io/collector/internal/globalgates => ../../internal/globalgates

replace go.opentelemetry.io/collector/config/configauth => ../configauth

replace go.opentelemetry.io/collector/config/configcompression => ../configcompression
Expand Down
2 changes: 0 additions & 2 deletions config/internal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata

replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile

replace go.opentelemetry.io/collector/internal/globalgates => ../../internal/globalgates

replace go.opentelemetry.io/collector/consumer/consumerprofiles => ../../consumer/consumerprofiles

replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/consumertest
Expand Down
5 changes: 2 additions & 3 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/knadh/koanf/v2"

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

const (
Expand Down Expand Up @@ -187,7 +186,7 @@ func decodeConfig(m *Conf, result any, errorUnused bool, skipTopLevelUnmarshaler
ErrorUnused: errorUnused,
Result: result,
TagName: "mapstructure",
WeaklyTypedInput: !globalgates.StrictlyTypedInputGate.IsEnabled(),
WeaklyTypedInput: false,
MatchName: caseSensitiveMatchName,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
useExpandValue(),
Expand Down Expand Up @@ -239,7 +238,7 @@ func caseSensitiveMatchName(a, b string) bool {

func castTo(exp expandedValue, useOriginal bool) (any, error) {
// If the target field is a string, use `exp.Original` or fail if not available.
if globalgates.StrictlyTypedInputGate.IsEnabled() && useOriginal {
if useOriginal {
return exp.Original, nil
}
// Otherwise, use the parsed value (previous behavior).
Expand Down
7 changes: 0 additions & 7 deletions confmap/converter/expandconverter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/hashicorp/go-version v1.7.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.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
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace go.opentelemetry.io/collector/confmap => ../..

replace go.opentelemetry.io/collector/featuregate => ../../../featuregate

replace go.opentelemetry.io/collector/internal/globalgates => ../../../internal/globalgates
2 changes: 0 additions & 2 deletions confmap/converter/expandconverter/go.sum

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

34 changes: 1 addition & 33 deletions confmap/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import (
"context"
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"strings"

"go.opentelemetry.io/collector/internal/globalgates"
)

// schemePattern defines the regexp pattern for scheme names.
Expand Down Expand Up @@ -192,41 +188,13 @@ func (mr *Resolver) findAndExpandURI(ctx context.Context, input string) (any, bo
return input, false, err
}

var repl string
if globalgates.StrictlyTypedInputGate.IsEnabled() {
repl, err = expanded.AsString()
} else {
repl, err = toString(expanded)
}
repl, err := expanded.AsString()
if err != nil {
return input, false, fmt.Errorf("expanding %v: %w", uri, err)
}
return strings.ReplaceAll(input, uri, repl), true, err
}

// toString attempts to convert input to a string.
func toString(ret *Retrieved) (string, error) {
// This list must be kept in sync with checkRawConfType.
input, err := ret.AsRaw()
if err != nil {
return "", err
}

val := reflect.ValueOf(input)
switch val.Kind() {
case reflect.String:
return val.String(), nil
case reflect.Int, reflect.Int32, reflect.Int64:
return strconv.FormatInt(val.Int(), 10), nil
case reflect.Float32, reflect.Float64:
return strconv.FormatFloat(val.Float(), 'f', -1, 64), nil
case reflect.Bool:
return strconv.FormatBool(val.Bool()), nil
default:
return "", fmt.Errorf("expected convertable to string value type, got %q(%T)", input, input)
}
}

func (mr *Resolver) expandURI(ctx context.Context, input string) (*Retrieved, error) {
// strip ${ and }
uri := input[2 : len(input)-1]
Expand Down
10 changes: 3 additions & 7 deletions confmap/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/knadh/koanf/providers/confmap v0.1.0
github.com/knadh/koanf/v2 v2.1.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/internal/globalgates v0.107.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand All @@ -17,18 +16,15 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/go-version v1.7.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
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

retract (
v0.76.0 // Depends on retracted pdata v1.0.0-rc10 module, use v0.76.1
v0.69.0 // Release failed, use v0.69.1
)

replace go.opentelemetry.io/collector/featuregate => ../featuregate

replace go.opentelemetry.io/collector/internal/globalgates => ../internal/globalgates
8 changes: 6 additions & 2 deletions confmap/go.sum

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

7 changes: 0 additions & 7 deletions confmap/internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ require (
go.opentelemetry.io/collector/confmap v0.107.0
go.opentelemetry.io/collector/confmap/provider/envprovider v0.107.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.107.0
go.opentelemetry.io/collector/featuregate v1.13.0
go.opentelemetry.io/collector/internal/globalgates v0.107.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/hashicorp/go-version v1.7.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.1 // indirect
Expand All @@ -31,7 +28,3 @@ replace go.opentelemetry.io/collector/confmap => ../../
replace go.opentelemetry.io/collector/confmap/provider/fileprovider => ../../provider/fileprovider

replace go.opentelemetry.io/collector/confmap/provider/envprovider => ../../provider/envprovider

replace go.opentelemetry.io/collector/featuregate => ../../../featuregate

replace go.opentelemetry.io/collector/internal/globalgates => ../../../internal/globalgates
2 changes: 0 additions & 2 deletions confmap/internal/e2e/go.sum

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

Loading

0 comments on commit e477c3a

Please sign in to comment.