mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-12 23:04:45 +00:00
feat: add version metric
This commit is contained in:
parent
821ac2af1b
commit
7e74155dca
4
Makefile
4
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
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user