mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 06:09:00 +08:00
changed errors to percent in external calls
This commit is contained in:
parent
ade18bc11f
commit
a6b1c271ee
@ -49,6 +49,8 @@ type ServiceExternalItem struct {
|
||||
AvgDuration float32 `json:"avgDuration,omitempty"`
|
||||
NumCalls int `json:"numCalls,omitempty"`
|
||||
CallRate float32 `json:"callRate,omitempty"`
|
||||
NumErrors int `json:"numErrors"`
|
||||
ErrorRate float32 `json:"errorRate"`
|
||||
}
|
||||
|
||||
type ServiceDBOverviewItem struct {
|
||||
@ -295,15 +297,51 @@ func GetServiceExternalErrors(client *SqlClient, query *model.GetServiceOverview
|
||||
return nil, fmt.Errorf("Error in unmarshalling response from druid")
|
||||
}
|
||||
|
||||
for i, _ := range *res {
|
||||
timeObj, _ := time.Parse(time.RFC3339Nano, (*res)[i].Time)
|
||||
(*res)[i].Timestamp = int64(timeObj.UnixNano())
|
||||
(*res)[i].Time = ""
|
||||
(*res)[i].CallRate = float32((*res)[i].NumCalls) / float32(query.StepSeconds)
|
||||
sqlQuery = fmt.Sprintf(`SELECT TIME_FLOOR(__time, '%s') as "time", COUNT(SpanId) as "numCalls", ExternalHttpUrl as externalHttpUrl FROM %s WHERE ServiceName='%s' AND Kind='3' AND ExternalHttpUrl != '' AND "__time" >= '%s' AND "__time" <= '%s'
|
||||
GROUP BY TIME_FLOOR(__time, '%s'), ExternalHttpUrl`, query.Period, constants.DruidDatasource, query.ServiceName, query.StartTime, query.EndTime, query.Period)
|
||||
|
||||
// zap.S().Debug(sqlQuery)
|
||||
|
||||
responseTotal, err := client.Query(sqlQuery, "object")
|
||||
|
||||
if err != nil {
|
||||
zap.S().Error(query, err)
|
||||
return nil, fmt.Errorf("Something went wrong in druid query")
|
||||
}
|
||||
|
||||
// responseStr := string(response)
|
||||
// zap.S().Info(responseStr)
|
||||
|
||||
resTotal := new([]ServiceExternalItem)
|
||||
err = json.Unmarshal(responseTotal, resTotal)
|
||||
if err != nil {
|
||||
zap.S().Error(err)
|
||||
return nil, fmt.Errorf("Error in unmarshalling response from druid")
|
||||
}
|
||||
|
||||
m := make(map[int64]int)
|
||||
|
||||
for j, _ := range *res {
|
||||
timeObj, _ := time.Parse(time.RFC3339Nano, (*res)[j].Time)
|
||||
m[int64(timeObj.UnixNano())] = (*res)[j].NumCalls
|
||||
}
|
||||
|
||||
for i, _ := range *resTotal {
|
||||
timeObj, _ := time.Parse(time.RFC3339Nano, (*resTotal)[i].Time)
|
||||
(*resTotal)[i].Timestamp = int64(timeObj.UnixNano())
|
||||
(*resTotal)[i].Time = ""
|
||||
(*resTotal)[i].CallRate = float32((*resTotal)[i].NumCalls) / float32(query.StepSeconds)
|
||||
|
||||
if val, ok := m[(*resTotal)[i].Timestamp]; ok {
|
||||
(*resTotal)[i].NumErrors = val
|
||||
(*resTotal)[i].ErrorRate = float32((*resTotal)[i].NumErrors) * 100 / float32((*resTotal)[i].NumCalls)
|
||||
}
|
||||
(*resTotal)[i].CallRate = 0
|
||||
(*resTotal)[i].NumCalls = 0
|
||||
|
||||
}
|
||||
|
||||
servicesExternalResponse := (*res)[1:]
|
||||
servicesExternalResponse := (*resTotal)[1:]
|
||||
return &servicesExternalResponse, nil
|
||||
}
|
||||
|
||||
@ -438,7 +476,7 @@ func GetServiceOverview(client *SqlClient, query *model.GetServiceOverviewParams
|
||||
if val, ok := m[(*res)[i].Timestamp]; ok {
|
||||
(*res)[i].NumErrors = val
|
||||
}
|
||||
(*res)[i].ErrorRate = float32((*res)[i].NumErrors) / float32((*res)[i].NumCalls)
|
||||
(*res)[i].ErrorRate = float32((*res)[i].NumErrors) * 100 / float32((*res)[i].NumCalls)
|
||||
(*res)[i].CallRate = float32((*res)[i].NumCalls) / float32(query.StepSeconds)
|
||||
|
||||
}
|
||||
@ -501,7 +539,7 @@ func GetServices(client *SqlClient, query *model.GetServicesParams) (*[]ServiceI
|
||||
(*res)[i].NumErrors = val
|
||||
}
|
||||
|
||||
(*res)[i].ErrorRate = float32((*res)[i].NumErrors) / float32((*res)[i].NumCalls)
|
||||
(*res)[i].ErrorRate = float32((*res)[i].NumErrors) * 100 / float32((*res)[i].NumCalls)
|
||||
(*res)[i].CallRate = float32((*res)[i].NumCalls) / float32(query.Period)
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user