Skip to content

Commit

Permalink
Use MustAddMetricSet in all metricsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Jul 15, 2021
1 parent a0feda9 commit 3c4c132
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 47 deletions.
6 changes: 2 additions & 4 deletions docs/devguide/create-metricset.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ modify this part of the file if your implementation requires more imports.
The init method registers the metricset with the central registry. In Go the `init()` function is called
before the execution of all other code. This means the module will be automatically registered with the global registry.

The `New` method, which is passed to `AddMetricSet`, will be called after the setup of the module and before starting to fetch data. You normally don't need to change this part of the file.
The `New` method, which is passed to `MustAddMetricSet`, will be called after the setup of the module and before starting to fetch data. You normally don't need to change this part of the file.

[source,go]
----
func init() {
if err := mb.Registry.AddMetricSet("{module}", "{metricset}", New); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("{module}", "{metricset}", New)
}
----

Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/golang/expvar/expvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("golang", "expvar", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("golang", "expvar", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/golang/heap/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("golang", "heap", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("golang", "heap", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/http/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("http", "json", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("http", "json", New,
mb.WithHostParser(hostParser),
)
}

const (
Expand Down
4 changes: 1 addition & 3 deletions metricbeat/module/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("http", "server", New); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("http", "server", New)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/jolokia/jmx/jmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var (

// init registers the MetricSet with the central registry.
func init() {
if err := mb.Registry.AddMetricSet("jolokia", "jmx", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("jolokia", "jmx", New,
mb.WithHostParser(hostParser),
)
}

const (
Expand Down
4 changes: 1 addition & 3 deletions metricbeat/module/kubernetes/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "event", New); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "event", New)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_container", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_container", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_daemonset", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_daemonset", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_deployment", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_deployment", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/kubernetes/state_job/state_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_job", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_job", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/kubernetes/state_node/state_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_node", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_node", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/kubernetes/state_pod/state_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_pod", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_pod", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_replicaset", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_replicaset", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var (
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("kubernetes", "state_statefulset", New, hostParser); err != nil {
panic(err)
}
mb.Registry.MustAddMetricSet("kubernetes", "state_statefulset", New,
mb.WithHostParser(hostParser),
)
}

// MetricSet type defines all fields of the MetricSet
Expand Down
4 changes: 3 additions & 1 deletion metricbeat/module/php_fpm/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
// the MetricSet for each host defined in the module's configuration. After the
// MetricSet has been created then Fetch will begin to be called periodically.
func init() {
mb.Registry.AddMetricSet("php_fpm", "process", New, php_fpm.HostParser)
mb.Registry.MustAddMetricSet("php_fpm", "process", New,
mb.WithHostParser(php_fpm.HostParser),
)
}

// MetricSet holds any configuration or state information. It must implement
Expand Down

0 comments on commit 3c4c132

Please sign in to comment.