From 373cbbc3758e70dfc650257465a2fec0ca722272 Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Fri, 22 Jul 2022 16:07:19 +0530 Subject: [PATCH] logs select statement converted to a const --- .../app/clickhouseReader/reader.go | 21 +++---------------- pkg/query-service/constants/constants.go | 9 ++++++++ 2 files changed, 12 insertions(+), 18 deletions(-) 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 " +)