From 01b6263f29c62fd4d536e516db79b525ccfa6676 Mon Sep 17 00:00:00 2001 From: nglmq Date: Tue, 17 Feb 2026 14:49:36 +0300 Subject: [PATCH 1/3] MSP-7199 replace RequestId middleware --- .gitignore | 2 ++ assembly/locator.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 73fbb5a..03f5a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,5 @@ package.json yarn.lock conf/config_dev.yml + +.DS_Store \ No newline at end of file diff --git a/assembly/locator.go b/assembly/locator.go index 7dc10a0..8a540af 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -110,11 +110,11 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha middleware.ErrorHandler(l.logger), middleware.Authenticate(authentication), middleware.AdminAuthenticate(adminService), + middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), middleware.Authorize(authorization, l.logger), middleware.AdminAuthorize(adminService), middleware.Throttling(throttlingService), middleware.DailyLimit(dailyLimitService), - middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), middleware.Metrics(metricsStorage), ) diff --git a/go.mod b/go.mod index 2832a16..80e4303 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/redis/go-redis/v9 v9.11.0 github.com/stretchr/testify v1.11.1 github.com/tomakado/websocketproxy v0.1.0 - github.com/txix-open/isp-kit v1.64.8 + github.com/txix-open/isp-kit v1.64.10 github.com/txix-open/jsonschema v1.3.0 golang.org/x/net v0.47.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 diff --git a/go.sum b/go.sum index 5ac9063..250d3ab 100644 --- a/go.sum +++ b/go.sum @@ -125,8 +125,8 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8= github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM= github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po= -github.com/txix-open/isp-kit v1.64.8 h1:nck8Gw5a7Jh6AVLqR2FihurrP5bTfeLUrodYB4j4+p4= -github.com/txix-open/isp-kit v1.64.8/go.mod h1:GvBsX5p2U3/ugK6PuWANYzSy/4YgawROm3eAKb35G6o= +github.com/txix-open/isp-kit v1.64.10 h1:lAowLtShBbICZbOWQJ4ptr9LaKKRZ7CE5DBK+7LcLqM= +github.com/txix-open/isp-kit v1.64.10/go.mod h1:GvBsX5p2U3/ugK6PuWANYzSy/4YgawROm3eAKb35G6o= github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4= github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00= github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0= From c0bb6fdc7e14f41be5ef61ac0b2633915c0fba1b Mon Sep 17 00:00:00 2001 From: nglmq Date: Tue, 17 Feb 2026 17:37:53 +0300 Subject: [PATCH 2/3] MSP-7199 edit requestId middleware --- assembly/locator.go | 6 ++++-- middleware/request_id.go | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/assembly/locator.go b/assembly/locator.go index 8a540af..1f2ba4f 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -107,10 +107,11 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha config.Logging.SkipBodyLoggingEndpointPrefixes, config.Logging.EnableForceUnescapingUnicode, ), + middleware.RequestId(), middleware.ErrorHandler(l.logger), middleware.Authenticate(authentication), middleware.AdminAuthenticate(adminService), - middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), + middleware.ClientRequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), middleware.Authorize(authorization, l.logger), middleware.AdminAuthorize(adminService), middleware.Throttling(throttlingService), @@ -128,8 +129,9 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Ha config.Logging.SkipBodyLoggingEndpointPrefixes, config.Logging.EnableForceUnescapingUnicode, ), + middleware.RequestId(), middleware.ErrorHandler(l.logger), - middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), + middleware.ClientRequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId), middleware.Metrics(metricsStorage), ) } diff --git a/middleware/request_id.go b/middleware/request_id.go index 7ba4ebd..548001d 100644 --- a/middleware/request_id.go +++ b/middleware/request_id.go @@ -13,10 +13,28 @@ const ( requestIdHeader = "x-request-id" ) -func RequestId(forwardClientRequestId bool, forwardReqIdByApp map[int]bool) Middleware { +func RequestId() Middleware { return func(next Handler) Handler { return HandlerFunc(func(ctx *request.Context) error { requestId := requestid.Next() + + context := requestid.ToContext(ctx.Context(), requestId) + context = log.ToContext(context, log.String("requestId", requestId)) + + ctx.SetContext(context) + return next.Handle(ctx) + }) + } +} + +func ClientRequestId(forwardClientRequestId bool, forwardReqIdByApp map[int]bool) Middleware { + return func(next Handler) Handler { + return HandlerFunc(func(ctx *request.Context) error { + requestId := requestid.FromContext(ctx.Context()) + if requestId == "" { + requestId = requestid.Next() + } + clientRequestId := strings.TrimSpace(ctx.Request().Header.Get(requestIdHeader)) logFields := make([]log.Field, 0) From c422de39b47f918eb8ae2a365410207c2f239ad5 Mon Sep 17 00:00:00 2001 From: nglmq Date: Wed, 18 Feb 2026 10:14:05 +0300 Subject: [PATCH 3/3] MSP-7199 bump version to 5.9.0 --- .version | 2 +- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 1802e77..b3d91f9 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -5.8.1 +5.9.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cbe889..9907cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v5.9.0 +* Исправлен порядок мидлварей, для корректного проброса `requestId` ### v5.8.1 * Обновлены зависимости ### v5.8.0