<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Move a test and interface guard related to `component.Type` to more
appropriate files.
#### Description
[gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) is a
stricter format than gofmt, while being backwards compatible.
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
#### Description
While working on
https://github.com/open-telemetry/opentelemetry-collector/pull/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.
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes#10673
<!--Describe what testing was performed and which tests were added.-->
#### Testing
Unit tests
<!--Describe the documentation added.-->
#### Documentation
Code comments
<!--Please delete paragraphs that you did not use before submitting.-->
**Description:**
- Adds `component.MustNewType` to create a type. This function panics if
the type has invalid characters. Add similar functions
`component.MustNewID` and `component.MustNewIDWithName`.
- Adds `component.Type.String` to recover the string
- Use `component.MustNewType`, `component.MustNewID`,
`component.MustNewIDWithName` and `component.Type.String` everywhere in
this codebase. To do this I changed `component.Type` into an opaque
struct and checked for compile-time errors.
Some notes:
1. All components currently on core and contrib follow this rule. This
is still breaking for other components.
2. A future PR will change this into a struct, to actually validate this
(right now you can just do `component.Type("anything")` to bypass
validation). I want to do this in two steps to avoid breaking contrib
tests: we first introduce this function, and after that we change into a
struct.
**Link to tracking Issue:** Updates #9208
* [chore] use license shortform
To remain consistent w/ contrib repo, see https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/22052
Signed-off-by: Alex Boten <aboten@lightstep.com>
* make goporto
Signed-off-by: Alex Boten <aboten@lightstep.com>
---------
Signed-off-by: Alex Boten <aboten@lightstep.com>
The main reason is to remove the circular dependency between the config (including sub-packages) and component. Here is the current state:
* component depends on config
* config/sub-package[grpc, http, etc.] depends on config & component
Because of this "circular" dependency, we cannot split for example "config" into its own module, only if all the other config sub-packages are also split.
Signed-off-by: Bogdan <bogdandrutu@gmail.com>