Skip to content

Commit

Permalink
fix topology db node
Browse files Browse the repository at this point in the history
  • Loading branch information
innerpeacez committed Dec 20, 2021
1 parent ffc30ee commit 723dac8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions modules/monitor/apm/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions modules/monitor/apm/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions modules/msp/apm/service/apm.service.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions modules/msp/apm/service/components/service-list/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion modules/msp/apm/service/view/chart/error_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 723dac8

Please sign in to comment.