mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 02:48:45 +08:00
Add more deploy metrics (#12248)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
This commit is contained in:
parent
283d7b0919
commit
6c4c0ef6b5
24
cmd/main.go
24
cmd/main.go
@ -72,9 +72,29 @@ func printBanner() {
|
||||
func injectVariablesToEnv() {
|
||||
// inject in need
|
||||
|
||||
err := os.Setenv(metricsinfo.GitCommitEnvKey, GitCommit)
|
||||
var err error
|
||||
|
||||
err = os.Setenv(metricsinfo.GitCommitEnvKey, GitCommit)
|
||||
if err != nil {
|
||||
log.Warn("failed to inject git commit to environment variable",
|
||||
log.Warn(fmt.Sprintf("failed to inject %s to environment variable", metricsinfo.GitCommitEnvKey),
|
||||
zap.Error(err))
|
||||
}
|
||||
|
||||
err = os.Setenv(metricsinfo.GitBuildTagsEnvKey, BuildTags)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("failed to inject %s to environment variable", metricsinfo.GitBuildTagsEnvKey),
|
||||
zap.Error(err))
|
||||
}
|
||||
|
||||
err = os.Setenv(metricsinfo.MilvusBuildTimeEnvKey, BuildTime)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("failed to inject %s to environment variable", metricsinfo.MilvusBuildTimeEnvKey),
|
||||
zap.Error(err))
|
||||
}
|
||||
|
||||
err = os.Setenv(metricsinfo.MilvusUsedGoVersion, GoVersion)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("failed to inject %s to environment variable", metricsinfo.MilvusUsedGoVersion),
|
||||
zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package datacoord
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
||||
|
||||
@ -90,7 +89,7 @@ func (s *Server) getSystemInfoMetrics(
|
||||
|
||||
// getDataCoordMetrics composes datacoord infos
|
||||
func (s *Server) getDataCoordMetrics() metricsinfo.DataCoordInfos {
|
||||
return metricsinfo.DataCoordInfos{
|
||||
ret := metricsinfo.DataCoordInfos{
|
||||
BaseComponentInfos: metricsinfo.BaseComponentInfos{
|
||||
Name: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.NodeID),
|
||||
HardwareInfos: metricsinfo.HardwareMetrics{
|
||||
@ -102,10 +101,7 @@ func (s *Server) getDataCoordMetrics() metricsinfo.DataCoordInfos {
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.DataCoordRole,
|
||||
@ -115,6 +111,10 @@ func (s *Server) getDataCoordMetrics() metricsinfo.DataCoordInfos {
|
||||
SegmentMaxSize: Params.SegmentMaxSize,
|
||||
},
|
||||
}
|
||||
|
||||
metricsinfo.FillDeployMetricsWithEnv(&ret.BaseComponentInfos.SystemInfo)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// getDataNodeMetrics composes data node infos
|
||||
|
@ -18,7 +18,6 @@ package datanode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
||||
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
||||
@ -40,10 +39,7 @@ func (node *DataNode) getSystemInfoMetrics(ctx context.Context, req *milvuspb.Ge
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.DataNodeRole,
|
||||
@ -53,6 +49,9 @@ func (node *DataNode) getSystemInfoMetrics(ctx context.Context, req *milvuspb.Ge
|
||||
FlushInsertBufferSize: Params.FlushInsertBufferSize,
|
||||
},
|
||||
}
|
||||
|
||||
metricsinfo.FillDeployMetricsWithEnv(&nodeInfos.SystemInfo)
|
||||
|
||||
resp, err := metricsinfo.MarshalComponentInfos(nodeInfos)
|
||||
if err != nil {
|
||||
return &milvuspb.GetMetricsResponse{
|
||||
|
@ -18,7 +18,6 @@ package indexcoord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
||||
|
||||
@ -53,10 +52,7 @@ func getSystemInfoMetrics(
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.IndexCoordRole,
|
||||
@ -69,6 +65,8 @@ func getSystemInfoMetrics(
|
||||
ConnectedNodes: make([]metricsinfo.IndexNodeInfos, 0),
|
||||
}
|
||||
|
||||
metricsinfo.FillDeployMetricsWithEnv(&clusterTopology.Self.SystemInfo)
|
||||
|
||||
nodesMetrics := coord.nodeManager.getMetrics(ctx, req)
|
||||
for _, nodeMetrics := range nodesMetrics {
|
||||
if nodeMetrics.err != nil {
|
||||
|
@ -18,7 +18,6 @@ package indexnode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
||||
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
||||
@ -46,10 +45,7 @@ func getSystemInfoMetrics(
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.IndexNodeRole,
|
||||
@ -61,6 +57,9 @@ func getSystemInfoMetrics(
|
||||
SimdType: Params.SimdType,
|
||||
},
|
||||
}
|
||||
|
||||
metricsinfo.FillDeployMetricsWithEnv(&nodeInfos.SystemInfo)
|
||||
|
||||
resp, err := metricsinfo.MarshalComponentInfos(nodeInfos)
|
||||
if err != nil {
|
||||
return &milvuspb.GetMetricsResponse{
|
||||
|
@ -2422,6 +2422,19 @@ func (node *Proxy) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsReque
|
||||
log.Debug("Proxy.GetMetrics",
|
||||
zap.String("metric_type", metricType))
|
||||
|
||||
msgID := UniqueID(0)
|
||||
msgID, err = node.idAllocator.AllocOne()
|
||||
if err != nil {
|
||||
log.Warn("Proxy.GetMetrics failed to allocate id",
|
||||
zap.Error(err))
|
||||
}
|
||||
req.Base = &commonpb.MsgBase{
|
||||
MsgType: commonpb.MsgType_SystemInfo,
|
||||
MsgID: msgID,
|
||||
Timestamp: 0,
|
||||
SourceID: Params.ProxyID,
|
||||
}
|
||||
|
||||
if metricType == metricsinfo.SystemInfoMetrics {
|
||||
ret, err := node.metricsCacheManager.GetSystemInfoMetrics()
|
||||
if err == nil && ret != nil {
|
||||
|
@ -18,7 +18,6 @@ package proxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
||||
|
||||
@ -48,6 +47,7 @@ func getSystemInfoMetrics(
|
||||
|
||||
proxyRoleName := metricsinfo.ConstructComponentName(typeutil.ProxyRole, Params.ProxyID)
|
||||
identifierMap[proxyRoleName] = int(node.session.ServerID)
|
||||
|
||||
proxyTopologyNode := metricsinfo.SystemTopologyNode{
|
||||
Identifier: int(node.session.ServerID),
|
||||
Connected: make([]metricsinfo.ConnectionEdge, 0),
|
||||
@ -65,10 +65,7 @@ func getSystemInfoMetrics(
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.ProxyRole,
|
||||
@ -80,6 +77,7 @@ func getSystemInfoMetrics(
|
||||
},
|
||||
},
|
||||
}
|
||||
metricsinfo.FillDeployMetricsWithEnv(&(proxyTopologyNode.Infos.(*metricsinfo.ProxyInfos).SystemInfo))
|
||||
|
||||
queryCoordResp, queryCoordErr := node.queryCoord.GetMetrics(ctx, request)
|
||||
queryCoordRoleName := ""
|
||||
|
@ -18,7 +18,6 @@ package querycoord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
||||
|
||||
@ -53,10 +52,7 @@ func getSystemInfoMetrics(
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.QueryCoordRole,
|
||||
@ -69,6 +65,7 @@ func getSystemInfoMetrics(
|
||||
},
|
||||
ConnectedNodes: make([]metricsinfo.QueryNodeInfos, 0),
|
||||
}
|
||||
metricsinfo.FillDeployMetricsWithEnv(&clusterTopology.Self.SystemInfo)
|
||||
|
||||
nodesMetrics := qc.cluster.getMetrics(ctx, req)
|
||||
for _, nodeMetrics := range nodesMetrics {
|
||||
|
@ -13,7 +13,6 @@ package querynode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
||||
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
||||
@ -42,10 +41,7 @@ func getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest,
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.QueryNodeRole,
|
||||
@ -62,6 +58,8 @@ func getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest,
|
||||
SimdType: Params.SimdType,
|
||||
},
|
||||
}
|
||||
metricsinfo.FillDeployMetricsWithEnv(&nodeInfos.SystemInfo)
|
||||
|
||||
resp, err := metricsinfo.MarshalComponentInfos(nodeInfos)
|
||||
if err != nil {
|
||||
return &milvuspb.GetMetricsResponse{
|
||||
|
@ -13,7 +13,6 @@ package rootcoord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
@ -39,10 +38,7 @@ func (c *Core) getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetric
|
||||
Disk: metricsinfo.GetDiskCount(),
|
||||
DiskUsage: metricsinfo.GetDiskUsage(),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{
|
||||
SystemVersion: os.Getenv(metricsinfo.GitCommitEnvKey),
|
||||
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
||||
},
|
||||
SystemInfo: metricsinfo.DeployMetrics{},
|
||||
CreatedTime: Params.CreatedTime.String(),
|
||||
UpdatedTime: Params.UpdatedTime.String(),
|
||||
Type: typeutil.RootCoordRole,
|
||||
@ -58,6 +54,7 @@ func (c *Core) getSystemInfoMetrics(ctx context.Context, req *milvuspb.GetMetric
|
||||
ConnectedComponents: []metricsinfo.ConnectionInfo{},
|
||||
},
|
||||
}
|
||||
metricsinfo.FillDeployMetricsWithEnv(&rootCoordTopology.Self.SystemInfo)
|
||||
|
||||
resp, err := metricsinfo.MarshalTopology(rootCoordTopology)
|
||||
if err != nil {
|
||||
|
@ -57,12 +57,24 @@ const (
|
||||
|
||||
// StandaloneDeployMode represents the stand-alone deployment mode
|
||||
StandaloneDeployMode = "STANDALONE"
|
||||
|
||||
// GitBuildTagsEnvKey build tag
|
||||
GitBuildTagsEnvKey = "MILVUS_GIT_BUILD_TAGS"
|
||||
|
||||
// MilvusBuildTimeEnvKey build time
|
||||
MilvusBuildTimeEnvKey = "MILVUS_BUILD_TIME"
|
||||
|
||||
// MilvusUsedGoVersion used go version
|
||||
MilvusUsedGoVersion = "MILVUS_USED_GO_VERSION"
|
||||
)
|
||||
|
||||
// DeployMetrics records the deploy information of nodes.
|
||||
type DeployMetrics struct {
|
||||
SystemVersion string `json:"system_version"`
|
||||
DeployMode string `json:"deploy_mode"`
|
||||
BuildVersion string `json:"build_version"`
|
||||
BuildTime string `json:"build_time"`
|
||||
UsedGoVersion string `json:"used_go_version"`
|
||||
}
|
||||
|
||||
// BaseComponentInfos contains basic information that all components should have.
|
||||
|
@ -40,6 +40,9 @@ func TestBaseComponentInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -74,6 +77,9 @@ func TestQueryNodeInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -119,6 +125,9 @@ func TestQueryCoordInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -158,6 +167,9 @@ func TestIndexNodeInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -198,6 +210,9 @@ func TestIndexCoordInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -236,6 +251,9 @@ func TestDataNodeInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -274,6 +292,9 @@ func TestDataCoordInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
@ -312,6 +333,9 @@ func TestRootCoordInfos_Codec(t *testing.T) {
|
||||
SystemInfo: DeployMetrics{
|
||||
SystemVersion: "8b1ae98fa97ce1c7ba853e8b9ff1c7ce24458dc1",
|
||||
DeployMode: ClusterDeployMode,
|
||||
BuildVersion: "2.0.0-rc8",
|
||||
BuildTime: "2021-11-24, 11:37:25",
|
||||
UsedGoVersion: "go version go1.15.2 linux/amd64",
|
||||
},
|
||||
CreatedTime: time.Now().String(),
|
||||
UpdatedTime: time.Now().String(),
|
||||
|
25
internal/util/metricsinfo/utils.go
Normal file
25
internal/util/metricsinfo/utils.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
package metricsinfo
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// FillDeployMetricsWithEnv fill deploy metrics with env.
|
||||
func FillDeployMetricsWithEnv(m *DeployMetrics) {
|
||||
m.SystemVersion = os.Getenv(GitCommitEnvKey)
|
||||
m.DeployMode = os.Getenv(DeployModeEnvKey)
|
||||
m.BuildVersion = os.Getenv(GitBuildTagsEnvKey)
|
||||
m.UsedGoVersion = os.Getenv(MilvusUsedGoVersion)
|
||||
m.BuildTime = os.Getenv(MilvusBuildTimeEnvKey)
|
||||
}
|
73
internal/util/metricsinfo/utils_test.go
Normal file
73
internal/util/metricsinfo/utils_test.go
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
package metricsinfo
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFillDeployMetricsWithEnv(t *testing.T) {
|
||||
var err error
|
||||
|
||||
var m DeployMetrics
|
||||
|
||||
commit := "commit"
|
||||
originalCommit := os.Getenv(GitCommitEnvKey)
|
||||
err = os.Setenv(GitCommitEnvKey, commit)
|
||||
assert.NoError(t, err)
|
||||
|
||||
deploy := "deploy"
|
||||
originalDeploy := os.Getenv(DeployModeEnvKey)
|
||||
err = os.Setenv(DeployModeEnvKey, deploy)
|
||||
assert.NoError(t, err)
|
||||
|
||||
version := "version"
|
||||
originalVersion := os.Getenv(GitBuildTagsEnvKey)
|
||||
err = os.Setenv(GitBuildTagsEnvKey, version)
|
||||
assert.NoError(t, err)
|
||||
|
||||
goVersion := "go"
|
||||
originalGoVersion := os.Getenv(MilvusUsedGoVersion)
|
||||
err = os.Setenv(MilvusUsedGoVersion, goVersion)
|
||||
assert.NoError(t, err)
|
||||
|
||||
buildTime := "build"
|
||||
originalBuildTime := os.Getenv(MilvusBuildTimeEnvKey)
|
||||
err = os.Setenv(MilvusBuildTimeEnvKey, buildTime)
|
||||
assert.NoError(t, err)
|
||||
|
||||
FillDeployMetricsWithEnv(&m)
|
||||
assert.NotNil(t, m)
|
||||
assert.Equal(t, commit, m.SystemVersion)
|
||||
assert.Equal(t, deploy, m.DeployMode)
|
||||
assert.Equal(t, version, m.BuildVersion)
|
||||
assert.Equal(t, goVersion, m.UsedGoVersion)
|
||||
assert.Equal(t, buildTime, m.BuildTime)
|
||||
|
||||
err = os.Setenv(GitCommitEnvKey, originalCommit)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.Setenv(DeployModeEnvKey, originalDeploy)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.Setenv(GitBuildTagsEnvKey, originalVersion)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.Setenv(MilvusUsedGoVersion, originalGoVersion)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.Setenv(MilvusBuildTimeEnvKey, originalBuildTime)
|
||||
assert.NoError(t, err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user