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.

fix: part of #1353, move db calls to prepared statement for checkttlstatusItem (#3976)

Srikanth Iyengar36aced6d1ad3
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go
index 8816179da2..8b42c9265a 100644
--- a/pkg/query-service/app/clickhouseReader/reader.go
+++ b/pkg/query-service/app/clickhouseReader/reader.go
@@ -2456,11 +2456,18 @@ func (r *ClickHouseReader) deleteTtlTransactions(ctx context.Context, numberOfTr
func (r *ClickHouseReader) checkTTLStatusItem(ctx context.Context, tableName string) (model.TTLStatusItem, *model.ApiError) {
statusItem := []model.TTLStatusItem{}
- query := fmt.Sprintf("SELECT id, status, ttl, cold_storage_ttl FROM ttl_status WHERE table_name = '%s' ORDER BY created_at DESC", tableName)
+ query := `SELECT id, status, ttl, cold_storage_ttl FROM ttl_status WHERE table_name = ? ORDER BY created_at DESC`
- err := r.localDB.Select(&statusItem, query)
+ zap.S().Info(query, tableName)
- zap.S().Info(query)
+ stmt, err := r.localDB.Preparex(query)
+
+ if err != nil {
+ zap.S().Debug("Error preparing query for checkTTLStatusItem: ", err)
+ return model.TTLStatusItem{}, &model.ApiError{Typ: model.ErrorInternal, Err: err}
+ }
+
+ err = stmt.Select(&statusItem, tableName)
if len(statusItem) == 0 {
return model.TTLStatusItem{}, nil