Skip to content

Commit 3c4c132

Browse files
committed
Use MustAddMetricSet in all metricsets
1 parent a0feda9 commit 3c4c132

16 files changed

Lines changed: 43 additions & 47 deletions

File tree

docs/devguide/create-metricset.asciidoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ modify this part of the file if your implementation requires more imports.
7878
The init method registers the metricset with the central registry. In Go the `init()` function is called
7979
before the execution of all other code. This means the module will be automatically registered with the global registry.
8080

81-
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.
81+
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.
8282

8383
[source,go]
8484
----
8585
func init() {
86-
if err := mb.Registry.AddMetricSet("{module}", "{metricset}", New); err != nil {
87-
panic(err)
88-
}
86+
mb.Registry.MustAddMetricSet("{module}", "{metricset}", New)
8987
}
9088
----
9189

metricbeat/module/golang/expvar/expvar.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ var (
4242
// init registers the MetricSet with the central registry.
4343
// The New method will be called after the setup of the module and before starting to fetch data
4444
func init() {
45-
if err := mb.Registry.AddMetricSet("golang", "expvar", New, hostParser); err != nil {
46-
panic(err)
47-
}
45+
mb.Registry.MustAddMetricSet("golang", "expvar", New,
46+
mb.WithHostParser(hostParser),
47+
)
4848
}
4949

5050
// MetricSet type defines all fields of the MetricSet

metricbeat/module/golang/heap/heap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ var (
4646
// init registers the MetricSet with the central registry.
4747
// The New method will be called after the setup of the module and before starting to fetch data
4848
func init() {
49-
if err := mb.Registry.AddMetricSet("golang", "heap", New, hostParser); err != nil {
50-
panic(err)
51-
}
49+
mb.Registry.MustAddMetricSet("golang", "heap", New,
50+
mb.WithHostParser(hostParser),
51+
)
5252
}
5353

5454
// MetricSet type defines all fields of the MetricSet

metricbeat/module/http/json/json.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import (
3232
// init registers the MetricSet with the central registry.
3333
// The New method will be called after the setup of the module and before starting to fetch data
3434
func init() {
35-
if err := mb.Registry.AddMetricSet("http", "json", New, hostParser); err != nil {
36-
panic(err)
37-
}
35+
mb.Registry.MustAddMetricSet("http", "json", New,
36+
mb.WithHostParser(hostParser),
37+
)
3838
}
3939

4040
const (

metricbeat/module/http/server/server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ import (
2828
// init registers the MetricSet with the central registry.
2929
// The New method will be called after the setup of the module and before starting to fetch data
3030
func init() {
31-
if err := mb.Registry.AddMetricSet("http", "server", New); err != nil {
32-
panic(err)
33-
}
31+
mb.Registry.MustAddMetricSet("http", "server", New)
3432
}
3533

3634
// MetricSet type defines all fields of the MetricSet

metricbeat/module/jolokia/jmx/jmx.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ var (
3232

3333
// init registers the MetricSet with the central registry.
3434
func init() {
35-
if err := mb.Registry.AddMetricSet("jolokia", "jmx", New, hostParser); err != nil {
36-
panic(err)
37-
}
35+
mb.Registry.MustAddMetricSet("jolokia", "jmx", New,
36+
mb.WithHostParser(hostParser),
37+
)
3838
}
3939

4040
const (

metricbeat/module/kubernetes/event/event.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import (
3030
// init registers the MetricSet with the central registry.
3131
// The New method will be called after the setup of the module and before starting to fetch data
3232
func init() {
33-
if err := mb.Registry.AddMetricSet("kubernetes", "event", New); err != nil {
34-
panic(err)
35-
}
33+
mb.Registry.MustAddMetricSet("kubernetes", "event", New)
3634
}
3735

3836
// MetricSet type defines all fields of the MetricSet

metricbeat/module/kubernetes/state_container/state_container.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ var (
7878
// init registers the MetricSet with the central registry.
7979
// The New method will be called after the setup of the module and before starting to fetch data
8080
func init() {
81-
if err := mb.Registry.AddMetricSet("kubernetes", "state_container", New, hostParser); err != nil {
82-
panic(err)
83-
}
81+
mb.Registry.MustAddMetricSet("kubernetes", "state_container", New,
82+
mb.WithHostParser(hostParser),
83+
)
8484
}
8585

8686
// MetricSet type defines all fields of the MetricSet

metricbeat/module/kubernetes/state_daemonset/state_daemonset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ var (
5858
// init registers the MetricSet with the central registry.
5959
// The New method will be called after the setup of the module and before starting to fetch data
6060
func init() {
61-
if err := mb.Registry.AddMetricSet("kubernetes", "state_daemonset", New, hostParser); err != nil {
62-
panic(err)
63-
}
61+
mb.Registry.MustAddMetricSet("kubernetes", "state_daemonset", New,
62+
mb.WithHostParser(hostParser),
63+
)
6464
}
6565

6666
// MetricSet type defines all fields of the MetricSet

metricbeat/module/kubernetes/state_deployment/state_deployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ var (
5959
// init registers the MetricSet with the central registry.
6060
// The New method will be called after the setup of the module and before starting to fetch data
6161
func init() {
62-
if err := mb.Registry.AddMetricSet("kubernetes", "state_deployment", New, hostParser); err != nil {
63-
panic(err)
64-
}
62+
mb.Registry.MustAddMetricSet("kubernetes", "state_deployment", New,
63+
mb.WithHostParser(hostParser),
64+
)
6565
}
6666

6767
// MetricSet type defines all fields of the MetricSet

0 commit comments

Comments
 (0)