Skip to content

Commit

Permalink
[component] Bump maximum length for component names to 1024 characters (
Browse files Browse the repository at this point in the history
#10818)

#### Description

Bumps component name length limit to 1024 characters.

#### Link to tracking issue

Fixes #10816

#### Testing

Added some unit tests.
  • Loading branch information
mx-psi authored Aug 7, 2024
1 parent 1de1bf1 commit 72c7d7f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_limit-for-component-names.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: bug_fix

# 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: Allow component names of up to 1024 characters in length.

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

# (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: []
7 changes: 5 additions & 2 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ var (
)

// nameRegexp is used to validate the name of a component. A name can consist of
// 1 to 63 unicode characters excluding whitespace, control characters, and
// 1 to 1024 unicode characters excluding whitespace, control characters, and
// symbols.
var nameRegexp = regexp.MustCompile(`^[^\pZ\pC\pS]{1,63}$`)
var nameRegexp = regexp.MustCompile(`^[^\pZ\pC\pS]+$`)

func validateName(nameStr string) error {
if len(nameStr) > 1024 {
return fmt.Errorf("name %q is longer than 1024 characters (%d characters)", nameStr, len(nameStr))
}
if !nameRegexp.MatchString(nameStr) {
return fmt.Errorf("invalid character(s) in name %q", nameStr)
}
Expand Down
10 changes: 10 additions & 0 deletions component/identifiable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package component

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,6 +44,11 @@ func TestUnmarshalText(t *testing.T) {
idStr: "valid_type/name-with-dashes",
expectedID: ID{typeVal: validType, nameVal: "name-with-dashes"},
},
// issue 10816
{
idStr: "valid_type/Linux-Messages-File_01J49HCH3SWFXRVASWFZFRT3J2__processor0__logs",
expectedID: ID{typeVal: validType, nameVal: "Linux-Messages-File_01J49HCH3SWFXRVASWFZFRT3J2__processor0__logs"},
},
{
idStr: "valid_type/1",
expectedID: ID{typeVal: validType, nameVal: "1"},
Expand Down Expand Up @@ -71,6 +77,10 @@ func TestUnmarshalText(t *testing.T) {
idStr: "valid_type/invalid name",
expectedErr: true,
},
{
idStr: "valid_type/" + strings.Repeat("a", 1025),
expectedErr: true,
},
}

for _, test := range testCases {
Expand Down

0 comments on commit 72c7d7f

Please sign in to comment.