Fix a potential nullptr issue with metric (#18540)

/kind improvement

related to: #18530

but not the root cause

Signed-off-by: Yuchen Gao <yuchen.gao@zilliz.com>
pull/18575/head
Ten Thousand Leaves 2022-08-09 21:12:42 +08:00 committed by GitHub
parent 179b496824
commit 12023e8569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -24,8 +24,6 @@ import (
"sync/atomic"
"time"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/proto/commonpb"
@ -36,6 +34,8 @@ import (
"github.com/milvus-io/milvus/internal/util/metricsinfo"
"github.com/milvus-io/milvus/internal/util/retry"
"github.com/milvus-io/milvus/internal/util/trace"
"github.com/milvus-io/milvus/internal/util/typeutil"
"go.uber.org/zap"
)
// checks whether server in Healthy State
@ -729,6 +729,7 @@ func (s *Server) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest
zap.Error(errDataCoordIsUnhealthy(Params.DataCoordCfg.GetNodeID())))
return &milvuspb.GetMetricsResponse{
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: msgDataCoordIsUnhealthy(Params.DataCoordCfg.GetNodeID()),
@ -745,6 +746,7 @@ func (s *Server) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest
zap.Error(err))
return &milvuspb.GetMetricsResponse{
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: err.Error(),
@ -784,6 +786,7 @@ func (s *Server) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest
zap.String("metric_type", metricType))
return &milvuspb.GetMetricsResponse{
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: metricsinfo.MsgUnimplementedMetric,

View File

@ -21,12 +21,9 @@ import (
"sync"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/util/typeutil"
"github.com/milvus-io/milvus/internal/util/metricsinfo"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
"github.com/milvus-io/milvus/internal/util/metricsinfo"
"github.com/milvus-io/milvus/internal/util/typeutil"
)
type getMetricsFuncType func(ctx context.Context, request *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
@ -107,7 +104,7 @@ func getSystemInfoMetrics(
defer wg.Done()
queryCoordResp, queryCoordErr = node.queryCoord.GetMetrics(ctx, request)
queryCoordRoleName = queryCoordResp.ComponentName
queryCoordRoleName = queryCoordResp.GetComponentName()
queryCoordErr = metricsinfo.UnmarshalTopology(queryCoordResp.Response, &queryCoordTopology)
}()
@ -116,7 +113,7 @@ func getSystemInfoMetrics(
defer wg.Done()
dataCoordResp, dataCoordErr = node.dataCoord.GetMetrics(ctx, request)
dataCoordRoleName = dataCoordResp.ComponentName
dataCoordRoleName = dataCoordResp.GetComponentName()
dataCoordErr = metricsinfo.UnmarshalTopology(dataCoordResp.Response, &dataCoordTopology)
}()
@ -125,7 +122,7 @@ func getSystemInfoMetrics(
defer wg.Done()
indexCoordResp, indexCoordErr = node.indexCoord.GetMetrics(ctx, request)
indexCoordRoleName = indexCoordResp.ComponentName
indexCoordRoleName = indexCoordResp.GetComponentName()
indexCoordErr = metricsinfo.UnmarshalTopology(indexCoordResp.Response, &indexCoordTopology)
}()
@ -134,7 +131,7 @@ func getSystemInfoMetrics(
defer wg.Done()
rootCoordResp, rootCoordErr = node.rootCoord.GetMetrics(ctx, request)
rootCoordRoleName = rootCoordResp.ComponentName
rootCoordRoleName = rootCoordResp.GetComponentName()
rootCoordErr = metricsinfo.UnmarshalTopology(rootCoordResp.Response, &rootCoordTopology)
}()