Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

changed errors to percent in external calls

Ankit Nayana6b1c271eedd
diff --git a/pkg/query-service/druidQuery/mysql-query.go b/pkg/query-service/druidQuery/mysql-query.go
index 56d864daa0..584b43c579 100644
--- a/pkg/query-service/druidQuery/mysql-query.go
+++ b/pkg/query-service/druidQuery/mysql-query.go
@@ -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)
}