fix(backend): added COMPRESSION_THRESHOLD env variable to Dockerfile

This commit is contained in:
Alexander Zavorotynskiy 2023-05-09 17:50:16 +02:00
parent 2c6f9a15ab
commit 72ccac1aed
3 changed files with 31 additions and 26 deletions

View file

@ -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 \

View file

@ -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 {

View file

@ -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() {