Merge branch 'MSP-1777' into 'master'
MSP-1777 [+] новый параметр в remote_config: logging.skip. Массив re. Если они... Closes MSP-1777 See merge request integration-system/isp-gate-service!14
This commit is contained in:
commit
0d430df928
8 files changed
+45
-25
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v4.2.0
|
||||
* новый параметр в remote_config: `skipBodyLoggingEndpointPrefixes`. Массив re. Если они есть в пути, то запрос не будет логироваться
|
||||
### v4.1.2
|
||||
* исправлена опция логирования тела запроса (при настройке ws могла отключаться)
|
||||
### v4.1.1
|
||||
|
||||
+4
-2
@@ -87,7 +87,8 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
handler := middleware.Chain(
|
||||
proxyFunc,
|
||||
middleware.RequestId(),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog,
|
||||
config.Logging.SkipBodyLoggingEndpointPrefixes),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
middleware.Authenticate(authentication),
|
||||
middleware.AdminAuthenticate(adminService),
|
||||
@@ -100,7 +101,8 @@ func (l Locator) Handler(config conf.Remote, locations []conf.Location, redisCli
|
||||
handler = middleware.Chain(
|
||||
proxyFunc,
|
||||
middleware.RequestId(),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog),
|
||||
middleware.Logger(l.logger, config.Logging.RequestLogEnable, enableBodyLog,
|
||||
config.Logging.SkipBodyLoggingEndpointPrefixes),
|
||||
middleware.ErrorHandler(l.logger),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
{
|
||||
"logging": {
|
||||
"logLevel": "debug",
|
||||
"requestLogEnable": true,
|
||||
"bodyLogEnable": false
|
||||
},
|
||||
"caching": {
|
||||
"authenticationDataInSec": 60,
|
||||
"authorizationDataInSec": 60
|
||||
},
|
||||
"http": {
|
||||
"maxRequestBodySizeInMb": 64,
|
||||
"proxyTimeoutInSec": 60
|
||||
}
|
||||
"logging": {
|
||||
"logLevel": "debug",
|
||||
"requestLogEnable": true,
|
||||
"bodyLogEnable": false,
|
||||
"skipBodyLoggingEndpointPrefixes": []
|
||||
},
|
||||
"caching": {
|
||||
"authenticationDataInSec": 60,
|
||||
"authorizationDataInSec": 60
|
||||
},
|
||||
"http": {
|
||||
"maxRequestBodySizeInMb": 64,
|
||||
"proxyTimeoutInSec": 60
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -31,9 +31,10 @@ type Http struct {
|
||||
}
|
||||
|
||||
type Logging struct {
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования,логирование запросов осуществляется на уровне debug"`
|
||||
RequestLogEnable bool `schema:"Включить логирование запросов"`
|
||||
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования,логирование запросов осуществляется на уровне debug"`
|
||||
RequestLogEnable bool `schema:"Включить логирование запросов"`
|
||||
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
||||
SkipBodyLoggingEndpointPrefixes []string `schema:"регулярные выражения для отключения логирования"`
|
||||
}
|
||||
|
||||
type Caching struct {
|
||||
|
||||
@@ -5,6 +5,7 @@ go 1.19
|
||||
require (
|
||||
github.com/go-redis/redis_rate/v10 v10.0.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/integration-system/isp-etp-go/v2 v2.1.3
|
||||
github.com/integration-system/isp-kit v1.17.0
|
||||
@@ -27,7 +28,6 @@ require (
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
|
||||
+13
-1
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/integration-system/isp-kit/http/endpoint/buffer"
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
@@ -42,7 +43,7 @@ func (w *writerWrapper) WriteHeader(statusCode int) {
|
||||
w.ResponseWriter.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
func Logger(logger log.Logger, enableRequestLogging bool, enableBodyLogging bool) Middleware {
|
||||
func Logger(logger log.Logger, enableRequestLogging bool, enableBodyLogging bool, skip []string) Middleware {
|
||||
return func(next Handler) Handler {
|
||||
return HandlerFunc(func(ctx *request.Context) error {
|
||||
if !enableRequestLogging {
|
||||
@@ -50,6 +51,7 @@ func Logger(logger log.Logger, enableRequestLogging bool, enableBodyLogging bool
|
||||
}
|
||||
|
||||
r := ctx.Request()
|
||||
|
||||
var scSrc scSource
|
||||
var buf *buffer.Buffer
|
||||
if enableBodyLogging {
|
||||
@@ -89,6 +91,16 @@ func Logger(logger log.Logger, enableRequestLogging bool, enableBodyLogging bool
|
||||
log.Int("application_id", authData.ApplicationId),
|
||||
log.Int("admin_id", ctx.AdminId()),
|
||||
}
|
||||
|
||||
if enableBodyLogging {
|
||||
for _, sskip := range skip {
|
||||
if strings.HasPrefix(ctx.Endpoint(), sskip) {
|
||||
enableBodyLogging = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if enableBodyLogging {
|
||||
fields = append(fields,
|
||||
log.ByteString("request", buf.RequestBody()),
|
||||
|
||||
@@ -138,7 +138,7 @@ func (s *HappyPathTestSuite) TestHttpProxy() {
|
||||
require.EqualValues(req.Id, resp.Id)
|
||||
}
|
||||
|
||||
func (s *HappyPathTestSuite) TestWsProxy() {
|
||||
func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
|
||||
test, require := test.New(s.T())
|
||||
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
|
||||
|
||||
@@ -179,6 +179,7 @@ func (s *HappyPathTestSuite) TestWsProxy() {
|
||||
"x-request-id": {requestId},
|
||||
},
|
||||
})
|
||||
|
||||
requestUrl, err := url.Parse(srv.URL)
|
||||
require.NoError(err)
|
||||
requestUrl.Path = "ws/service"
|
||||
@@ -214,9 +215,10 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, r
|
||||
})
|
||||
|
||||
config := conf.Remote{
|
||||
Redis: &conf.Redis{Address: redisCli.address},
|
||||
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
||||
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true},
|
||||
Redis: &conf.Redis{Address: redisCli.address},
|
||||
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
||||
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true,
|
||||
SkipBodyLoggingEndpointPrefixes: []string{"endpoint"}},
|
||||
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
|
||||
DailyLimits: []conf.DailyLimit{{ApplicationId: 1, RequestsPerDay: 100}},
|
||||
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 100}},
|
||||
|
||||
Reference in new issue
Block a user