Skip to content

Commit aca19db

Browse files
mx-psisfc-gh-sili
authored andcommitted
[component] Make component.Kind a struct (open-telemetry#12214)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number if applicable --> Changes the underlying type of `component.Kind` to be closer to [`pipeline.Signal`](https://pkg.go.dev/go.opentelemetry.io/collector/pipeline#Signal). Right now the type is defined within `component`, but it could be moved to an internal module so that we could have a different module exposing other value on this enum. This is already doable today, the only thing this PR gives us is 1. slightly more flexibility on things like making the concept of kind more complex (e.g. adding an adjective to a kind). 2. restricting external consumers from implementing their own component kinds without our explicit approval (with some kind of API we design) I am not convinced this is _necessary_ to do, but we may as well do it. This is technically a breaking change since `component.Kind(42)` was a valid expression and it no longer is. I think this is extremely rare, so I suggest if we go ahead we do so in one go. #### Link to tracking issue Fixes open-telemetry#11443
1 parent e64d019 commit aca19db

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: component
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change underlying type for `component.Kind` to be a struct.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12214]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

component/component.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,20 @@ func (f ShutdownFunc) Shutdown(ctx context.Context) error {
7878
}
7979

8080
// Kind represents component kinds.
81-
type Kind int
81+
type Kind struct {
82+
name string
83+
}
8284

83-
const (
84-
_ Kind = iota // skip 0, start types from 1.
85-
KindReceiver
86-
KindProcessor
87-
KindExporter
88-
KindExtension
89-
KindConnector
85+
var (
86+
KindReceiver = Kind{name: "Receiver"}
87+
KindProcessor = Kind{name: "Processor"}
88+
KindExporter = Kind{name: "Exporter"}
89+
KindExtension = Kind{name: "Extension"}
90+
KindConnector = Kind{name: "Connector"}
9091
)
9192

9293
func (k Kind) String() string {
93-
switch k {
94-
case KindReceiver:
95-
return "Receiver"
96-
case KindProcessor:
97-
return "Processor"
98-
case KindExporter:
99-
return "Exporter"
100-
case KindExtension:
101-
return "Extension"
102-
case KindConnector:
103-
return "Connector"
104-
}
105-
return ""
94+
return k.name
10695
}
10796

10897
// StabilityLevel represents the stability level of the component created by the factory.

component/component_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import (
1010
)
1111

1212
func TestKindString(t *testing.T) {
13-
assert.Equal(t, "", Kind(0).String())
13+
assert.Equal(t, "", Kind{}.String())
1414
assert.Equal(t, "Receiver", KindReceiver.String())
1515
assert.Equal(t, "Processor", KindProcessor.String())
1616
assert.Equal(t, "Exporter", KindExporter.String())
1717
assert.Equal(t, "Extension", KindExtension.String())
1818
assert.Equal(t, "Connector", KindConnector.String())
19-
assert.Equal(t, "", Kind(100).String())
2019
}
2120

2221
func TestStabilityLevelUnmarshal(t *testing.T) {

service/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestServiceGetFactory(t *testing.T) {
207207
assert.Equal(t, srv.host.Extensions.Factory(nopType), srv.host.GetFactory(component.KindExtension, nopType))
208208

209209
// Try retrieve non existing component.Kind.
210-
assert.Nil(t, srv.host.GetFactory(42, nopType))
210+
assert.Nil(t, srv.host.GetFactory(component.Kind{}, nopType))
211211
}
212212

213213
func TestServiceGetExtensions(t *testing.T) {

0 commit comments

Comments
 (0)