From fd89e94bdd0af7b2458c50129c844c968018314f Mon Sep 17 00:00:00 2001 From: Sergey Lazarenko Date: Mon, 30 Mar 2026 10:51:42 +0300 Subject: [PATCH 1/4] query in logs --- internal/app/mw/log.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/app/mw/log.go b/internal/app/mw/log.go index 6c2500b..478a358 100644 --- a/internal/app/mw/log.go +++ b/internal/app/mw/log.go @@ -2,6 +2,7 @@ package mw import ( "context" + "encoding/json" "strings" "time" @@ -72,6 +73,14 @@ func logRequestBeforeHandler(ctx context.Context, logger *tracing.Logger, args r zap.String("full_method", args.fullMethod), zap.String("body", args.requestBody), } + if args.requestBody != "" { + var requestData map[string]any + if err := json.Unmarshal([]byte(args.requestBody), &requestData); err == nil { + if q, ok := requestData["query"].(string); ok && q != "" { + logArgs = append(logArgs, zap.String("query", q)) + } + } + } if args.user != "" { logArgs = append(logArgs, zap.String("user", args.user)) } From 2e3c3e725b88c7f4e06a582b169e64c17a71f5e8 Mon Sep 17 00:00:00 2001 From: Sergey Lazarenko Date: Mon, 30 Mar 2026 13:37:47 +0300 Subject: [PATCH 2/4] correct sort envs --- internal/api/seqapi/v1/grpc/api.go | 31 +++++++++- internal/api/seqapi/v1/grpc/get_envs_test.go | 51 ++++++++++++++++ internal/api/seqapi/v1/http/api.go | 31 +++++++++- internal/api/seqapi/v1/http/get_envs_test.go | 62 ++++++++++++++++++-- 4 files changed, 169 insertions(+), 6 deletions(-) diff --git a/internal/api/seqapi/v1/grpc/api.go b/internal/api/seqapi/v1/grpc/api.go index 3fe29db..9760bb4 100644 --- a/internal/api/seqapi/v1/grpc/api.go +++ b/internal/api/seqapi/v1/grpc/api.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sort" + "strconv" "time" "go.uber.org/zap" @@ -139,7 +140,35 @@ func parseEnvs(cfg config.SeqAPI) *seqapi.GetEnvsResponse { for name := range cfg.Envs { names = append(names, name) } - sort.Strings(names) + sort.Slice(names, func(i, j int) bool { + a, b := names[i], names[j] + + var aPrefix, bPrefix string + var aNum, bNum int + + k := 0 + for k < len(a) && (a[k] < '0' || a[k] > '9') { + k++ + } + aPrefix = a[:k] + if k < len(a) { + aNum, _ = strconv.Atoi(a[k:]) + } + + k = 0 + for k < len(b) && (b[k] < '0' || b[k] > '9') { + k++ + } + bPrefix = b[:k] + if k < len(b) { + bNum, _ = strconv.Atoi(b[k:]) + } + + if aPrefix != bPrefix { + return aPrefix < bPrefix + } + return aNum < bNum + }) envs = make([]*seqapi.GetEnvsResponse_Env, 0, len(cfg.Envs)) for _, name := range names { diff --git a/internal/api/seqapi/v1/grpc/get_envs_test.go b/internal/api/seqapi/v1/grpc/get_envs_test.go index 3f38625..d3b3e78 100644 --- a/internal/api/seqapi/v1/grpc/get_envs_test.go +++ b/internal/api/seqapi/v1/grpc/get_envs_test.go @@ -62,6 +62,33 @@ func TestGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 15000, }, }, + "z22": { + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 150, + MaxExportLimit: 250, + MaxParallelExportRequests: 3, + MaxAggregationsPerRequest: 6, + SeqCLIMaxSearchLimit: 15000, + }, + }, + "z132": { + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 100, + MaxExportLimit: 200, + MaxParallelExportRequests: 2, + MaxAggregationsPerRequest: 5, + SeqCLIMaxSearchLimit: 10000, + }, + }, + "z221": { + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 100, + MaxExportLimit: 200, + MaxParallelExportRequests: 2, + MaxAggregationsPerRequest: 5, + SeqCLIMaxSearchLimit: 10000, + }, + }, }, DefaultEnv: "test", }, @@ -83,6 +110,30 @@ func TestGetEnvs(t *testing.T) { MaxAggregationsPerRequest: 5, SeqCliMaxSearchLimit: 10000, }, + { + Env: "z22", + MaxSearchLimit: 150, + MaxExportLimit: 250, + MaxParallelExportRequests: 3, + MaxAggregationsPerRequest: 6, + SeqCliMaxSearchLimit: 15000, + }, + { + Env: "z132", + MaxSearchLimit: 100, + MaxExportLimit: 200, + MaxParallelExportRequests: 2, + MaxAggregationsPerRequest: 5, + SeqCliMaxSearchLimit: 10000, + }, + { + Env: "z221", + MaxSearchLimit: 100, + MaxExportLimit: 200, + MaxParallelExportRequests: 2, + MaxAggregationsPerRequest: 5, + SeqCliMaxSearchLimit: 10000, + }, }, }, }, diff --git a/internal/api/seqapi/v1/http/api.go b/internal/api/seqapi/v1/http/api.go index f8382a6..16c603e 100644 --- a/internal/api/seqapi/v1/http/api.go +++ b/internal/api/seqapi/v1/http/api.go @@ -3,6 +3,7 @@ package http import ( "fmt" "sort" + "strconv" "time" "github.com/go-chi/chi/v5" @@ -181,7 +182,35 @@ func parseEnvs(cfg config.SeqAPI) getEnvsResponse { for name := range cfg.Envs { names = append(names, name) } - sort.Strings(names) + sort.Slice(names, func(i, j int) bool { + a, b := names[i], names[j] + + var aPrefix, bPrefix string + var aNum, bNum int + + k := 0 + for k < len(a) && (a[k] < '0' || a[k] > '9') { + k++ + } + aPrefix = a[:k] + if k < len(a) { + aNum, _ = strconv.Atoi(a[k:]) + } + + k = 0 + for k < len(b) && (b[k] < '0' || b[k] > '9') { + k++ + } + bPrefix = b[:k] + if k < len(b) { + bNum, _ = strconv.Atoi(b[k:]) + } + + if aPrefix != bPrefix { + return aPrefix < bPrefix + } + return aNum < bNum + }) envs = make([]envInfo, 0, len(cfg.Envs)) for _, name := range names { diff --git a/internal/api/seqapi/v1/http/get_envs_test.go b/internal/api/seqapi/v1/http/get_envs_test.go index 8097e93..dd9444c 100644 --- a/internal/api/seqapi/v1/http/get_envs_test.go +++ b/internal/api/seqapi/v1/http/get_envs_test.go @@ -44,7 +44,17 @@ func TestServeGetEnvs(t *testing.T) { cfg: config.SeqAPI{ SeqAPIOptions: &config.SeqAPIOptions{}, Envs: map[string]config.SeqAPIEnv{ - "prod": { + "z221": { + SeqDB: "pro-seqdb", + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 1000, + MaxExportLimit: 500, + MaxParallelExportRequests: 10, + MaxAggregationsPerRequest: 5, + SeqCLIMaxSearchLimit: 2000, + }, + }, + "z22": { SeqDB: "prod-seqdb", Options: &config.SeqAPIOptions{ MaxSearchLimit: 1000, @@ -54,7 +64,7 @@ func TestServeGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 2000, }, }, - "staging": { + "z132": { SeqDB: "staging-seqdb", Options: &config.SeqAPIOptions{ MaxSearchLimit: 500, @@ -64,12 +74,48 @@ func TestServeGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 1000, }, }, + "prod": { + SeqDB: "stag-seqdb", + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 500, + MaxExportLimit: 250, + MaxParallelExportRequests: 5, + MaxAggregationsPerRequest: 3, + SeqCLIMaxSearchLimit: 1000, + }, + }, + "wyanki": { + SeqDB: "sta-seqdb", + Options: &config.SeqAPIOptions{ + MaxSearchLimit: 500, + MaxExportLimit: 250, + MaxParallelExportRequests: 5, + MaxAggregationsPerRequest: 3, + SeqCLIMaxSearchLimit: 1000, + }, + }, }, - DefaultEnv: "prod", + DefaultEnv: "z22", }, wantEnvs: []envInfo{ { Env: "prod", + MaxSearchLimit: 500, + MaxExportLimit: 250, + MaxParallelExportRequests: 5, + MaxAggregationsPerRequest: 3, + SeqCliMaxSearchLimit: 1000, + }, + { + Env: "wyanki", + MaxSearchLimit: 500, + MaxExportLimit: 250, + MaxParallelExportRequests: 5, + MaxAggregationsPerRequest: 3, + SeqCliMaxSearchLimit: 1000, + }, + { + Env: "z22", MaxSearchLimit: 1000, MaxExportLimit: 500, MaxParallelExportRequests: 10, @@ -77,13 +123,21 @@ func TestServeGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 2000, }, { - Env: "staging", + Env: "z132", MaxSearchLimit: 500, MaxExportLimit: 250, MaxParallelExportRequests: 5, MaxAggregationsPerRequest: 3, SeqCliMaxSearchLimit: 1000, }, + { + Env: "z221", + MaxSearchLimit: 1000, + MaxExportLimit: 500, + MaxParallelExportRequests: 10, + MaxAggregationsPerRequest: 5, + SeqCliMaxSearchLimit: 2000, + }, }, }, } From 78bd22a6c54bae473e2d604b10049fd5cafffa8d Mon Sep 17 00:00:00 2001 From: Sergey Lazarenko Date: Mon, 30 Mar 2026 13:53:54 +0300 Subject: [PATCH 3/4] remove query in logs --- internal/app/mw/log.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/internal/app/mw/log.go b/internal/app/mw/log.go index 478a358..6c2500b 100644 --- a/internal/app/mw/log.go +++ b/internal/app/mw/log.go @@ -2,7 +2,6 @@ package mw import ( "context" - "encoding/json" "strings" "time" @@ -73,14 +72,6 @@ func logRequestBeforeHandler(ctx context.Context, logger *tracing.Logger, args r zap.String("full_method", args.fullMethod), zap.String("body", args.requestBody), } - if args.requestBody != "" { - var requestData map[string]any - if err := json.Unmarshal([]byte(args.requestBody), &requestData); err == nil { - if q, ok := requestData["query"].(string); ok && q != "" { - logArgs = append(logArgs, zap.String("query", q)) - } - } - } if args.user != "" { logArgs = append(logArgs, zap.String("user", args.user)) } From eb30198c48c6604edffb03b6fbc7a2db3e3b6f56 Mon Sep 17 00:00:00 2001 From: Sergey Lazarenko Date: Mon, 30 Mar 2026 14:20:49 +0300 Subject: [PATCH 4/4] fix --- internal/api/seqapi/v1/grpc/get_envs_test.go | 30 ++++++++-------- internal/api/seqapi/v1/http/get_envs_test.go | 38 ++++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/internal/api/seqapi/v1/grpc/get_envs_test.go b/internal/api/seqapi/v1/grpc/get_envs_test.go index d3b3e78..5dbbd8e 100644 --- a/internal/api/seqapi/v1/grpc/get_envs_test.go +++ b/internal/api/seqapi/v1/grpc/get_envs_test.go @@ -62,7 +62,7 @@ func TestGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 15000, }, }, - "z22": { + "cluster-10": { Options: &config.SeqAPIOptions{ MaxSearchLimit: 150, MaxExportLimit: 250, @@ -71,7 +71,7 @@ func TestGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 15000, }, }, - "z132": { + "cluster-102": { Options: &config.SeqAPIOptions{ MaxSearchLimit: 100, MaxExportLimit: 200, @@ -80,7 +80,7 @@ func TestGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 10000, }, }, - "z221": { + "cluster-220": { Options: &config.SeqAPIOptions{ MaxSearchLimit: 100, MaxExportLimit: 200, @@ -95,7 +95,7 @@ func TestGetEnvs(t *testing.T) { want: &seqapi.GetEnvsResponse{ Envs: []*seqapi.GetEnvsResponse_Env{ { - Env: "prod", + Env: "cluster-10", MaxSearchLimit: 150, MaxExportLimit: 250, MaxParallelExportRequests: 3, @@ -103,7 +103,7 @@ func TestGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 15000, }, { - Env: "test", + Env: "cluster-102", MaxSearchLimit: 100, MaxExportLimit: 200, MaxParallelExportRequests: 2, @@ -111,15 +111,7 @@ func TestGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 10000, }, { - Env: "z22", - MaxSearchLimit: 150, - MaxExportLimit: 250, - MaxParallelExportRequests: 3, - MaxAggregationsPerRequest: 6, - SeqCliMaxSearchLimit: 15000, - }, - { - Env: "z132", + Env: "cluster-220", MaxSearchLimit: 100, MaxExportLimit: 200, MaxParallelExportRequests: 2, @@ -127,7 +119,15 @@ func TestGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 10000, }, { - Env: "z221", + Env: "prod", + MaxSearchLimit: 150, + MaxExportLimit: 250, + MaxParallelExportRequests: 3, + MaxAggregationsPerRequest: 6, + SeqCliMaxSearchLimit: 15000, + }, + { + Env: "test", MaxSearchLimit: 100, MaxExportLimit: 200, MaxParallelExportRequests: 2, diff --git a/internal/api/seqapi/v1/http/get_envs_test.go b/internal/api/seqapi/v1/http/get_envs_test.go index dd9444c..6916208 100644 --- a/internal/api/seqapi/v1/http/get_envs_test.go +++ b/internal/api/seqapi/v1/http/get_envs_test.go @@ -44,7 +44,7 @@ func TestServeGetEnvs(t *testing.T) { cfg: config.SeqAPI{ SeqAPIOptions: &config.SeqAPIOptions{}, Envs: map[string]config.SeqAPIEnv{ - "z221": { + "cluster-220": { SeqDB: "pro-seqdb", Options: &config.SeqAPIOptions{ MaxSearchLimit: 1000, @@ -54,7 +54,7 @@ func TestServeGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 2000, }, }, - "z22": { + "cluster-10": { SeqDB: "prod-seqdb", Options: &config.SeqAPIOptions{ MaxSearchLimit: 1000, @@ -64,7 +64,7 @@ func TestServeGetEnvs(t *testing.T) { SeqCLIMaxSearchLimit: 2000, }, }, - "z132": { + "cluster-102": { SeqDB: "staging-seqdb", Options: &config.SeqAPIOptions{ MaxSearchLimit: 500, @@ -95,19 +95,19 @@ func TestServeGetEnvs(t *testing.T) { }, }, }, - DefaultEnv: "z22", + DefaultEnv: "cluster-10", }, wantEnvs: []envInfo{ { - Env: "prod", - MaxSearchLimit: 500, - MaxExportLimit: 250, - MaxParallelExportRequests: 5, - MaxAggregationsPerRequest: 3, - SeqCliMaxSearchLimit: 1000, + Env: "cluster-10", + MaxSearchLimit: 1000, + MaxExportLimit: 500, + MaxParallelExportRequests: 10, + MaxAggregationsPerRequest: 5, + SeqCliMaxSearchLimit: 2000, }, { - Env: "wyanki", + Env: "cluster-102", MaxSearchLimit: 500, MaxExportLimit: 250, MaxParallelExportRequests: 5, @@ -115,7 +115,7 @@ func TestServeGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 1000, }, { - Env: "z22", + Env: "cluster-220", MaxSearchLimit: 1000, MaxExportLimit: 500, MaxParallelExportRequests: 10, @@ -123,7 +123,7 @@ func TestServeGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 2000, }, { - Env: "z132", + Env: "prod", MaxSearchLimit: 500, MaxExportLimit: 250, MaxParallelExportRequests: 5, @@ -131,12 +131,12 @@ func TestServeGetEnvs(t *testing.T) { SeqCliMaxSearchLimit: 1000, }, { - Env: "z221", - MaxSearchLimit: 1000, - MaxExportLimit: 500, - MaxParallelExportRequests: 10, - MaxAggregationsPerRequest: 5, - SeqCliMaxSearchLimit: 2000, + Env: "wyanki", + MaxSearchLimit: 500, + MaxExportLimit: 250, + MaxParallelExportRequests: 5, + MaxAggregationsPerRequest: 3, + SeqCliMaxSearchLimit: 1000, }, }, },