Skip to content

Commit

Permalink
Add ReportFatalError behavior to ReportComponentStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Aug 24, 2023
1 parent deefbcc commit d837d72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (host *serviceHost) ReportFatalError(err error) {
func (host *serviceHost) ReportComponentStatus(source *component.InstanceID, event *component.StatusEvent) {
// TODO: What should we do if there is an error notifying here?
host.serviceExtensions.NotifyComponentStatusChange(source, event) //nolint:errcheck
if event.Status() == component.StatusFatalError {
host.asyncErrorChannel <- event.Err()
}
}

func (host *serviceHost) GetFactory(kind component.Kind, componentType component.Type) component.Factory {
Expand Down
23 changes: 23 additions & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,29 @@ func TestNilCollectorEffectiveConfig(t *testing.T) {
require.NoError(t, srv.Shutdown(context.Background()))
}

func TestServiceFatalError(t *testing.T) {
set := newNopSettings()
set.AsyncErrorChannel = make(chan error)

srv, err := New(context.Background(), set, newNopConfig())
require.NoError(t, err)

assert.NoError(t, srv.Start(context.Background()))
t.Cleanup(func() {
assert.NoError(t, srv.Shutdown(context.Background()))
})

go func() {
ev, _ := component.NewStatusEvent(component.StatusFatalError, component.WithError(assert.AnError))
srv.host.ReportComponentStatus(&component.InstanceID{}, ev)
}()

err = <-srv.host.asyncErrorChannel

require.Error(t, err)
require.ErrorIs(t, err, assert.AnError)
}

func assertResourceLabels(t *testing.T, res pcommon.Resource, expectedLabels map[string]labelValue) {
for key, labelValue := range expectedLabels {
lookupKey, ok := prometheusToOtelConv[key]
Expand Down

0 comments on commit d837d72

Please sign in to comment.