diff --git a/docs/devguide/create-metricset.asciidoc b/docs/devguide/create-metricset.asciidoc index db84c3272fd..cbbe6d651df 100644 --- a/docs/devguide/create-metricset.asciidoc +++ b/docs/devguide/create-metricset.asciidoc @@ -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) } ---- diff --git a/metricbeat/module/golang/expvar/expvar.go b/metricbeat/module/golang/expvar/expvar.go index bf026f3f50e..0de02b78c3f 100644 --- a/metricbeat/module/golang/expvar/expvar.go +++ b/metricbeat/module/golang/expvar/expvar.go @@ -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 diff --git a/metricbeat/module/golang/heap/heap.go b/metricbeat/module/golang/heap/heap.go index e30142b6c91..c449117eb6f 100644 --- a/metricbeat/module/golang/heap/heap.go +++ b/metricbeat/module/golang/heap/heap.go @@ -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 diff --git a/metricbeat/module/http/json/json.go b/metricbeat/module/http/json/json.go index 7803efe2f1e..8a0f549c876 100644 --- a/metricbeat/module/http/json/json.go +++ b/metricbeat/module/http/json/json.go @@ -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 ( diff --git a/metricbeat/module/http/server/server.go b/metricbeat/module/http/server/server.go index 61e2d099145..6fe118e282f 100644 --- a/metricbeat/module/http/server/server.go +++ b/metricbeat/module/http/server/server.go @@ -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 diff --git a/metricbeat/module/jolokia/jmx/jmx.go b/metricbeat/module/jolokia/jmx/jmx.go index 909a0db2166..f4500b2c1b2 100644 --- a/metricbeat/module/jolokia/jmx/jmx.go +++ b/metricbeat/module/jolokia/jmx/jmx.go @@ -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 ( diff --git a/metricbeat/module/kubernetes/event/event.go b/metricbeat/module/kubernetes/event/event.go index f7b98bd6723..f4ec9fdf576 100644 --- a/metricbeat/module/kubernetes/event/event.go +++ b/metricbeat/module/kubernetes/event/event.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_container/state_container.go b/metricbeat/module/kubernetes/state_container/state_container.go index 842ebbfbc32..4ad5f4342da 100644 --- a/metricbeat/module/kubernetes/state_container/state_container.go +++ b/metricbeat/module/kubernetes/state_container/state_container.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_daemonset/state_daemonset.go b/metricbeat/module/kubernetes/state_daemonset/state_daemonset.go index 4c7da772c94..1066afa2195 100644 --- a/metricbeat/module/kubernetes/state_daemonset/state_daemonset.go +++ b/metricbeat/module/kubernetes/state_daemonset/state_daemonset.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_deployment/state_deployment.go b/metricbeat/module/kubernetes/state_deployment/state_deployment.go index 4d7b2283a56..02448afdc9a 100644 --- a/metricbeat/module/kubernetes/state_deployment/state_deployment.go +++ b/metricbeat/module/kubernetes/state_deployment/state_deployment.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_job/state_job.go b/metricbeat/module/kubernetes/state_job/state_job.go index 4000711e14d..1b072eae742 100644 --- a/metricbeat/module/kubernetes/state_job/state_job.go +++ b/metricbeat/module/kubernetes/state_job/state_job.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_node/state_node.go b/metricbeat/module/kubernetes/state_node/state_node.go index 16d468680bb..09aa5aece77 100644 --- a/metricbeat/module/kubernetes/state_node/state_node.go +++ b/metricbeat/module/kubernetes/state_node/state_node.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_pod/state_pod.go b/metricbeat/module/kubernetes/state_pod/state_pod.go index 9e5f15c7ac1..ea742ab26bd 100644 --- a/metricbeat/module/kubernetes/state_pod/state_pod.go +++ b/metricbeat/module/kubernetes/state_pod/state_pod.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_replicaset/state_replicaset.go b/metricbeat/module/kubernetes/state_replicaset/state_replicaset.go index 711ffb16b92..7ee8e62864a 100644 --- a/metricbeat/module/kubernetes/state_replicaset/state_replicaset.go +++ b/metricbeat/module/kubernetes/state_replicaset/state_replicaset.go @@ -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 diff --git a/metricbeat/module/kubernetes/state_statefulset/state_statefulset.go b/metricbeat/module/kubernetes/state_statefulset/state_statefulset.go index a29046b409b..c2c02195206 100644 --- a/metricbeat/module/kubernetes/state_statefulset/state_statefulset.go +++ b/metricbeat/module/kubernetes/state_statefulset/state_statefulset.go @@ -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 diff --git a/metricbeat/module/php_fpm/process/process.go b/metricbeat/module/php_fpm/process/process.go index 73a78e4ff13..9db11f67c3a 100644 --- a/metricbeat/module/php_fpm/process/process.go +++ b/metricbeat/module/php_fpm/process/process.go @@ -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