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.

logs select statement converted to a const

nityanandagohain373cbbc3758e
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go
index 4428ed38cf..368ecf7944 100644
--- a/pkg/query-service/app/clickhouseReader/reader.go
+++ b/pkg/query-service/app/clickhouseReader/reader.go
@@ -2861,13 +2861,7 @@ func (r *ClickHouseReader) GetLogs(ctx context.Context, params *model.LogsFilter
return nil, &model.ApiError{Err: err, Typ: model.ErrorBadData}
}
- query := fmt.Sprintf("SELECT "+
- "timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, body,"+
- "CAST((attributes_string_key, attributes_string_value), 'Map(String, String)') as attributes_string,"+
- "CAST((attributes_int64_key, attributes_int64_value), 'Map(String, Int64)') as attributes_int64,"+
- "CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64,"+
- "CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string "+
- "from %s.%s", r.logsDB, r.logsTable)
+ query := fmt.Sprintf("%s from %s.%s", constants.LogsSQLSelect, r.logsDB, r.logsTable)
if filterSql != "" {
query += fmt.Sprintf(" where %s", filterSql)
@@ -2900,13 +2894,7 @@ func (r *ClickHouseReader) TailLogs(ctx context.Context, client *model.LogsTailC
return
}
- query := fmt.Sprintf("SELECT "+
- "timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, body,"+
- "CAST((attributes_string_key, attributes_string_value), 'Map(String, String)') as attributes_string,"+
- "CAST((attributes_int64_key, attributes_int64_value), 'Map(String, Int64)') as attributes_int64,"+
- "CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64,"+
- "CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string "+
- "from %s.%s", r.logsDB, r.logsTable)
+ query := fmt.Sprintf("%s from %s.%s", constants.LogsSQLSelect, r.logsDB, r.logsTable)
tsStart := uint64(time.Now().UnixNano())
if client.Filter.TimestampStart != nil {
@@ -2958,10 +2946,7 @@ func (r *ClickHouseReader) TailLogs(ctx context.Context, client *model.LogsTailC
}
}
}
- if len == 0 {
- tsStart = uint64(time.Now().UnixNano())
- }
- time.Sleep(2 * time.Second)
+ time.Sleep(10 * time.Second)
}
}
}
diff --git a/pkg/query-service/constants/constants.go b/pkg/query-service/constants/constants.go
index e5e727de0b..af96d2571f 100644
--- a/pkg/query-service/constants/constants.go
+++ b/pkg/query-service/constants/constants.go
@@ -139,3 +139,12 @@ var StaticSelectedLogFields = []model.LogField{
Type: Static,
},
}
+
+const (
+ LogsSQLSelect = "SELECT " +
+ "timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, body," +
+ "CAST((attributes_string_key, attributes_string_value), 'Map(String, String)') as attributes_string," +
+ "CAST((attributes_int64_key, attributes_int64_value), 'Map(String, Int64)') as attributes_int64," +
+ "CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64," +
+ "CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string "
+)