Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Nov 9, 2023
1 parent 69b4f4f commit e5a06df
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .chloggen/automated-status-on-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ change_type: enhancement
component: statusreporting

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Automates status reporting when `Start` returns.
note: Automates status reporting upon the completion of component.Start().

# One or more tracking issues or pull requests related to the change
issues: []
issues: [7682]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
Expand Down
4 changes: 2 additions & 2 deletions component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type TelemetrySettingsBase struct {
Resource pcommon.Resource
}

// TelemetrySettings and servicetelemetry.Settings differ in the method signature for
// ReportComponentStatus
// TelemetrySettings and servicetelemetry.TelemetrySettings differ in their
// mechanism for reporting component status.
type TelemetrySettings struct {
*TelemetrySettingsBase

Expand Down
15 changes: 12 additions & 3 deletions service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ func (bes *Extensions) Shutdown(ctx context.Context) error {
extID := bes.extensionIDs[i]
instanceID := bes.instanceIDs[extID]
ext := bes.extMap[extID]
_ = bes.telemetry.Status.ReportComponentStatus(instanceID, component.NewStatusEvent(component.StatusStopping))
_ = bes.telemetry.Status.ReportComponentStatus(
instanceID,
component.NewStatusEvent(component.StatusStopping),
)
if err := ext.Shutdown(ctx); err != nil {
_ = bes.telemetry.Status.ReportComponentStatus(instanceID, component.NewPermanentErrorEvent(err))
_ = bes.telemetry.Status.ReportComponentStatus(
instanceID,
component.NewPermanentErrorEvent(err),
)
errs = multierr.Append(errs, err)
continue
}
_ = bes.telemetry.Status.ReportComponentStatus(instanceID, component.NewStatusEvent(component.StatusStopped))
_ = bes.telemetry.Status.ReportComponentStatus(
instanceID,
component.NewStatusEvent(component.StatusStopped),
)
}

return errs
Expand Down
15 changes: 12 additions & 3 deletions service/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,24 @@ func (g *Graph) ShutdownAll(ctx context.Context) error {
}

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

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

_ = g.telemetry.Status.ReportComponentStatus(instanceID, component.NewStatusEvent(component.StatusStopped))
_ = g.telemetry.Status.ReportComponentStatus(
instanceID,
component.NewStatusEvent(component.StatusStopped),
)
}
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions service/internal/servicetelemetry/telemetry_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"go.opentelemetry.io/collector/service/internal/status"
)

// TelemetrySettings mirrors component.TelemetrySettings except for the method signature of
// ReportComponentStatus. The service level TelemetrySettings is not bound a specific component, and
// therefore takes a component.InstanceID as an argument.
// TelemetrySettings mirrors component.TelemetrySettings except for the mechanism for reporting
// status. Service-level status reporting has additional methods which can report status for
// components by their InstanceID whereas the component versions are tied to a specific component.
type TelemetrySettings struct {
*component.TelemetrySettingsBase
Status *status.Reporter
Expand Down
3 changes: 2 additions & 1 deletion service/internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type Reporter struct {
onStatusChange NotifyStatusFunc
}

// NewReporter a reporter that will invoke the NotifyStatusFunc when a component's status
// NewReporter returns a reporter that will invoke the NotifyStatusFunc when a component's status
// has changed.
func NewReporter(onStatusChange NotifyStatusFunc) *Reporter {
return &Reporter{
Expand Down Expand Up @@ -148,6 +148,7 @@ func (r *Reporter) ReportComponentStatusIf(
return nil
}

// Note: a lock must be acquired before calling this method.
func (r *Reporter) componentFSM(id *component.InstanceID) *fsm {
fsm, ok := r.fsmMap[id]
if !ok {
Expand Down

0 comments on commit e5a06df

Please sign in to comment.