diff --git a/Makefile b/Makefile index 4f2cf534..ad4a4516 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,8 @@ GIT_COMMIT = $(shell git rev-parse --short HEAD) VERSION = $(shell cat ./VERSION) BUILD_FLAGS ?= $(shell echo "-ldflags='\ - -X github.com/waku-org/waku/v2/node.GitCommit=$(GIT_COMMIT) \ - -X github.com/waku-org/waku/v2/node.Version=$(VERSION)'") + -X github.com/waku-org/go-waku/waku/v2/node.GitCommit=$(GIT_COMMIT) \ + -X github.com/waku-org/go-waku/waku/v2/node.Version=$(VERSION)'") # control rln code compilation diff --git a/waku/metrics/http.go b/waku/metrics/http.go index 632897d5..2effef6b 100644 --- a/waku/metrics/http.go +++ b/waku/metrics/http.go @@ -57,6 +57,7 @@ func NewMetricsServer(address string, port int, log *zap.Logger) *Server { metrics.StoreMessagesView, metrics.PeersView, metrics.DialsView, + metrics.VersionView, ); err != nil { p.log.Fatal("registering views", zap.Error(err)) } diff --git a/waku/node.go b/waku/node.go index 97010f1c..e06b1136 100644 --- a/waku/node.go +++ b/waku/node.go @@ -14,6 +14,8 @@ import ( "syscall" "time" + wmetrics "github.com/waku-org/go-waku/waku/v2/metrics" + "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -78,6 +80,8 @@ const dialTimeout = 7 * time.Second // Execute starts a go-waku node with settings determined by the Options parameter func Execute(options Options) { + utils.Logger().Info("Version details ", zap.String("version", node.Version), zap.String("commit", node.GitCommit)) + if options.GenerateKey { if err := writePrivateKeyToFile(options.KeyFile, []byte(options.KeyPasswd), options.Overwrite); err != nil { failOnErr(err, "nodekey error") @@ -118,6 +122,7 @@ func Execute(options Options) { if options.Metrics.Enable { metricsServer = metrics.NewMetricsServer(options.Metrics.Address, options.Metrics.Port, logger) go metricsServer.Start() + wmetrics.RecordVersion(context.Background(), node.Version, node.GitCommit) } nodeOpts := []node.WakuNodeOption{ diff --git a/waku/v2/metrics/metrics.go b/waku/v2/metrics/metrics.go index df757c1c..94da4498 100644 --- a/waku/v2/metrics/metrics.go +++ b/waku/v2/metrics/metrics.go @@ -2,6 +2,7 @@ package metrics import ( "context" + "fmt" "github.com/waku-org/go-waku/waku/v2/utils" "go.opencensus.io/stats" @@ -11,6 +12,7 @@ import ( ) var ( + WakuVersion = stats.Int64("waku_version", "", stats.UnitDimensionless) Messages = stats.Int64("node_messages", "Number of messages received", stats.UnitDimensionless) Peers = stats.Int64("peers", "Number of connected peers", stats.UnitDimensionless) Dials = stats.Int64("dials", "Number of peer dials", stats.UnitDimensionless) @@ -22,8 +24,9 @@ var ( ) var ( - KeyType, _ = tag.NewKey("type") - ErrorType, _ = tag.NewKey("error_type") + KeyType, _ = tag.NewKey("type") + ErrorType, _ = tag.NewKey("error_type") + GitVersion, _ = tag.NewKey("git_version") ) var ( @@ -72,6 +75,13 @@ var ( Aggregation: view.Count(), TagKeys: []tag.Key{ErrorType}, } + VersionView = &view.View{ + Name: "gowaku_version", + Measure: WakuVersion, + Description: "The gowaku version", + Aggregation: view.LastValue(), + TagKeys: []tag.Key{GitVersion}, + } ) func RecordLightpushError(ctx context.Context, tagType string) { @@ -97,3 +107,10 @@ func RecordStoreError(ctx context.Context, tagType string) { utils.Logger().Error("failed to record with tags", zap.Error(err)) } } + +func RecordVersion(ctx context.Context, version string, commit string) { + v := fmt.Sprintf("%s-%s", version, commit) + if err := stats.RecordWithTags(ctx, []tag.Mutator{tag.Insert(GitVersion, v)}, WakuVersion.M(1)); err != nil { + utils.Logger().Error("failed to record with tags", zap.Error(err)) + } +} diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index c9ddcf42..d3691c81 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -259,8 +259,6 @@ func (w *WakuNode) checkForAddressChanges() { // Start initializes all the protocols that were setup in the WakuNode func (w *WakuNode) Start() error { - w.log.Info("Version details ", zap.String("commit", GitCommit), zap.String("version", Version)) - if w.opts.enableSwap { w.swap = swap.NewWakuSwap(w.log, []swap.SwapOption{ swap.WithMode(w.opts.swapMode),