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.

Used Prepared Statements for GetChannel in clickhousereader (#1414)

jshiwame39d2f799d14
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go
index 6716373c8b..a1f86c7413 100644
--- a/pkg/query-service/app/clickhouseReader/reader.go
+++ b/pkg/query-service/app/clickhouseReader/reader.go
@@ -374,14 +374,21 @@ func (r *ClickHouseReader) GetChannel(id string) (*model.ChannelItem, *model.Api
idInt, _ := strconv.Atoi(id)
channel := model.ChannelItem{}
- query := fmt.Sprintf("SELECT id, created_at, updated_at, name, type, data data FROM notification_channels WHERE id=%d", idInt)
+ query := "SELECT id, created_at, updated_at, name, type, data data FROM notification_channels WHERE id=? "
- err := r.localDB.Get(&channel, query)
+ stmt, err := r.localDB.Preparex(query)
- zap.S().Info(query)
+ zap.S().Info(query, idInt)
if err != nil {
- zap.S().Debug("Error in processing sql query: ", err)
+ zap.S().Debug("Error in preparing sql query for GetChannel : ", err)
+ return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
+ }
+
+ err = stmt.Get(&channel, idInt)
+
+ if err != nil {
+ zap.S().Debug(fmt.Sprintf("Error in getting channel with id=%d : ", idInt), err)
return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err}
}