Skip to content

Commit

Permalink
add deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Dec 23, 2023
1 parent 4765f96 commit 593b1e4
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 38 deletions.
2 changes: 1 addition & 1 deletion component/componenttest/nop_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewNopTelemetrySettings() component.TelemetrySettings {
MeterProvider: noopmetric.NewMeterProvider(),
MetricsLevel: configtelemetry.LevelNone,
Resource: pcommon.NewResource(),
ReportComponentStatus: func(*component.StatusEvent) {
ReportStatus: func(*component.StatusEvent) {
},
}
}
9 changes: 8 additions & 1 deletion component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ type TelemetrySettings struct {
// ReportComponentStatus allows a component to report runtime changes in status. The service
// will automatically report status for a component during startup and shutdown. Components can
// use this method to report status after start and before shutdown.
ReportComponentStatus func(*StatusEvent)
// Deprecated: [v0.92.0] This function will be removed in a future release.
// Use ReportStatus instead.
ReportComponentStatus func(*StatusEvent) error

// ReportStatus allows a component to report runtime changes in status. The service
// will automatically report status for a component during startup and shutdown. Components can
// use this method to report status after start and before shutdown.
ReportStatus func(*StatusEvent)
}
6 changes: 3 additions & 3 deletions internal/sharedcomponent/sharedcomponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (m *Map[K, V]) LoadOrStore(key K, create func() (V, error), telemetrySettin
// component represents.
if _, ok := c.seenSettings[telemetrySettings]; !ok {
c.seenSettings[telemetrySettings] = struct{}{}
prev := c.telemetry.ReportComponentStatus
c.telemetry.ReportComponentStatus = func(ev *component.StatusEvent) {
telemetrySettings.ReportComponentStatus(ev)
prev := c.telemetry.ReportStatus
c.telemetry.ReportStatus = func(ev *component.StatusEvent) {
telemetrySettings.ReportStatus(ev)
prev(ev)
}
}
Expand Down
12 changes: 6 additions & 6 deletions service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func (bes *Extensions) Start(ctx context.Context, host component.Host) error {
extLogger.Info("Extension is starting...")
instanceID := bes.instanceIDs[extID]
ext := bes.extMap[extID]
bes.telemetry.Status.ReportComponentStatus(
bes.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStarting),
)
if err := ext.Start(ctx, components.NewHostWrapper(host, extLogger)); err != nil {
bes.telemetry.Status.ReportComponentStatus(
bes.telemetry.Status.ReportStatus(
instanceID,
component.NewPermanentErrorEvent(err),
)
return err
}
bes.telemetry.Status.ReportComponentOKIfStarting(instanceID)
bes.telemetry.Status.ReportOKIfStarting(instanceID)
extLogger.Info("Extension started.")
}
return nil
Expand All @@ -62,19 +62,19 @@ func (bes *Extensions) Shutdown(ctx context.Context) error {
extID := bes.extensionIDs[i]
instanceID := bes.instanceIDs[extID]
ext := bes.extMap[extID]
bes.telemetry.Status.ReportComponentStatus(
bes.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStopping),
)
if err := ext.Shutdown(ctx); err != nil {
bes.telemetry.Status.ReportComponentStatus(
bes.telemetry.Status.ReportStatus(
instanceID,
component.NewPermanentErrorEvent(err),
)
errs = multierr.Append(errs, err)
continue
}
bes.telemetry.Status.ReportComponentStatus(
bes.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStopped),
)
Expand Down
12 changes: 6 additions & 6 deletions service/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,20 @@ func (g *Graph) StartAll(ctx context.Context, host component.Host) error {
}

instanceID := g.instanceIDs[node.ID()]
g.telemetry.Status.ReportComponentStatus(
g.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStarting),
)

if compErr := comp.Start(ctx, host); compErr != nil {
g.telemetry.Status.ReportComponentStatus(
g.telemetry.Status.ReportStatus(
instanceID,
component.NewPermanentErrorEvent(compErr),
)
return compErr
}

g.telemetry.Status.ReportComponentOKIfStarting(instanceID)
g.telemetry.Status.ReportOKIfStarting(instanceID)
}
return nil
}
Expand All @@ -427,21 +427,21 @@ func (g *Graph) ShutdownAll(ctx context.Context) error {
}

