-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce component status reporting
This is an alternate to #6550 ## Summary of changes - Add component status concept. Components can report their status via Host.ReportComponentStatus(). Interested extensions can watch status events if they implement StatusWatcher interface. This is similar to how PipelineWatcher works today. - Deprecate Host.ReportFatalError() in favour of Host.ReportComponentStatus(). ## TODO after this is merged - healthcheck extension must implement StatusWatcher. - Replace all ReportFatalError() calls by ReportComponentStatus() calls in core and contrib. ## Open Questions - StatusWatchers need to be able to tell if all current components are healthy. It is assumed that the listeners need to maintain a map of components and track the status of each component. This works only if we assume that the set of components cannot change during the lifetime of the listener. This assumption is true today but can change in the future if we introduce partial pipeline restarts where only modified/added/removed components are recreated (this will break listener's assumption and the map will become invalid). Should we instead keep track of this entire status map in the Host and broadcast the entire status to the listeners as a whole instead of (or in addition to) individual component events?
- Loading branch information
1 parent
a8d6280
commit 0f0980b
Showing
12 changed files
with
279 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package component | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
) | ||
|
||
type Status int | ||
|
||
const ( | ||
StatusOK Status = iota | ||
StatusError | ||
) | ||
|
||
// StatusSource component that reports a status about itself. | ||
// The implementation of this interface must be comparable to be useful as a map key. | ||
type StatusSource interface { | ||
ID() ID | ||
} | ||
|
||
type StatusEvent struct { | ||
timestamp time.Time | ||
status Status | ||
err error | ||
} | ||
|
||
func (ev *StatusEvent) Status() Status { | ||
return ev.status | ||
} | ||
|
||
// Timestamp returns the time of the event. | ||
func (ev *StatusEvent) Timestamp() time.Time { | ||
return ev.timestamp | ||
} | ||
|
||
// Err returns the error associated with the ComponentEvent. | ||
func (ev *StatusEvent) Err() error { | ||
return ev.err | ||
} | ||
|
||
// statusEventOption applies options to a StatusEvent. | ||
type statusEventOption func(*StatusEvent) error | ||
|
||
// WithTimestamp sets the timestamp for a ComponentEvent. | ||
func WithTimestamp(timestamp time.Time) statusEventOption { | ||
return func(o *StatusEvent) error { | ||
o.timestamp = timestamp | ||
return nil | ||
} | ||
} | ||
|
||
// WithError sets the error object of the Event. It is optional | ||
// and should only be applied to an Event of type ComponentError. | ||
func WithError(err error) statusEventOption { | ||
return func(o *StatusEvent) error { | ||
if o.status == StatusOK { | ||
return errors.New("event with ComponentOK cannot have an error") | ||
} | ||
o.err = err | ||
return nil | ||
} | ||
} | ||
|
||
// NewStatusEvent creates and returns a StatusEvent with default and provided | ||
// options. Will return an error if an error is provided for a non-error event | ||
// type (status.ComponentOK). | ||
// If the timestamp is not provided will set it to time.Now(). | ||
func NewStatusEvent(status Status, options ...statusEventOption) (*StatusEvent, error) { | ||
ev := StatusEvent{ | ||
status: status, | ||
} | ||
|
||
for _, opt := range options { | ||
if err := opt(&ev); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if ev.timestamp.IsZero() { | ||
ev.timestamp = time.Now() | ||
} | ||
|
||
return &ev, nil | ||
} | ||
|
||
// StatusWatcher is an extra interface for Extension hosted by the OpenTelemetry | ||
// Collector that is to be implemented by extensions interested in changes to component | ||
// status. | ||
type StatusWatcher interface { | ||
// StatusChanged notifies about a change in the source component status. | ||
StatusChanged(timestamp time.Time, source StatusSource, event *StatusEvent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.