Skip to content

Commit

Permalink
[component] Change component.Type underlying type to a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Feb 6, 2024
1 parent f5a7315 commit 51cf15b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_switch-to-type.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: 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]
20 changes: 11 additions & 9 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -156,13 +158,13 @@ func MustNewType(strType string) Type {
type DataType = Type

// 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 DataType = MustNewType("traces")

// DataTypeMetrics is the data type tag for metrics.
DataTypeMetrics DataType = "metrics"
DataTypeMetrics DataType = MustNewType("metrics")

// DataTypeLogs is the data type tag for logs.
DataTypeLogs DataType = "logs"
DataTypeLogs DataType = MustNewType("logs")
)
2 changes: 1 addition & 1 deletion component/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
)

var _ fmt.Stringer = (Type)("")
var _ fmt.Stringer = Type{}

type configChildStruct struct {
Child errConfig
Expand Down

0 comments on commit 51cf15b

Please sign in to comment.