Skip to content

Commit

Permalink
doc(exporter): add doc for MustRegisterMetricsProbe & MustRegisterEve…
Browse files Browse the repository at this point in the history
…ntProbe

Signed-off-by: xiayu.lyt <xiayu.lyt@alibaba-inc.com>
  • Loading branch information
Lyt99 committed Oct 9, 2023
1 parent 3a897c4 commit 677c9d3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/exporter/probe/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ func (e *EventProbeCreator) Call(sink chan<- *Event, args map[string]interface{}
return ret, err.(error)
}

// MustRegisterEventProbe registers the event probe by given name and creator.
// The creator is a function that creates EventProbe. Return values of the creator
// must be (EventProbe, error). The creator can accept one parameter
// of type chan<- *Event, or struct/map as an extra parameter.
// When the creator specifies the extra parameter, the configuration of the probe in the configuration file
// will be passed to the creator when the probe is created. For example:
//
// The creator accepts no extra args.
//
// func eventProbeCreator(sink chan<- *Event) (EventProbe, error)
//
// The creator accepts struct "probeArgs" as args. Names of struct fields are case-insensitive.
//
// // Config in yaml
// args:
// argA: test
// argB: 20
// argC:
// - a
// // Struct definition
// type probeArgs struct {
// ArgA string
// ArgB int
// ArgC []string
// }
// // The creator function:
// func eventProbeCreator(sink chan<- *Event, args probeArgs) (EventProbe, error)
//
// The creator can also use a map with string keys as parameters.
// However, if you use a type other than interface{} as the value type, errors may occur
// during the configuration parsing process.
//
// func metricsProbeCreator(sink chan<- *Event, args map[string]string) (EventProbe, error)
// func metricsProbeCreator(sink chan<- *Event, args map[string]interface{} (EventProbe, error)
func MustRegisterEventProbe(name string, creator interface{}) {
if _, ok := availableEventProbe[name]; ok {
panic(fmt.Errorf("duplicated event probe %s", name))
Expand Down
33 changes: 33 additions & 0 deletions pkg/exporter/probe/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,39 @@ func (m *MetricsProbeCreator) Call(args map[string]interface{}) (MetricsProbe, e
return ret, err.(error)
}

// MustRegisterMetricsProbe registers the metrics probe by given name and creator.
// The creator is a function that creates MetricProbe. Return values of the creator
// must be (MetricsProbe, error). The creator can accept no parameter, or struct/map as a parameter.
// When the creator specifies the parameter, the configuration of the probe in the configuration file
// will be passed to the creator when the probe is created. For example:
//
// The creator accepts no extra args.
//
// func metricsProbeCreator() (MetricsProbe, error)
//
// The creator accepts struct "probeArgs" as args. Names of struct fields are case-insensitive.
//
// // Config in yaml
// args:
// argA: test
// argB: 20
// argC:
// - a
// // Struct definition
// type probeArgs struct {
// ArgA string
// ArgB int
// ArgC []string
// }
// // The creator function:
// func metricsProbeCreator(args probeArgs) (MetricsProbe, error)
//
// The creator can also use a map with string keys as parameters.
// However, if you use a type other than interface{} as the value type, errors may occur
// during the configuration parsing process.
//
// func metricsProbeCreator(args map[string]string) (MetricsProbe, error)
// func metricsProbeCreator(args map[string]interface{} (MetricsProbe, error)
func MustRegisterMetricsProbe(name string, creator interface{}) {
if _, ok := availableMetricsProbes[name]; ok {
panic(fmt.Errorf("duplicated metric probe %s", name))
Expand Down

0 comments on commit 677c9d3

Please sign in to comment.