Commit ee69c3ae authored by Ankit Nayan's avatar Ankit Nayan
Browse files

Merge branch 'backend' into main

parents cd90ac8e a6b1c271
Showing with 46 additions and 8 deletions
+46 -8
......@@ -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")
}
servicesExternalResponse := (*res)[1:]
// 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 := (*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)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment