Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][receiver/cloudfoundry] Use ReportStatus instead of ReportFatalError #30613

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions receiver/cloudfoundryreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ func (cfr *cloudFoundryReceiver) Start(ctx context.Context, host component.Host)

_, tokenErr = tokenProvider.ProvideToken()
if tokenErr != nil {
host.ReportFatalError(fmt.Errorf("cloud foundry receiver failed to fetch initial token from UAA: %w", tokenErr))
cfr.settings.ReportStatus(component.NewFatalErrorEvent(fmt.Errorf("cloud foundry receiver failed to fetch initial token from UAA: %w", tokenErr)))
return
}

envelopeStream, err := streamFactory.CreateStream(innerCtx, cfr.config.RLPGateway.ShardID)
if err != nil {
host.ReportFatalError(fmt.Errorf("creating RLP gateway envelope stream: %w", err))
cfr.settings.ReportStatus(component.NewFatalErrorEvent(fmt.Errorf("creating RLP gateway envelope stream: %w", err)))
return
}

cfr.streamMetrics(innerCtx, envelopeStream, host)
cfr.streamMetrics(innerCtx, envelopeStream)
cfr.settings.Logger.Debug("cloudfoundry metrics streamer stopped")
}()

Expand All @@ -120,16 +120,15 @@ func (cfr *cloudFoundryReceiver) Shutdown(_ context.Context) error {

func (cfr *cloudFoundryReceiver) streamMetrics(
ctx context.Context,
stream loggregator.EnvelopeStream,
host component.Host) {
stream loggregator.EnvelopeStream) {

for {
// Blocks until non-empty result or context is cancelled (returns nil in that case)
envelopes := stream()
if envelopes == nil {
// If context has not been cancelled, then nil means the shutdown was due to an error within stream
if ctx.Err() == nil {
host.ReportFatalError(errors.New("RLP gateway streamer shut down due to an error"))
cfr.settings.ReportStatus(component.NewFatalErrorEvent(errors.New("RLP gateway streamer shut down due to an error")))
}

break
Expand Down