Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[component] Restrict character set for component.ID name #10674

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

mwear
Copy link
Member

@mwear mwear commented Jul 20, 2024

Description

While working on #10495 we discovered that there are not any restrictions on the name field of a component.ID. There are restrictions on the type field introduced in #9208. This PR adds similar restrictions to name.

A type must

  • have at least one character,
  • start with an ASCII alphabetic character and
  • can only contain ASCII alphanumeric characters and '_'.

I found that we need a slightly different set of rules for name as some tests use a digit and others use a uuid as a name. A name is still optional, but if it's provided it must:

  • have at least one character,
  • start with an ASCII alphanumeric character and
  • can only contain ASCII alphanumeric characters, '_', and '-'.

I'd be willing to adjust these restrictions if anyone has any opinions on what should or should not be allowed.

Link to tracking issue

Fixes #10673

Testing

Unit tests

Documentation

Code comments

@mwear mwear requested review from a team and mx-psi July 20, 2024 00:16
Copy link

codecov bot commented Jul 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.24%. Comparing base (7d5b1ba) to head (f1d7584).
Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10674      +/-   ##
==========================================
- Coverage   92.38%   92.24%   -0.15%     
==========================================
  Files         403      403              
  Lines       18729    18726       -3     
==========================================
- Hits        17303    17274      -29     
- Misses       1066     1097      +31     
+ Partials      360      355       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! Just one thought about the allowed characters.

Comment on lines 183 to 186
// nameRegexp is used to validate the name of a component.
// A name must start with an ASCII alphanumeric character and
// can only contain ASCII alphanumeric characters, '_', and '-'.
var nameRegexp = regexp.MustCompile(`^[0-9a-zA-Z][0-9a-zA-Z_-]{0,62}$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about opening this up to all Unicode letters and numbers? i.e. swapping [0-9] for \pN (numbers) and [a-zA-Z] for \pL (letters). Perhaps also replacing the hyphen and dash with \pP (punctuation).

I think ASCII is reasonable for type, since there's a specific set of them. On the other hand, the name component is arbitrary and user-defined. So, for example, allowing Chinese characters may be more inclusive of native Chinese speakers/readers/writers.

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we start with introducing this restriction only on UnmarshalText?

We can later think about adding Name or not, but that is the part that impacts end-users of the binary and I think we can start there

@mwear
Copy link
Member Author

mwear commented Jul 22, 2024

Updated with both suggestions @mx-psi and @axw.

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes, looks great!

component/config.go Outdated Show resolved Hide resolved
component/config.go Outdated Show resolved Hide resolved
@mx-psi mx-psi merged commit 95902c1 into open-telemetry:main Jul 25, 2024
50 checks passed
@github-actions github-actions bot added this to the next release milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[component] Restrict allowed characters for component.ID name
4 participants