client

package
v0.0.0-...-f240d8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownApmType error = errors.New("no match apmType is found")
)

Functions

func GetClientCalls

func GetClientCalls(trace *apmmodel.OTelTrace, spanId string) []*model.ApmClientCall

func GetErrorSpans

func GetErrorSpans(node *apmmodel.OtelServiceNode) []*model.ErrorSpan

func GetMatchSampledSpanTrace

func GetMatchSampledSpanTrace(apmType string, service *apmmodel.OtelServiceNode, sampledTraces map[string]*model.Trace) *model.Trace

func NewApmClientCall

func NewApmClientCall(clientSpan *apmmodel.OtelSpan, serverEntrySpan *apmmodel.OtelSpan) *model.ApmClientCall

func SQLParseOperationAndTable

func SQLParseOperationAndTable(query string) (string, string)

func SQLParseOperationAndTableNEW

func SQLParseOperationAndTableNEW(query string) (string, string)

Types

type AdapterHTTPClient

type AdapterHTTPClient struct {
	TraceListAddress   string
	TraceDetailAddress string
	Timeout            time.Duration
	// contains filtered or unexported fields
}

func NewAdapterHTTPClient

func NewAdapterHTTPClient(address string, timeout int64) *AdapterHTTPClient

func (*AdapterHTTPClient) QueryDetail

func (c *AdapterHTTPClient) QueryDetail(ctx context.Context, queryParams *api.QueryParams) ([]*model.OtelSpan, error)

func (*AdapterHTTPClient) QueryList

func (c *AdapterHTTPClient) QueryList(ctx context.Context, queryParams *api.QueryParams) ([]*model.OtelServiceNode, error)

func (*AdapterHTTPClient) SetRountTriper

func (c *AdapterHTTPClient) SetRountTriper(rt http.RoundTripper)

type ApmTraceClient

type ApmTraceClient struct {
	// contains filtered or unexported fields
}

func NewApmTraceClient

func NewApmTraceClient(address string, timeout int64, muatedRatio int, mutateNodeMode string, getDetailTypes []string) *ApmTraceClient

func NewApmTraceClientByAPI

func NewApmTraceClientByAPI(api api.AdapterAPI, muatedRatio int, mutateNodeMode string, getDetailTypes []string) *ApmTraceClient

func (*ApmTraceClient) FillMutatedSpan

func (client *ApmTraceClient) FillMutatedSpan(ctx context.Context, clusterID string, apmType string, traceId string, serviceNode *apmmodel.OtelServiceNode) error

func (*ApmTraceClient) NeedGetDetailSpan

func (client *ApmTraceClient) NeedGetDetailSpan(ctx context.Context, apmType string) bool

func (*ApmTraceClient) QueryErrorTraceTree

func (client *ApmTraceClient) QueryErrorTraceTree(ctx context.Context, clusterID string, traceId string, traces *model.Traces) (*model.ErrorTreeNode, error)

func (*ApmTraceClient) QueryMutatedSlowTraceTree

func (client *ApmTraceClient) QueryMutatedSlowTraceTree(ctx context.Context, clusterID string, traceId string, traces *model.Traces) (*model.TraceTreeNode, []*model.ApmClientCall, error)

func (*ApmTraceClient) QueryServices

func (client *ApmTraceClient) QueryServices(ctx context.Context, clusterID string, apmType string, traceId string, rootTrace *model.TraceLabels) ([]*apmmodel.OtelServiceNode, error)

func (*ApmTraceClient) QueryTrace

func (client *ApmTraceClient) QueryTrace(ctx context.Context, clusterID string, apmType string, traceId string, rootTrace *model.TraceLabels) (*apmmodel.OTelTrace, error)

type CalcMutatedNodeFn

type CalcMutatedNodeFn func(tree *TraceTree, traceId string, ratioThreshold int) (*model.TraceTreeNode, error)
var CalcByMutatedService CalcMutatedNodeFn = func(tree *TraceTree, traceId string, ratioThreshold int) (*model.TraceTreeNode, error) {
	serviceEndPoints := newServiceEndPoints()
	for _, v := range tree.NodeMap {
		v.CalcMutateValue()
		serviceEndPoints.addMutateSpan(v)
	}
	sort.Sort(byServiceMutatedValue(serviceEndPoints.services))

	if len(serviceEndPoints.services) == 0 {
		return nil, fmt.Errorf("trace[%s] has no mutated service", traceId)
	}
	serviceEndPoint := serviceEndPoints.services[0]
	duration := tree.Root.TotalTime
	threshold := duration * uint64(ratioThreshold) / 100
	if serviceEndPoint.SelfTime < threshold {
		var percent float64 = 0
		if duration > 0 {
			percent = float64(serviceEndPoint.SelfTime*100) / float64(duration)
		}
		return nil, fmt.Errorf("service(%s) selfTime(%sms) has not enough duration ratio(%s%%)",
			serviceEndPoint.ServiceName,
			strconv.FormatFloat(float64(serviceEndPoint.SelfTime)/1000000, 'f', 2, 64),
			strconv.FormatFloat(percent, 'f', 2, 64))
	}

	node, _ := serviceEndPoint.getMutateNode()
	if node.MutatedValue > 0 {
		return node, nil
	}
	return nil, fmt.Errorf("Instance(%s) URL(%s) is not mutated. Mutated[%d], Self: %d", node.Id, node.Url, node.MutatedValue, node.SelfTime)
}
var CalcByMutatedSpan CalcMutatedNodeFn = func(tree *TraceTree, traceId string, ratioThreshold int) (*model.TraceTreeNode, error) {
	sortedNodes := make([]*model.TraceTreeNode, 0)
	for _, v := range tree.NodeMap {
		v.CalcMutateValue()
		if tree.Root.SpanId == v.SpanId && v.HasVNodeChild() {
			continue
		}
		sortedNodes = append(sortedNodes, v)
	}
	sort.Sort(byMuatedValue(sortedNodes))

	duration := tree.Root.TotalTime
	threshold := duration * uint64(ratioThreshold) / 100
	var profiledNode *model.TraceTreeNode = nil
	node := sortedNodes[0]
	if node.MutatedValue > 0 {
		if node.SelfTime >= threshold {
			return node, nil
		}
		if profiledNode == nil || profiledNode.SelfTime < node.SelfTime {
			profiledNode = node
		}
	}

	if profiledNode == nil {
		return nil, fmt.Errorf("Instance(%s) is not mutated. Mutated[%d], Self: %d", node.Id, node.MutatedValue, node.SelfTime)
	}

	var percent float64 = 0
	if duration > 0 {
		percent = float64(profiledNode.SelfTime*100) / float64(duration)
	}
	return nil, fmt.Errorf("Instance(%s) selfTime(%sms) has not enough duration ratio(%s%%)",
		profiledNode.Id,
		strconv.FormatFloat(float64(profiledNode.SelfTime)/1000000, 'f', 2, 64),
		strconv.FormatFloat(percent, 'f', 2, 64))
}
var CalcByTop3MutatedService CalcMutatedNodeFn = func(tree *TraceTree, traceId string, ratioThreshold int) (*model.TraceTreeNode, error) {
	serviceEndPoints := newServiceEndPoints()
	for _, v := range tree.NodeMap {
		v.CalcMutateValue()
		serviceEndPoints.addMutateSpan(v)
	}
	sort.Sort(byServiceMutatedValue(serviceEndPoints.services))

	if len(serviceEndPoints.services) == 0 {
		return nil, fmt.Errorf("trace[%s] has no mutated service", traceId)
	}
	duration := tree.Root.TotalTime
	threshold := duration * uint64(ratioThreshold) / 100
	var profiledMutatedNode *model.TraceTreeNode
	var profiled bool
	for i, serviceEndPoint := range serviceEndPoints.services {
		if i == 3 {
			break
		}
		if serviceEndPoint.SelfTime < threshold {
			var percent float64 = 0
			if duration > 0 {
				percent = float64(serviceEndPoint.SelfTime*100) / float64(duration)
			}
			log.Printf("The Top[%d] service(%s) selfTime(%sms) has not enough duration ratio(%s%%)",
				i+1, serviceEndPoint.ServiceName,
				strconv.FormatFloat(float64(serviceEndPoint.SelfTime)/1000000, 'f', 2, 64),
				strconv.FormatFloat(percent, 'f', 2, 64))
			continue
		}

		profiledMutatedNode, profiled = serviceEndPoint.getMutateNode()
		if profiledMutatedNode.MutatedValue > 0 && profiled {
			return profiledMutatedNode, nil
		}
	}

	if profiledMutatedNode == nil {
		return nil, fmt.Errorf("no Top3 service has enough duration ratio")
	} else {
		return nil, fmt.Errorf("top3 node [%s] has enough duration ratio but is not profiled",
			profiledMutatedNode.Id)
	}
}

type ErrorTraceTree

type ErrorTraceTree struct {
	Root    *model.ErrorTreeNode
	NodeMap map[string]*model.ErrorTreeNode
}

func BuildErrorTree

func BuildErrorTree(trace *apmmodel.OTelTrace, sampledTraces *model.Traces) (*ErrorTraceTree, error)

func ConvertErrorTree

func ConvertErrorTree(spanTrace *NodeSpanTrace) *ErrorTraceTree

func (*ErrorTraceTree) GetRootCauseErrorNode

func (tree *ErrorTraceTree) GetRootCauseErrorNode(traceId string) (*model.ErrorTreeNode, error)

type NodeSpanTrace

type NodeSpanTrace struct {
	SampledTrace *model.Trace
	// contains filtered or unexported fields
}

func (*NodeSpanTrace) GetClientCalls

func (trace *NodeSpanTrace) GetClientCalls(spanId string) []*model.ApmClientCall

func (*NodeSpanTrace) GetServiceNode

func (trace *NodeSpanTrace) GetServiceNode(spanId string) *apmmodel.OtelServiceNode

type NodeSpanTraces

type NodeSpanTraces struct {
	Traces []*NodeSpanTrace
}

func NewNodeSpanTraces

func NewNodeSpanTraces(apmType string, serviceNodes []*apmmodel.OtelServiceNode, sampledTraces *model.Traces) *NodeSpanTraces

type QueryParams

type QueryParams struct {
	TraceId    string `json:"traceId"`
	ApmType    string `json:"apmType"`
	StartTime  uint64 `json:"startTime"`
	Attributes string `json:"attributes,omitempty"`

	ClusterID string `json:"clusterId"`
}

type TraceTree

type TraceTree struct {
	Root    *model.TraceTreeNode
	NodeMap map[string]*model.TraceTreeNode
}

func BuildTopologyTree

func BuildTopologyTree(trace *apmmodel.OTelTrace, sampledTraces *model.Traces) (*TraceTree, error)

func ConvertSlowTree

func ConvertSlowTree(spanTrace *NodeSpanTrace) *TraceTree

func (*TraceTree) GetMutatedTraceNode

func (tree *TraceTree) GetMutatedTraceNode(traceId string, ratioThreshold int, mode string) (*model.TraceTreeNode, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址