mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
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:
parent
fcd9f894ca
commit
211143c5e6
@ -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) {
|
||||
|
@ -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 {
|
||||
|
62
pkg/metrics/info_metrics.go
Normal file
62
pkg/metrics/info_metrics.go
Normal 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)
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user