feat: add version metric

This commit is contained in:
Richard Ramos 2022-11-25 17:24:34 -04:00 committed by RichΛrd
parent 821ac2af1b
commit 7e74155dca
5 changed files with 27 additions and 6 deletions

View File

@ -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

View File

@ -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))
}

View File

@ -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{

View File

@ -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)
@ -24,6 +26,7 @@ var (
var (
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))
}
}

View File

@ -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),