-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add new MetricSet interfaces for Module Developers #3908
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,19 +71,62 @@ type MetricSet interface { | |
HostData() HostData // HostData returns the parsed host data. | ||
} | ||
|
||
// Closer is an optional interface that a MetricSet can implement in order to | ||
// cleanup any resources it has open at shutdown. | ||
type Closer interface { | ||
Close() error | ||
} | ||
|
||
// EventFetcher is a MetricSet that returns a single event when collecting data. | ||
// Use ReportingMetricSet for new MetricSet implementations. | ||
type EventFetcher interface { | ||
MetricSet | ||
Fetch() (common.MapStr, error) | ||
} | ||
|
||
// EventsFetcher is a MetricSet that returns a multiple events when collecting | ||
// data. | ||
// data. Use ReportingMetricSet for new MetricSet implementations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case we decided to keep both, we need to rename it later to something like |
||
type EventsFetcher interface { | ||
MetricSet | ||
Fetch() ([]common.MapStr, error) | ||
} | ||
|
||
// Reporter is used by a MetricSet to report events, errors, or errors with | ||
// metadata. The methods return false if and only if publishing failed because | ||
// the MetricSet is being closed. | ||
type Reporter interface { | ||
Event(event common.MapStr) bool // Event reports a single successful event. | ||
ErrorWith(err error, meta common.MapStr) bool // ErrorWith reports a single error event with the additional metadata. | ||
Error(err error) bool // Error reports a single error event. | ||
} | ||
|
||
// ReportingMetricSet is a MetricSet that reports events or errors through the | ||
// Reporter interface. Fetch is called periodically to collect events. | ||
type ReportingMetricSet interface { | ||
MetricSet | ||
Fetch(r Reporter) | ||
} | ||
|
||
// PushReporter is used by a MetricSet to report events, errors, or errors with | ||
// metadata. It provides a done channel used to signal that reporter should | ||
// stop. | ||
type PushReporter interface { | ||
Reporter | ||
|
||
// Done returns a channel that's closed when work done on behalf of this | ||
// reporter should be canceled. | ||
Done() <-chan struct{} | ||
} | ||
|
||
// PushMetricSet is a MetricSet that pushes events (rather than pulling them | ||
// periodically via a Fetch callback). Run is invoked to start the event | ||
// subscription and it should block until the MetricSet is ready to stop or | ||
// the PushReporter's done channel is closed. | ||
type PushMetricSet interface { | ||
MetricSet | ||
Run(r PushReporter) | ||
} | ||
|
||
// HostData contains values parsed from the 'host' configuration. Other | ||
// configuration data like protocols, usernames, and passwords may also be | ||
// used to construct this HostData data. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,9 @@ func (b EventBuilder) Build() (common.MapStr, error) { | |
metricsetData := common.MapStr{ | ||
"module": b.ModuleName, | ||
"name": b.MetricSetName, | ||
"rtt": b.FetchDuration.Nanoseconds() / int64(time.Microsecond), | ||
} | ||
if b.FetchDuration != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, that means we also remove this value in the system module case 👍 |
||
metricsetData["rtt"] = b.FetchDuration.Nanoseconds() / int64(time.Microsecond) | ||
} | ||
|
||
namespace := b.MetricSetName | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That pattern we will probably see quite often. If Error would not return anything, we could use
return report.Error(err)
probably.