Skip to content

Commit

Permalink
Finish the depencency reader
Browse files Browse the repository at this point in the history
  • Loading branch information
qiansheng91 committed Aug 3, 2021
1 parent e4a1063 commit 45ffab4
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion sls_store/sls_dependency_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,63 @@ import (
"context"
slsSdk "github.com/aliyun/aliyun-log-go-sdk"
"github.com/jaegertracing/jaeger/model"
"strconv"
"time"
)

const (
// DependenciesQueryString The query string which calculates the dependency relationship between each service.
DependenciesQueryString = "* and version: service_name"

// ParentServiceFieldName The log item key of parent service name
ParentServiceFieldName = "parent_service"
// FailureCallingTimesFieldName The key of failure calling times
FailureCallingTimesFieldName = "n_status_fail"
// SuccessfulCallingTimesFieldName The key of successful calling times
SuccessfulCallingTimesFieldName = "n_status_succ"
// ParentService the key of parent service
ParentService = "parent_service"
// ChildService the key of child service
ChildService = "child_service"
)

type slsDependencyReader struct {
client *slsSdk.Client
instance slsTraceInstance
}

func (s slsDependencyReader) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
return nil, nil
response, error := s.client.GetLogs(s.instance.project(), s.instance.serviceDependencyLogStore(), "",
endTs.Unix()-int64(lookback), endTs.Unix(), DependenciesQueryString, 1000, 0, false)

if error != nil {
return nil, error
}

result := make([]model.DependencyLink, response.Count)
for i, log := range response.Logs {
if log[ParentServiceFieldName] == "None" {
continue
}

result[i] = model.DependencyLink{
Parent: log[ParentService],
Child: log[ChildService],
CallCount: getCallingTime(log),
}
}

return result, nil
}

func getCallingTime(log map[string]string) uint64 {
return getCallingTimes(log, SuccessfulCallingTimesFieldName) + getCallingTimes(log, FailureCallingTimesFieldName)
}

func getCallingTimes(log map[string]string, key string) uint64 {
successCount, e2 := strconv.Atoi(log[key])
if e2 != nil {
successCount = 0
}
return uint64(successCount)
}

0 comments on commit 45ffab4

Please sign in to comment.