diff --git a/.chloggen/mx-psi_switch-to-type.yaml b/.chloggen/mx-psi_switch-to-type.yaml new file mode 100755 index 00000000000..79543c33e92 --- /dev/null +++ b/.chloggen/mx-psi_switch-to-type.yaml @@ -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: component + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change underlying type of `component.Type` to an opaque struct. + +# One or more tracking issues or pull requests related to the change +issues: [9208] + +# (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: [api] diff --git a/component/config.go b/component/config.go index f54b3a176c2..03569aa166b 100644 --- a/component/config.go +++ b/component/config.go @@ -110,11 +110,13 @@ func callValidateIfPossible(v reflect.Value) error { } // Type is the component type as it is used in the config. -type Type string +type Type struct { + name string +} // String returns the string representation of the type. func (t Type) String() string { - return string(t) + return t.name } // typeRegexp is used to validate the type of a component. @@ -130,12 +132,12 @@ var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`) // - can only contain ASCII alphanumeric characters and '_'. func NewType(ty string) (Type, error) { if len(ty) == 0 { - return Type(""), fmt.Errorf("id must not be empty") + return Type{}, fmt.Errorf("id must not be empty") } if !typeRegexp.MatchString(ty) { - return Type(""), fmt.Errorf("invalid character(s) in type %q", ty) + return Type{}, fmt.Errorf("invalid character(s) in type %q", ty) } - return Type(ty), nil + return Type{name: ty}, nil } // MustNewType creates a type. It panics if the type is invalid. @@ -155,14 +157,18 @@ func MustNewType(strType string) Type { // collecting metrics, traces and logs, this can expand in the future. type DataType = Type +func mustNewDataType(strType string) DataType { + return MustNewType(strType) +} + // Currently supported data types. Add new data types here when new types are supported in the future. -const ( +var ( // DataTypeTraces is the data type tag for traces. - DataTypeTraces DataType = "traces" + DataTypeTraces = mustNewDataType("traces") // DataTypeMetrics is the data type tag for metrics. - DataTypeMetrics DataType = "metrics" + DataTypeMetrics = mustNewDataType("metrics") // DataTypeLogs is the data type tag for logs. - DataTypeLogs DataType = "logs" + DataTypeLogs = mustNewDataType("logs") ) diff --git a/component/config_test.go b/component/config_test.go index fcddc343d20..79651959108 100644 --- a/component/config_test.go +++ b/component/config_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" ) -var _ fmt.Stringer = (Type)("") +var _ fmt.Stringer = Type{} type configChildStruct struct { Child errConfig diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index fc90f8f7caf..55e9ce726ca 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -423,7 +423,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension_and_compression", settings: ClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("mock")}, Compression: configcompression.TypeGzip, }, shouldErr: false,