From 72ccac1aed5a0ef87ecdaa0b4c59499f32d21ad7 Mon Sep 17 00:00:00 2001 From: Alexander Zavorotynskiy Date: Tue, 9 May 2023 17:50:16 +0200 Subject: [PATCH] fix(backend): added COMPRESSION_THRESHOLD env variable to Dockerfile --- backend/Dockerfile | 4 +++- backend/internal/config/http/config.go | 31 +++++++++++++------------- backend/internal/http/router/router.go | 22 +++++++++--------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 68b11ab84..e45f5a194 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -87,7 +87,9 @@ ENV TZ=UTC \ MAX_FILE_SIZE=100000000 \ USE_ENCRYPTION=false \ # Use to enable cloud specific feature - CLOUD="aws" + CLOUD="aws" \ + # Use to set compression threshold for tracker requests (20kb by default) + COMPRESSION_THRESHOLD="20000" RUN if [ "$SERVICE_NAME" = "http" ]; then \ diff --git a/backend/internal/config/http/config.go b/backend/internal/config/http/config.go index a4af87bd3..c5c7d88ec 100644 --- a/backend/internal/config/http/config.go +++ b/backend/internal/config/http/config.go @@ -10,21 +10,22 @@ import ( type Config struct { common.Config common.Postgres - HTTPHost string `env:"HTTP_HOST,default="` - HTTPPort string `env:"HTTP_PORT,required"` - HTTPTimeout time.Duration `env:"HTTP_TIMEOUT,default=60s"` - TopicRawWeb string `env:"TOPIC_RAW_WEB,required"` - TopicRawIOS string `env:"TOPIC_RAW_IOS,required"` - BeaconSizeLimit int64 `env:"BEACON_SIZE_LIMIT,required"` - JsonSizeLimit int64 `env:"JSON_SIZE_LIMIT,default=1000"` - FileSizeLimit int64 `env:"FILE_SIZE_LIMIT,default=10000000"` - AWSRegion string `env:"AWS_REGION,required"` - S3BucketIOSImages string `env:"S3_BUCKET_IOS_IMAGES,required"` - TokenSecret string `env:"TOKEN_SECRET,required"` - UAParserFile string `env:"UAPARSER_FILE,required"` - MaxMinDBFile string `env:"MAXMINDDB_FILE,required"` - UseProfiler bool `env:"PROFILER_ENABLED,default=false"` - WorkerID uint16 + HTTPHost string `env:"HTTP_HOST,default="` + HTTPPort string `env:"HTTP_PORT,required"` + HTTPTimeout time.Duration `env:"HTTP_TIMEOUT,default=60s"` + TopicRawWeb string `env:"TOPIC_RAW_WEB,required"` + TopicRawIOS string `env:"TOPIC_RAW_IOS,required"` + BeaconSizeLimit int64 `env:"BEACON_SIZE_LIMIT,required"` + CompressionThreshold int64 `env:"COMPRESSION_THRESHOLD,default=20000"` + JsonSizeLimit int64 `env:"JSON_SIZE_LIMIT,default=1000"` + FileSizeLimit int64 `env:"FILE_SIZE_LIMIT,default=10000000"` + AWSRegion string `env:"AWS_REGION,required"` + S3BucketIOSImages string `env:"S3_BUCKET_IOS_IMAGES,required"` + TokenSecret string `env:"TOKEN_SECRET,required"` + UAParserFile string `env:"UAPARSER_FILE,required"` + MaxMinDBFile string `env:"MAXMINDDB_FILE,required"` + UseProfiler bool `env:"PROFILER_ENABLED,default=false"` + WorkerID uint16 } func New() *Config { diff --git a/backend/internal/http/router/router.go b/backend/internal/http/router/router.go index 30263dbcf..1d5468367 100644 --- a/backend/internal/http/router/router.go +++ b/backend/internal/http/router/router.go @@ -19,11 +19,12 @@ type BeaconSize struct { } type Router struct { - router *mux.Router - cfg *http3.Config - services *http2.ServicesBuilder - mutex *sync.RWMutex - beaconSizeCache map[uint64]*BeaconSize // Cache for session's beaconSize + router *mux.Router + cfg *http3.Config + services *http2.ServicesBuilder + mutex *sync.RWMutex + beaconSizeCache map[uint64]*BeaconSize // Cache for session's beaconSize + compressionThreshold int64 } func NewRouter(cfg *http3.Config, services *http2.ServicesBuilder) (*Router, error) { @@ -34,10 +35,11 @@ func NewRouter(cfg *http3.Config, services *http2.ServicesBuilder) (*Router, err return nil, fmt.Errorf("services is empty") } e := &Router{ - cfg: cfg, - services: services, - mutex: &sync.RWMutex{}, - beaconSizeCache: make(map[uint64]*BeaconSize), + cfg: cfg, + services: services, + mutex: &sync.RWMutex{}, + beaconSizeCache: make(map[uint64]*BeaconSize), + compressionThreshold: cfg.CompressionThreshold, } e.init() go e.clearBeaconSizes() @@ -67,7 +69,7 @@ func (e *Router) getBeaconSize(sessionID uint64) int64 { } func (e *Router) getCompressionThreshold() int64 { - return 20000 + return e.compressionThreshold } func (e *Router) clearBeaconSizes() {