From 211143c5e6a1892c69c6cda54ffbea8ed6fa799b Mon Sep 17 00:00:00 2001 From: chyezh Date: Mon, 29 Jan 2024 15:47:02 +0800 Subject: [PATCH] enhance: add basic information of milvus into metrics (#29665) add basic build information and runtime component dependency into metrics. issue: #29664 Signed-off-by: chyezh --- cmd/milvus/run.go | 2 + internal/util/dependency/factory.go | 2 + pkg/metrics/info_metrics.go | 62 ++++++++++++++++++++++++++++ pkg/metrics/metrics.go | 2 + pkg/metrics/metrics_test.go | 19 +++++++++ pkg/util/paramtable/service_param.go | 5 +++ 6 files changed, 92 insertions(+) create mode 100644 pkg/metrics/info_metrics.go diff --git a/cmd/milvus/run.go b/cmd/milvus/run.go index 17f8e55ce2..e3796e16bc 100644 --- a/cmd/milvus/run.go +++ b/cmd/milvus/run.go @@ -11,6 +11,7 @@ import ( "go.uber.org/zap" "github.com/milvus-io/milvus/pkg/log" + "github.com/milvus-io/milvus/pkg/metrics" "github.com/milvus-io/milvus/pkg/util/hardware" "github.com/milvus-io/milvus/pkg/util/metricsinfo" ) @@ -59,6 +60,7 @@ func (c *run) printBanner(w io.Writer) { fmt.Fprintln(w, "GitCommit: "+GitCommit) fmt.Fprintln(w, "GoVersion: "+GoVersion) fmt.Fprintln(w) + metrics.BuildInfo.WithLabelValues(BuildTags, BuildTime, GitCommit).Set(1) } func (c *run) printHardwareInfo(w io.Writer) { diff --git a/internal/util/dependency/factory.go b/internal/util/dependency/factory.go index 7611434597..106cb32635 100644 --- a/internal/util/dependency/factory.go +++ b/internal/util/dependency/factory.go @@ -9,6 +9,7 @@ import ( smsgstream "github.com/milvus-io/milvus/internal/mq/msgstream" "github.com/milvus-io/milvus/internal/storage" "github.com/milvus-io/milvus/pkg/log" + "github.com/milvus-io/milvus/pkg/metrics" "github.com/milvus-io/milvus/pkg/mq/msgstream" "github.com/milvus-io/milvus/pkg/util/paramtable" ) @@ -81,6 +82,7 @@ func (f *DefaultFactory) Init(params *paramtable.ComponentParam) { func (f *DefaultFactory) initMQ(standalone bool, params *paramtable.ComponentParam) error { mqType := mustSelectMQType(standalone, params.MQCfg.Type.GetValue(), mqEnable{params.RocksmqEnable(), params.NatsmqEnable(), params.PulsarEnable(), params.KafkaEnable()}) + metrics.RegisterMQType(mqType) log.Info("try to init mq", zap.Bool("standalone", standalone), zap.String("mqType", mqType)) switch mqType { diff --git a/pkg/metrics/info_metrics.go b/pkg/metrics/info_metrics.go new file mode 100644 index 0000000000..9fbd579092 --- /dev/null +++ b/pkg/metrics/info_metrics.go @@ -0,0 +1,62 @@ +package metrics + +import ( + "sync" + + "github.com/prometheus/client_golang/prometheus" +) + +var ( + infoMutex sync.Mutex + mqType string + metaType string + + BuildInfo = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: milvusNamespace, + Name: "build_info", + Help: "Build information of milvus", + }, + []string{ + "version", + "built", + "git_commit", + }, + ) + + RuntimeInfo = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: milvusNamespace, + Name: "runtime_info", + Help: "Runtime information of milvus", + }, + []string{ + "mq", + "meta", + }, + ) +) + +// RegisterMQType registers the type of mq +func RegisterMQType(mq string) { + infoMutex.Lock() + defer infoMutex.Unlock() + mqType = mq + updateRuntimeInfo() +} + +// RegisterMetaType registers the type of meta +func RegisterMetaType(meta string) { + infoMutex.Lock() + defer infoMutex.Unlock() + metaType = meta + updateRuntimeInfo() +} + +// updateRuntimeInfo update the runtime info of milvus if every label is ready. +func updateRuntimeInfo() { + if mqType == "" || metaType == "" { + return + } + RuntimeInfo.WithLabelValues(mqType, metaType).Set(1) +} diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index a6e533585a..11c876a5c4 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -145,5 +145,7 @@ func GetRegisterer() prometheus.Registerer { func Register(r prometheus.Registerer) { r.MustRegister(NumNodes) r.MustRegister(LockCosts) + r.MustRegister(BuildInfo) + r.MustRegister(RuntimeInfo) metricRegisterer = r } diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go index 9709349c55..085dbdbe0b 100644 --- a/pkg/metrics/metrics_test.go +++ b/pkg/metrics/metrics_test.go @@ -21,6 +21,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" + "golang.org/x/sync/errgroup" ) func TestRegisterMetrics(t *testing.T) { @@ -50,3 +51,21 @@ func TestGetRegisterer(t *testing.T) { assert.NotNil(t, register) assert.Equal(t, r, register) } + +func TestRegisterRuntimeInfo(t *testing.T) { + g := &errgroup.Group{} + g.Go(func() error { + RegisterMetaType("etcd") + return nil + }) + g.Go(func() error { + RegisterMQType("pulsar") + return nil + }) + g.Wait() + + infoMutex.Lock() + defer infoMutex.Unlock() + assert.Equal(t, "etcd", metaType) + assert.Equal(t, "pulsar", mqType) +} diff --git a/pkg/util/paramtable/service_param.go b/pkg/util/paramtable/service_param.go index 1861f7afaa..ca6136d361 100644 --- a/pkg/util/paramtable/service_param.go +++ b/pkg/util/paramtable/service_param.go @@ -27,6 +27,7 @@ import ( "go.uber.org/zap" "github.com/milvus-io/milvus/pkg/log" + "github.com/milvus-io/milvus/pkg/metrics" "github.com/milvus-io/milvus/pkg/util" "github.com/milvus-io/milvus/pkg/util/metricsinfo" ) @@ -454,6 +455,10 @@ func (p *MetaStoreConfig) Init(base *BaseTable) { Export: true, } p.MetaStoreType.Init(base.mgr) + + // TODO: The initialization operation of metadata storage is called in the initialization phase of every node. + // There should be a single initialization operation for meta store, then move the metrics registration to there. + metrics.RegisterMetaType(p.MetaStoreType.GetValue()) } // /////////////////////////////////////////////////////////////////////////////