instanceID := g.instanceIDs[node.ID()]
g.telemetry.Status.ReportComponentStatus(
g.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStopping),
)

if compErr := comp.Shutdown(ctx); compErr != nil {
errs = multierr.Append(errs, compErr)
g.telemetry.Status.ReportComponentStatus(
g.telemetry.Status.ReportStatus(
instanceID,
component.NewPermanentErrorEvent(compErr),
)
continue
}

g.telemetry.Status.ReportComponentStatus(
g.telemetry.Status.ReportStatus(
instanceID,
component.NewStatusEvent(component.StatusStopped),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func TestNewNopSettings(t *testing.T) {
require.Equal(t, noopmetric.NewMeterProvider(), set.MeterProvider)
require.Equal(t, configtelemetry.LevelNone, set.MetricsLevel)
require.Equal(t, pcommon.NewResource(), set.Resource)
set.Status.ReportComponentStatus(
set.Status.ReportStatus(
&component.InstanceID{},
component.NewStatusEvent(component.StatusStarting),
)
set.Status.ReportComponentOKIfStarting(&component.InstanceID{})
set.Status.ReportOKIfStarting(&component.InstanceID{})

}
17 changes: 11 additions & 6 deletions service/internal/servicetelemetry/telemetry_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ type TelemetrySettings struct {
// ToComponentTelemetrySettings returns a TelemetrySettings for a specific component derived from
// this service level Settings object.
func (s TelemetrySettings) ToComponentTelemetrySettings(id *component.InstanceID) component.TelemetrySettings {
status := status.NewComponentStatusFunc(id, s.Status.ReportStatus)
return component.TelemetrySettings{
Logger: s.Logger,
TracerProvider: s.TracerProvider,
MeterProvider: s.MeterProvider,
MetricsLevel: s.MetricsLevel,
Resource: s.Resource,
ReportComponentStatus: status.NewComponentStatusFunc(id, s.Status.ReportComponentStatus),
Logger: s.Logger,
TracerProvider: s.TracerProvider,
MeterProvider: s.MeterProvider,
MetricsLevel: s.MetricsLevel,
Resource: s.Resource,
ReportComponentStatus: func(event *component.StatusEvent) error {
status(event)
return nil
},
ReportStatus: status,
}
}
4 changes: 2 additions & 2 deletions service/internal/servicetelemetry/telemetry_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func TestSettings(t *testing.T) {
func(err error) { require.NoError(t, err) }),
}
set.Status.Ready()
set.Status.ReportComponentStatus(
set.Status.ReportStatus(
&component.InstanceID{},
component.NewStatusEvent(component.StatusStarting),
)
set.Status.ReportComponentOKIfStarting(&component.InstanceID{})
set.Status.ReportOKIfStarting(&component.InstanceID{})

compSet := set.ToComponentTelemetrySettings(&component.InstanceID{})
compSet.ReportComponentStatus(component.NewStatusEvent(component.StatusStarting))
Expand Down
22 changes: 20 additions & 2 deletions service/internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,20 @@ func (r *Reporter) Ready() {
}

// ReportComponentStatus reports status for the given InstanceID
// Deprecated: [v0.92.0] This function will be removed in a future release.
// Use ReportStatus instead.
func (r *Reporter) ReportComponentStatus(
id *component.InstanceID,
ev *component.StatusEvent,
) error {
r.ReportStatus(id, ev)
return nil
}

// ReportStatus reports status for the given InstanceID
func (r *Reporter) ReportStatus(
id *component.InstanceID,
ev *component.StatusEvent,
) {
r.mu.Lock()
defer r.mu.Unlock()
Expand All @@ -138,7 +149,14 @@ func (r *Reporter) ReportComponentStatus(
}

// ReportComponentOkIfStarting reports StatusOK if the component's current status is Starting
func (r *Reporter) ReportComponentOKIfStarting(id *component.InstanceID) {
// Deprecated: [v0.92.0] This function will be removed in a future release.
// Use ReportOKIfStarting instead.
func (r *Reporter) ReportComponentOKIfStarting(id *component.InstanceID) error {
r.ReportOKIfStarting(id)
return nil
}

func (r *Reporter) ReportOKIfStarting(id *component.InstanceID) {
r.mu.Lock()
defer r.mu.Unlock()
if !r.ready {
Expand All @@ -162,7 +180,7 @@ func (r *Reporter) componentFSM(id *component.InstanceID) *fsm {
return fsm
}

// NewComponentStatusFunc returns a function to be used as ReportComponentStatus for
// NewComponentStatusFunc returns a function to be used as ReportStatus for
// component.TelemetrySettings, which differs from servicetelemetry.Settings in that
// the component version is tied to specific component instance.
func NewComponentStatusFunc(
Expand Down
14 changes: 7 additions & 7 deletions service/internal/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func TestStatusFuncs(t *testing.T) {
func(err error) {
require.NoError(t, err)
})
comp1Func := NewComponentStatusFunc(id1, rep.ReportComponentStatus)
comp2Func := NewComponentStatusFunc(id2, rep.ReportComponentStatus)
comp1Func := NewComponentStatusFunc(id1, rep.ReportStatus)
comp2Func := NewComponentStatusFunc(id2, rep.ReportStatus)
rep.Ready()

for _, st := range statuses1 {
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestStatusFuncsConcurrent(t *testing.T) {
for _, id := range ids {
id := id
go func() {
compFn := NewComponentStatusFunc(id, rep.ReportComponentStatus)
compFn := NewComponentStatusFunc(id, rep.ReportStatus)
compFn(component.NewStatusEvent(component.StatusStarting))
for i := 0; i < 1000; i++ {
compFn(component.NewStatusEvent(component.StatusRecoverableError))
Expand All @@ -268,12 +268,12 @@ func TestReporterReady(t *testing.T) {
})
id := &component.InstanceID{}

rep.ReportComponentStatus(id, component.NewStatusEvent(component.StatusStarting))
rep.ReportStatus(id, component.NewStatusEvent(component.StatusStarting))
require.ErrorIs(t, err, ErrStatusNotReady)
rep.Ready()

err = nil
rep.ReportComponentStatus(id, component.NewStatusEvent(component.StatusStarting))
rep.ReportStatus(id, component.NewStatusEvent(component.StatusStarting))
require.NoError(t, err)
}

Expand Down Expand Up @@ -342,10 +342,10 @@ func TestReportComponentOKIfStarting(t *testing.T) {

id := &component.InstanceID{}
for _, status := range tc.initialStatuses {
rep.ReportComponentStatus(id, component.NewStatusEvent(status))
rep.ReportStatus(id, component.NewStatusEvent(status))
}

rep.ReportComponentOKIfStarting(id)
rep.ReportOKIfStarting(id)

require.Equal(t, tc.expectedStatuses, receivedStatuses)
})
Expand Down
3 changes: 1 addition & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {
Status: status.NewReporter(srv.host.notifyComponentStatusChange, func(err error) {
if errors.Is(err, status.ErrStatusNotReady) {
srv.telemetry.Logger().Warn("Invalid transition", zap.Error(err))
} else {
srv.telemetry.Logger().Debug("Invalid transition", zap.Error(err))
}
// ignore other errors as they represent invalid state transitions and are considered benign.
}),
}

Expand Down

0 comments on commit 593b1e4

Please sign in to comment.