diff --git a/plugins/core.go b/plugins/core.go index ea95d45ada54dc2eeaeb6b344b9d5500e9916daa..f304538ff9fddad5fd350aa4ee9266dbe65b5a70 100644 --- a/plugins/core.go +++ b/plugins/core.go @@ -36,7 +36,7 @@ var Core = node.Plugins( profiling.Plugin(), database.Plugin(), autopeering.Plugin(), - pow.Plugin, + pow.Plugin(), messagelayer.Plugin(), gossip.Plugin(), issuer.Plugin(), diff --git a/plugins/pow/plugin.go b/plugins/pow/plugin.go index 5b4f04d04f5808058a8e04cea3fa16e65ad91210..2529afc9cfab5291e750af8b852c1bd68c8503d9 100644 --- a/plugins/pow/plugin.go +++ b/plugins/pow/plugin.go @@ -1,6 +1,8 @@ package pow import ( + "sync" + "github.com/iotaledger/goshimmer/packages/tangle" "github.com/iotaledger/goshimmer/plugins/messagelayer" "github.com/iotaledger/hive.go/logger" @@ -12,9 +14,18 @@ const PluginName = "PoW" var ( // Plugin is the plugin instance of the PoW plugin. - Plugin = node.NewPlugin(PluginName, node.Enabled, run) + plugin *node.Plugin + once sync.Once ) +// Plugin gets the plugin instance. +func Plugin() *node.Plugin { + once.Do(func() { + plugin = node.NewPlugin(PluginName, node.Enabled, run) + }) + return plugin +} + func run(*node.Plugin) { // assure that the logger is available log := logger.NewLogger(PluginName) diff --git a/plugins/prometheus/info.go b/plugins/prometheus/info.go index 3a0a479b60d9d6639833034b7fab973fd7b5f272..2c3050c7f97aaf4ed5e2a3d1d24b84a0532ab3b0 100644 --- a/plugins/prometheus/info.go +++ b/plugins/prometheus/info.go @@ -8,9 +8,9 @@ import ( ) var ( - infoApp *prometheus.GaugeVec - sync prometheus.Gauge - nodeID string + infoApp *prometheus.GaugeVec + syncStatus prometheus.Gauge + nodeID string ) func registerInfoMetrics() { @@ -26,19 +26,19 @@ func registerInfoMetrics() { } infoApp.WithLabelValues(banner.AppName, banner.AppVersion, nodeID).Set(1) - sync = prometheus.NewGauge(prometheus.GaugeOpts{ + syncStatus = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "sync", Help: "Node sync status.", }) registry.MustRegister(infoApp) - registry.MustRegister(sync) + registry.MustRegister(syncStatus) addCollect(collectInfoMetrics) } func collectInfoMetrics() { - sync.Set(func() float64 { + syncStatus.Set(func() float64 { if metrics.Synced() { return 1.0 } diff --git a/plugins/prometheus/plugin.go b/plugins/prometheus/plugin.go index 1a612d8700318c883c42bdadd21a56334a478be6..723e68061e737bab1346c3e56ff2e9cadc217f37 100644 --- a/plugins/prometheus/plugin.go +++ b/plugins/prometheus/plugin.go @@ -3,6 +3,7 @@ package prometheus import ( "context" "net/http" + "sync" "time" "github.com/gin-gonic/gin" @@ -16,9 +17,13 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) +// PluginName is the name of the prometheus plugin. +const PluginName = "Prometheus" + // Plugin Prometheus var ( - Plugin = node.NewPlugin("Prometheus", node.Disabled, configure, run) + plugin *node.Plugin + once sync.Once log *logger.Logger server *http.Server @@ -26,6 +31,14 @@ var ( collects []func() ) +// Plugin gets the plugin instance. +func Plugin() *node.Plugin { + once.Do(func() { + plugin = node.NewPlugin(PluginName, node.Disabled, configure, run) + }) + return plugin +} + func configure(plugin *node.Plugin) { log = logger.NewLogger(plugin.Name) diff --git a/plugins/research.go b/plugins/research.go index c624e49bf15d1be7ec888bb3144bfdbc33559122..adf5144bca86373d1d21f4da06c8d1b8c4487251 100644 --- a/plugins/research.go +++ b/plugins/research.go @@ -16,6 +16,6 @@ var Research = node.Plugins( analysisserver.Plugin(), analysisclient.Plugin(), analysisdashboard.Plugin(), - prometheus.Plugin, + prometheus.Plugin(), networkdelay.App(), )