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 <ye.zhen@zilliz.com>
This commit is contained in:
chyezh 2024-01-29 15:47:02 +08:00 committed by GitHub
parent fcd9f894ca
commit 211143c5e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 92 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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