mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 20:38:59 +08:00
fix: respect durationSort feature flag on getSpanFilters API (#1900)
* fix: respect durationSort feature flag on getSpanFilters API * chore: update DB query
This commit is contained in:
parent
40ec4517c2
commit
35f5fb6957
@ -1177,33 +1177,54 @@ func (r *ClickHouseReader) GetSpanFilters(ctx context.Context, queryParams *mode
|
|||||||
traceFilterReponse.Status = map[string]uint64{"ok": 0, "error": 0}
|
traceFilterReponse.Status = map[string]uint64{"ok": 0, "error": 0}
|
||||||
}
|
}
|
||||||
case constants.Duration:
|
case constants.Duration:
|
||||||
finalQuery := fmt.Sprintf("SELECT durationNano as numTotal FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.durationTable)
|
err := r.featureFlags.CheckFeature(constants.DurationSort)
|
||||||
finalQuery += query
|
durationSortEnabled := err == nil
|
||||||
finalQuery += " ORDER BY durationNano LIMIT 1"
|
finalQuery := ""
|
||||||
var dBResponse []model.DBResponseTotal
|
if !durationSortEnabled {
|
||||||
err := r.db.Select(ctx, &dBResponse, finalQuery, args...)
|
// if duration sort is not enabled, we need to get the min and max duration from the index table
|
||||||
zap.S().Info(finalQuery)
|
finalQuery = fmt.Sprintf("SELECT min(durationNano) as min, max(durationNano) as max FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.indexTable)
|
||||||
|
finalQuery += query
|
||||||
|
var dBResponse []model.DBResponseMinMax
|
||||||
|
err = r.db.Select(ctx, &dBResponse, finalQuery, args...)
|
||||||
|
zap.S().Info(finalQuery)
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Debug("Error in processing sql query: ", err)
|
||||||
|
return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query: %s", err)}
|
||||||
|
}
|
||||||
|
if len(dBResponse) > 0 {
|
||||||
|
traceFilterReponse.Duration = map[string]uint64{"minDuration": dBResponse[0].Min, "maxDuration": dBResponse[0].Max}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// when duration sort is enabled, we need to get the min and max duration from the duration table
|
||||||
|
finalQuery = fmt.Sprintf("SELECT durationNano as numTotal FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.durationTable)
|
||||||
|
finalQuery += query
|
||||||
|
finalQuery += " ORDER BY durationNano LIMIT 1"
|
||||||
|
var dBResponse []model.DBResponseTotal
|
||||||
|
err = r.db.Select(ctx, &dBResponse, finalQuery, args...)
|
||||||
|
zap.S().Info(finalQuery)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Debug("Error in processing sql query: ", err)
|
zap.S().Debug("Error in processing sql query: ", err)
|
||||||
return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query: %s", err)}
|
return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query: %s", err)}
|
||||||
}
|
}
|
||||||
finalQuery = fmt.Sprintf("SELECT durationNano as numTotal FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.durationTable)
|
|
||||||
finalQuery += query
|
|
||||||
finalQuery += " ORDER BY durationNano DESC LIMIT 1"
|
|
||||||
var dBResponse2 []model.DBResponseTotal
|
|
||||||
err = r.db.Select(ctx, &dBResponse2, finalQuery, args...)
|
|
||||||
zap.S().Info(finalQuery)
|
|
||||||
|
|
||||||
if err != nil {
|
finalQuery = fmt.Sprintf("SELECT durationNano as numTotal FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.durationTable)
|
||||||
zap.S().Debug("Error in processing sql query: ", err)
|
finalQuery += query
|
||||||
return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query: %s", err)}
|
finalQuery += " ORDER BY durationNano DESC LIMIT 1"
|
||||||
}
|
var dBResponse2 []model.DBResponseTotal
|
||||||
if len(dBResponse) > 0 {
|
err = r.db.Select(ctx, &dBResponse2, finalQuery, args...)
|
||||||
traceFilterReponse.Duration["minDuration"] = dBResponse[0].NumTotal
|
zap.S().Info(finalQuery)
|
||||||
}
|
|
||||||
if len(dBResponse2) > 0 {
|
if err != nil {
|
||||||
traceFilterReponse.Duration["maxDuration"] = dBResponse2[0].NumTotal
|
zap.S().Debug("Error in processing sql query: ", err)
|
||||||
|
return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query: %s", err)}
|
||||||
|
}
|
||||||
|
if len(dBResponse) > 0 {
|
||||||
|
traceFilterReponse.Duration["minDuration"] = dBResponse[0].NumTotal
|
||||||
|
}
|
||||||
|
if len(dBResponse2) > 0 {
|
||||||
|
traceFilterReponse.Duration["maxDuration"] = dBResponse2[0].NumTotal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case constants.RPCMethod:
|
case constants.RPCMethod:
|
||||||
finalQuery := fmt.Sprintf("SELECT rpcMethod, count() as count FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.indexTable)
|
finalQuery := fmt.Sprintf("SELECT rpcMethod, count() as count FROM %s.%s WHERE timestamp >= @timestampL AND timestamp <= @timestampU", r.TraceDB, r.indexTable)
|
||||||
|
@ -399,6 +399,11 @@ type DBResponseTotal struct {
|
|||||||
NumTotal uint64 `ch:"numTotal"`
|
NumTotal uint64 `ch:"numTotal"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DBResponseMinMax struct {
|
||||||
|
Min uint64 `ch:"min"`
|
||||||
|
Max uint64 `ch:"max"`
|
||||||
|
}
|
||||||
|
|
||||||
type SpanFiltersResponse struct {
|
type SpanFiltersResponse struct {
|
||||||
ServiceName map[string]uint64 `json:"serviceName"`
|
ServiceName map[string]uint64 `json:"serviceName"`
|
||||||
Status map[string]uint64 `json:"status"`
|
Status map[string]uint64 `json:"status"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user