2021-10-25 20:21:18 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-09-01 10:13:15 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-25 20:21:18 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-01 10:13:15 +08:00
|
|
|
//
|
2021-10-25 20:21:18 +08:00
|
|
|
// 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.
|
2021-09-01 10:13:15 +08:00
|
|
|
|
|
|
|
package datacoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-09-09 10:16:00 +08:00
|
|
|
"errors"
|
2021-09-01 10:13:15 +08:00
|
|
|
|
2022-09-16 16:56:49 +08:00
|
|
|
"github.com/milvus-io/milvus/api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/api/milvuspb"
|
2021-09-01 10:13:15 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2022-08-12 13:20:39 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-09-01 10:13:15 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-12-20 18:07:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
2022-01-05 17:17:26 +08:00
|
|
|
"go.uber.org/zap"
|
2021-09-01 10:13:15 +08:00
|
|
|
)
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
//getComponentConfigurations returns the configurations of dataNode matching req.Pattern
|
|
|
|
func getComponentConfigurations(ctx context.Context, req *internalpb.ShowConfigurationsRequest) *internalpb.ShowConfigurationsResponse {
|
|
|
|
prefix := "datacoord."
|
|
|
|
matchedConfig := Params.DataCoordCfg.Base.GetByPattern(prefix + req.Pattern)
|
|
|
|
configList := make([]*commonpb.KeyValuePair, 0, len(matchedConfig))
|
|
|
|
for key, value := range matchedConfig {
|
|
|
|
configList = append(configList,
|
|
|
|
&commonpb.KeyValuePair{
|
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &internalpb.ShowConfigurationsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Configuations: configList,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-09 22:14:14 +08:00
|
|
|
// getSystemInfoMetrics composes data cluster metrics
|
2021-09-01 10:13:15 +08:00
|
|
|
func (s *Server) getSystemInfoMetrics(
|
|
|
|
ctx context.Context,
|
|
|
|
req *milvuspb.GetMetricsRequest,
|
|
|
|
) (*milvuspb.GetMetricsResponse, error) {
|
2021-09-09 10:16:00 +08:00
|
|
|
// TODO(dragondriver): add more detail metrics
|
2021-09-01 10:13:15 +08:00
|
|
|
|
2021-09-09 10:16:00 +08:00
|
|
|
// get datacoord info
|
2021-10-14 15:44:34 +08:00
|
|
|
nodes := s.cluster.GetSessions()
|
2021-09-01 10:13:15 +08:00
|
|
|
clusterTopology := metricsinfo.DataClusterTopology{
|
2021-09-09 10:16:00 +08:00
|
|
|
Self: s.getDataCoordMetrics(),
|
|
|
|
ConnectedNodes: make([]metricsinfo.DataNodeInfos, 0, len(nodes)),
|
2021-09-01 10:13:15 +08:00
|
|
|
}
|
|
|
|
|
2021-09-09 10:16:00 +08:00
|
|
|
// for each data node, fetch metrics info
|
2021-09-01 17:35:00 +08:00
|
|
|
log.Debug("datacoord.getSystemInfoMetrics",
|
2021-12-21 19:03:20 +08:00
|
|
|
zap.Int("DataNodes number", len(nodes)))
|
2021-09-01 10:13:15 +08:00
|
|
|
for _, node := range nodes {
|
2021-09-09 10:16:00 +08:00
|
|
|
infos, err := s.getDataNodeMetrics(ctx, req, node)
|
2021-09-01 10:13:15 +08:00
|
|
|
if err != nil {
|
2021-12-21 19:03:20 +08:00
|
|
|
log.Warn("fails to get DataNode metrics", zap.Error(err))
|
2021-09-01 10:13:15 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
clusterTopology.ConnectedNodes = append(clusterTopology.ConnectedNodes, infos)
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:16:00 +08:00
|
|
|
// compose topolgoy struct
|
2021-09-01 10:13:15 +08:00
|
|
|
coordTopology := metricsinfo.DataCoordTopology{
|
|
|
|
Cluster: clusterTopology,
|
|
|
|
Connections: metricsinfo.ConnTopology{
|
2022-04-24 22:03:44 +08:00
|
|
|
Name: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
|
2021-09-01 17:35:00 +08:00
|
|
|
// TODO(dragondriver): fill ConnectedComponents if necessary
|
|
|
|
ConnectedComponents: []metricsinfo.ConnectionInfo{},
|
2021-09-01 10:13:15 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:16:00 +08:00
|
|
|
resp := &milvuspb.GetMetricsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
Response: "",
|
2022-04-24 22:03:44 +08:00
|
|
|
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
|
2021-09-09 10:16:00 +08:00
|
|
|
}
|
|
|
|
var err error
|
|
|
|
resp.Response, err = metricsinfo.MarshalTopology(coordTopology)
|
2021-09-01 10:13:15 +08:00
|
|
|
if err != nil {
|
2021-09-09 10:16:00 +08:00
|
|
|
resp.Status.Reason = err.Error()
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Status.ErrorCode = commonpb.ErrorCode_Success
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDataCoordMetrics composes datacoord infos
|
|
|
|
func (s *Server) getDataCoordMetrics() metricsinfo.DataCoordInfos {
|
2021-11-24 15:43:15 +08:00
|
|
|
ret := metricsinfo.DataCoordInfos{
|
2021-09-09 10:16:00 +08:00
|
|
|
BaseComponentInfos: metricsinfo.BaseComponentInfos{
|
2022-04-24 22:03:44 +08:00
|
|
|
Name: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, Params.DataCoordCfg.GetNodeID()),
|
2021-09-09 10:16:00 +08:00
|
|
|
HardwareInfos: metricsinfo.HardwareMetrics{
|
|
|
|
IP: s.session.Address,
|
|
|
|
CPUCoreCount: metricsinfo.GetCPUCoreCount(false),
|
|
|
|
CPUCoreUsage: metricsinfo.GetCPUUsage(),
|
|
|
|
Memory: metricsinfo.GetMemoryCount(),
|
|
|
|
MemoryUsage: metricsinfo.GetUsedMemoryCount(),
|
|
|
|
Disk: metricsinfo.GetDiskCount(),
|
|
|
|
DiskUsage: metricsinfo.GetDiskUsage(),
|
|
|
|
},
|
2021-11-24 15:43:15 +08:00
|
|
|
SystemInfo: metricsinfo.DeployMetrics{},
|
2021-12-23 18:39:11 +08:00
|
|
|
CreatedTime: Params.DataCoordCfg.CreatedTime.String(),
|
|
|
|
UpdatedTime: Params.DataCoordCfg.UpdatedTime.String(),
|
2021-09-26 17:50:07 +08:00
|
|
|
Type: typeutil.DataCoordRole,
|
2021-10-14 11:12:38 +08:00
|
|
|
ID: s.session.ServerID,
|
2021-09-09 10:16:00 +08:00
|
|
|
},
|
|
|
|
SystemConfigurations: metricsinfo.DataCoordConfiguration{
|
2021-12-23 18:39:11 +08:00
|
|
|
SegmentMaxSize: Params.DataCoordCfg.SegmentMaxSize,
|
2021-09-09 10:16:00 +08:00
|
|
|
},
|
2021-09-01 10:13:15 +08:00
|
|
|
}
|
2021-11-24 15:43:15 +08:00
|
|
|
|
|
|
|
metricsinfo.FillDeployMetricsWithEnv(&ret.BaseComponentInfos.SystemInfo)
|
|
|
|
|
|
|
|
return ret
|
2021-09-09 10:16:00 +08:00
|
|
|
}
|
2021-09-01 10:13:15 +08:00
|
|
|
|
2021-12-21 19:03:20 +08:00
|
|
|
// getDataNodeMetrics composes DataNode infos
|
|
|
|
// this function will invoke GetMetrics with DataNode specified in NodeInfo
|
2021-10-14 15:44:34 +08:00
|
|
|
func (s *Server) getDataNodeMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest, node *Session) (metricsinfo.DataNodeInfos, error) {
|
2021-09-09 10:16:00 +08:00
|
|
|
infos := metricsinfo.DataNodeInfos{
|
|
|
|
BaseComponentInfos: metricsinfo.BaseComponentInfos{
|
|
|
|
HasError: true,
|
2021-10-14 11:12:38 +08:00
|
|
|
ID: int64(uniquegenerator.GetUniqueIntGeneratorIns().GetInt()),
|
2021-09-01 10:13:15 +08:00
|
|
|
},
|
2021-09-09 10:16:00 +08:00
|
|
|
}
|
|
|
|
if node == nil {
|
2021-12-22 15:19:31 +08:00
|
|
|
return infos, errors.New("DataNode is nil")
|
2021-09-09 10:16:00 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 15:44:34 +08:00
|
|
|
cli, err := node.GetOrCreateClient(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return infos, err
|
2021-09-09 10:16:00 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 15:44:34 +08:00
|
|
|
metrics, err := cli.GetMetrics(ctx, req)
|
2021-09-09 10:16:00 +08:00
|
|
|
if err != nil {
|
2021-12-21 12:01:31 +08:00
|
|
|
log.Warn("invalid metrics of DataNode was found",
|
2021-09-09 10:16:00 +08:00
|
|
|
zap.Error(err))
|
|
|
|
infos.BaseComponentInfos.ErrorReason = err.Error()
|
|
|
|
// err handled, returns nil
|
|
|
|
return infos, nil
|
|
|
|
}
|
|
|
|
infos.BaseComponentInfos.Name = metrics.GetComponentName()
|
|
|
|
|
|
|
|
if metrics.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
2021-12-21 12:03:22 +08:00
|
|
|
log.Warn("invalid metrics of DataNode was found",
|
2021-09-09 10:16:00 +08:00
|
|
|
zap.Any("error_code", metrics.Status.ErrorCode),
|
|
|
|
zap.Any("error_reason", metrics.Status.Reason))
|
|
|
|
infos.BaseComponentInfos.ErrorReason = metrics.GetStatus().GetReason()
|
|
|
|
return infos, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = metricsinfo.UnmarshalComponentInfos(metrics.GetResponse(), &infos)
|
|
|
|
if err != nil {
|
2021-12-21 19:03:20 +08:00
|
|
|
log.Warn("invalid metrics of DataNode found",
|
2021-09-09 10:16:00 +08:00
|
|
|
zap.Error(err))
|
|
|
|
infos.BaseComponentInfos.ErrorReason = err.Error()
|
|
|
|
return infos, nil
|
|
|
|
}
|
|
|
|
infos.BaseComponentInfos.HasError = false
|
|
|
|
return infos, nil
|
2021-09-01 10:13:15 +08:00
|
|
|
}
|