Skip to content

Commit 4fe8a3f

Browse files
committed
Cleanup
1 parent 239c635 commit 4fe8a3f

File tree

17 files changed

+105
-45
lines changed

17 files changed

+105
-45
lines changed

component/componenttest/nop_host.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ func NewNopHost() component.Host {
1717

1818
func (nh *nopHost) ReportFatalError(_ error) {}
1919

20-
func (nh *nopHost) ReportComponentStatus(_ component.Status, _ ...component.StatusEventOption) {}
21-
2220
func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
2321
return nil
2422
}

component/componenttest/nop_host_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func TestNewNopHost(t *testing.T) {
1919
require.IsType(t, &nopHost{}, nh)
2020

2121
nh.ReportFatalError(errors.New("TestError"))
22-
2322
assert.Nil(t, nh.GetExporters()) // nolint: staticcheck
2423
assert.Nil(t, nh.GetExtensions())
2524
assert.Nil(t, nh.GetFactory(component.KindReceiver, "test"))

component/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Host interface {
1212
//
1313
// ReportFatalError should be called by the component anytime after Component.Start() ends and
1414
// before Component.Shutdown() begins.
15-
// Deprecated: [0.65.0] Use ReportComponentStatus instead (with an event component.StatusFatalError)
15+
// Deprecated: [x.x.x] Use ReportComponentStatus instead (with an event component.StatusFatalError)
1616
ReportFatalError(err error)
1717

1818
// GetFactory of the specified kind. Returns the factory for a component type.

component/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ type StatusWatcher interface {
137137
ComponentStatusChanged(source *InstanceID, event *StatusEvent)
138138
}
139139

140+
// StatusFunc is the expected type of ReportComponentStatus for compoment.TelemetrySettings
140141
type StatusFunc func(Status, ...StatusEventOption) error

component/telemetry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ type TelemetrySettingsBase[T any] struct {
4444
ReportComponentStatus T
4545
}
4646

47+
// TelemetrySettings and servicetelemetry.Settings differ in the method signature for
48+
// ReportComponentStatus
4749
type TelemetrySettings TelemetrySettingsBase[StatusFunc]

otelcol/collector_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,20 @@ func TestComponentStatusWatcher(t *testing.T) {
158158
assert.NoError(t, err)
159159

160160
// Use a processor factory that creates "unhealthy" processor: one that
161-
// always reports StatusError after successful Start.
161+
// always reports StatusRecoverableError after successful Start.
162162
unhealthyProcessorFactory := processortest.NewUnhealthyProcessorFactory()
163163
factories.Processors[unhealthyProcessorFactory.Type()] = unhealthyProcessorFactory
164164

165165
// Keep track of all status changes in a map.
166-
changedComponents := map[*component.InstanceID]component.Status{}
166+
changedComponents := map[*component.InstanceID][]component.Status{}
167167
var mux sync.Mutex
168168
onStatusChanged := func(source *component.InstanceID, event *component.StatusEvent) {
169-
if event.Status() != component.StatusRecoverableError {
169+
if source.ID.Type() != unhealthyProcessorFactory.Type() {
170170
return
171171
}
172172
mux.Lock()
173173
defer mux.Unlock()
174-
changedComponents[source] = event.Status()
174+
changedComponents[source] = append(changedComponents[source], event.Status())
175175
}
176176

177177
// Add a "statuswatcher" extension that will receive notifications when processor
@@ -194,6 +194,13 @@ func TestComponentStatusWatcher(t *testing.T) {
194194
// Start the newly created collector.
195195
wg := startCollector(context.Background(), t, col)
196196

197+
// An unhealthy processor will successfully start, then report a recoverable error.
198+
expectedStatuses := []component.Status{
199+
component.StatusStarting,
200+
component.StatusOK,
201+
component.StatusRecoverableError,
202+
}
203+
197204
// The "unhealthy" processors will now begin to asynchronously report StatusError.
198205
// We expect to see these reports.
199206
assert.Eventually(t, func() bool {
@@ -203,8 +210,8 @@ func TestComponentStatusWatcher(t *testing.T) {
203210
for k, v := range changedComponents {
204211
// All processors must report a status change with the same ID
205212
assert.EqualValues(t, component.NewID(unhealthyProcessorFactory.Type()), k.ID)
206-
// And all must be in StatusError
207-
assert.EqualValues(t, component.StatusRecoverableError, v)
213+
// And all must have the expected statuses
214+
assert.Equal(t, expectedStatuses, v)
208215
}
209216
// We have 3 processors with exactly the same ID in otelcol-statuswatcher.yaml
210217
// We must have exactly 3 items in our map. This ensures that the "source" argument
@@ -216,6 +223,13 @@ func TestComponentStatusWatcher(t *testing.T) {
216223

217224
col.Shutdown()
218225
wg.Wait()
226+
227+
// Check for additional statuses after Shutdown.
228+
expectedStatuses = append(expectedStatuses, component.StatusStopping, component.StatusStopped)
229+
for _, v := range changedComponents {
230+
assert.Equal(t, expectedStatuses, v)
231+
}
232+
219233
assert.Equal(t, StateClosed, col.GetState())
220234
}
221235

processor/processortest/unhealthy_processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type unhealthyProcessor struct {
6262
telemetry component.TelemetrySettings
6363
}
6464

65-
func (p unhealthyProcessor) Start(_ context.Context, host component.Host) error {
65+
func (p unhealthyProcessor) Start(_ context.Context, _ component.Host) error {
6666
go func() {
6767
_ = p.telemetry.ReportComponentStatus(component.StatusRecoverableError)
6868
}()

service/extensions/extensions.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,13 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) {
154154
extMap: make(map[component.ID]extension.Extension),
155155
}
156156
for _, extID := range cfg {
157-
158157
instanceID := &component.InstanceID{
159158
ID: extID,
160159
Kind: component.KindExtension,
161160
}
162-
163-
telSet := set.Telemetry.ToComponentTelemetrySettings(instanceID)
164-
165161
extSet := extension.CreateSettings{
166162
ID: extID,
167-
TelemetrySettings: telSet,
163+
TelemetrySettings: set.Telemetry.ToComponentTelemetrySettings(instanceID),
168164
BuildInfo: set.BuildInfo,
169165
}
170166
extSet.TelemetrySettings.Logger = components.ExtensionLogger(set.Telemetry.Logger, extID)

service/internal/components/host_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewHostWrapper(host component.Host, logger *zap.Logger) component.Host {
2727
func (hw *hostWrapper) ReportFatalError(err error) {
2828
// The logger from the built component already identifies the component.
2929
hw.Logger.Error("Component fatal error", zap.Error(err))
30-
hw.Host.ReportFatalError(err) // nolint:staticcheck
30+
hw.Host.ReportFatalError(err)
3131
}
3232

3333
// RegisterZPages is used by zpages extension to register handles from service.

service/internal/components/host_wrapper_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"errors"
88
"testing"
99

10-
"go.opentelemetry.io/collector/component/componenttest"
1110
"go.uber.org/zap"
11+
12+
"go.opentelemetry.io/collector/component/componenttest"
1213
)
1314

1415
func Test_newHostWrapper(_ *testing.T) {

0 commit comments

Comments
 (0)