From 723dac82541d58a60723ce2256ecbbda3ded8686 Mon Sep 17 00:00:00 2001 From: innerpeacez Date: Mon, 20 Dec 2021 17:11:36 +0800 Subject: [PATCH] fix topology db node --- modules/monitor/apm/common/common.go | 2 ++ modules/monitor/apm/topology/topology.go | 12 +++++++----- modules/msp/apm/service/apm.service.service.go | 4 ++-- .../apm/service/components/service-list/provider.go | 6 +++--- .../service/components/service-overview/provider.go | 3 ++- modules/msp/apm/service/view/chart/error_rate.go | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/monitor/apm/common/common.go b/modules/monitor/apm/common/common.go index 468a0ccecfd..cb2e4e4bccb 100644 --- a/modules/monitor/apm/common/common.go +++ b/modules/monitor/apm/common/common.go @@ -50,6 +50,8 @@ const ( TagsHttpUrl = Tags + Sep4 + "http_url" TagsPeerServiceScope = Tags + Sep4 + "peer_service_scope" TagsPeerAddress = Tags + Sep4 + "peer_address" + TagsDBSystem = Tags + Sep4 + "db_system" + TagsDBHost = Tags + Sep4 + "db_host" TagsPeerService = Tags + Sep4 + "peer_service" TagsApplicationId = Tags + Sep4 + "application_id" TagsApplicationName = Tags + Sep4 + "application_name" diff --git a/modules/monitor/apm/topology/topology.go b/modules/monitor/apm/topology/topology.go index 9364041b470..cbdfc36b0a5 100644 --- a/modules/monitor/apm/topology/topology.go +++ b/modules/monitor/apm/topology/topology.go @@ -178,11 +178,13 @@ type Field struct { type Tag struct { Component string `json:"component,omitempty"` DBType string `json:"db_type,omitempty"` + DBSystem string `json:"db_system,omitempty"` Host string `json:"host,omitempty"` HttpUrl string `json:"http_url,omitempty"` PeerServiceScope string `json:"peer_service_scope,omitempty"` PeerAddress string `json:"peer_address,omitempty"` PeerService string `json:"peer_service,omitempty"` + DBHost string `json:"db_host,omitempty"` SourceProjectId string `json:"source_project_id,omitempty"` SourceProjectName string `json:"source_project_name,omitempty"` SourceWorkspace string `json:"source_workspace,omitempty"` @@ -421,8 +423,8 @@ func init() { } TargetComponentNodeType = &NodeType{ Type: TargetComponentNode, - GroupByField: &GroupByField{Name: apm.TagsPeerAddress, SubField: &GroupByField{Name: apm.TagsDBType}}, - SourceFields: []string{apm.TagsComponent, apm.TagsHost, apm.TagsTargetAddonGroup, apm.TagsDBType, apm.TagsPeerAddress}, + GroupByField: &GroupByField{Name: apm.TagsDBHost, SubField: &GroupByField{Name: apm.TagsDBSystem}}, + SourceFields: []string{apm.TagsComponent, apm.TagsHost, apm.TagsTargetAddonGroup, apm.TagsDBSystem, apm.TagsDBHost}, Filter: elastic.NewBoolQuery().MustNot(elastic.NewExistsQuery(apm.TagsTargetAddonType)), Aggregation: NodeAggregation, } @@ -1763,9 +1765,9 @@ func columnsParser(nodeType string, nodeRelation *TopologyNodeRelation) *Node { node.Id = encodeTypeToKey(node.AddonId + apm.Sep1 + node.AddonType) case TargetComponentNode: node.Type = tags.Component - node.Name = tags.PeerAddress - if tags.DBType != "" { - node.Type = tags.DBType + node.Name = tags.DBHost + if tags.DBSystem != "" { + node.Type = tags.DBSystem } node.Id = encodeTypeToKey(node.Type + apm.Sep1 + node.Name) case SourceMQNode: diff --git a/modules/msp/apm/service/apm.service.service.go b/modules/msp/apm/service/apm.service.service.go index a6ae3a2cc76..0d44fc50fd6 100644 --- a/modules/msp/apm/service/apm.service.service.go +++ b/modules/msp/apm/service/apm.service.service.go @@ -319,7 +319,7 @@ func (s *apmServiceService) GetServiceCount(ctx context.Context, req *pb.GetServ total := int64(countResponse.Results[0].Series[0].Rows[0].GetValues()[0].GetNumberValue()) // hasError count - statement = "SELECT DISTINCT(target_service_id::tag) FROM application_http_service WHERE $condition" + statement = "SELECT DISTINCT(target_service_id::tag) FROM application_http_service,application_rpc_service,application_db_service,application_cache_service,application_mq_service WHERE $condition" unhealthyCondition := " target_terminus_key::tag=$target_terminus_key AND errors_sum::field>0 " statement = strings.ReplaceAll(statement, "$condition", unhealthyCondition) @@ -339,7 +339,7 @@ func (s *apmServiceService) GetServiceCount(ctx context.Context, req *pb.GetServ hasErrorCount := int64(countResponse.Results[0].Series[0].Rows[0].GetValues()[0].GetNumberValue()) // withoutRequest count - statement = "SELECT DISTINCT(target_service_id::tag) FROM application_http_service WHERE $condition" + statement = "SELECT DISTINCT(target_service_id::tag) FROM application_http_service,application_rpc_service,application_db_service,application_cache_service,application_mq_service WHERE $condition" withoutRequestCondition := "target_terminus_key::tag=$target_terminus_key AND elapsed_sum::field<=0 " statement = strings.ReplaceAll(statement, "$condition", withoutRequestCondition) queryParams = map[string]*structpb.Value{ diff --git a/modules/msp/apm/service/components/service-list/provider.go b/modules/msp/apm/service/components/service-list/provider.go index 6b4d137e707..496f47578bd 100644 --- a/modules/msp/apm/service/components/service-list/provider.go +++ b/modules/msp/apm/service/components/service-list/provider.go @@ -103,7 +103,7 @@ func (p *provider) RegisterInitializeOp() (opFunc cptype.OperationFunc) { func (p *provider) errorRateTop5(interval int64, tenantId interface{}, start int64, end int64, ctx context.Context) ([]topn.Item, error) { statement := fmt.Sprintf("SELECT target_service_id::tag,target_service_name::tag,sum(errors_sum::field)/sum(count_sum::field) " + - "FROM application_http_service " + + "FROM application_http_service,application_rpc_service,application_db_service,application_cache_service,application_mq_service " + "WHERE (target_terminus_key::tag=$terminus_key OR source_terminus_key::tag=$terminus_key) " + "GROUP BY target_service_id::tag ") queryParams := map[string]*structpb.Value{ @@ -185,12 +185,12 @@ func (p *provider) avgDurationTop5(interval int64, tenantId interface{}, start i if rows == nil || len(rows) == 0 { return items, nil } - total := math.DecimalPlacesWithDigitsNumber(rows[0].Values[2].GetNumberValue()/1e6, 2) + total := math.DecimalPlacesWithDigitsNumber(rows[0].Values[2].GetNumberValue(), 2) for _, row := range rows { var item topn.Item item.ID = row.Values[0].GetStringValue() item.Name = row.Values[1].GetStringValue() - item.Value = math.DecimalPlacesWithDigitsNumber(row.Values[2].GetNumberValue()/1e6, 2) + item.Value = math.DecimalPlacesWithDigitsNumber(row.Values[2].GetNumberValue(), 2) if item.Value == 0 { continue } diff --git a/modules/msp/apm/service/components/service-overview/provider.go b/modules/msp/apm/service/components/service-overview/provider.go index 4ff48a17f02..afc3a34e4ee 100644 --- a/modules/msp/apm/service/components/service-overview/provider.go +++ b/modules/msp/apm/service/components/service-overview/provider.go @@ -21,6 +21,8 @@ import ( "sort" "strconv" + "google.golang.org/protobuf/types/known/structpb" + "github.com/erda-project/erda-infra/base/logs" "github.com/erda-project/erda-infra/base/servicehub" "github.com/erda-project/erda-infra/providers/component-protocol/components/topn" @@ -31,7 +33,6 @@ import ( metricpb "github.com/erda-project/erda-proto-go/core/monitor/metric/pb" "github.com/erda-project/erda/pkg/math" "github.com/erda-project/erda/pkg/time" - "google.golang.org/protobuf/types/known/structpb" ) type provider struct { diff --git a/modules/msp/apm/service/view/chart/error_rate.go b/modules/msp/apm/service/view/chart/error_rate.go index 62cd98849f9..7cbadc92333 100644 --- a/modules/msp/apm/service/view/chart/error_rate.go +++ b/modules/msp/apm/service/view/chart/error_rate.go @@ -34,7 +34,7 @@ type ErrorRateChart struct { func (errorRate *ErrorRateChart) GetChart(ctx context.Context) (*pb.ServiceChart, error) { statement := fmt.Sprintf("SELECT sum(if(eq(error::tag, 'true'),elapsed_count::field,0))/sum(elapsed_count::field) "+ - "FROM application_http "+ + "FROM application_http,application_rpc,application_db,application_cache,application_mq "+ "WHERE (target_terminus_key::tag=$terminus_key OR source_terminus_key::tag=$terminus_key) "+ "AND target_service_id::tag=$service_id "+ "GROUP BY time(%s)", errorRate.Interval)