diff --git a/pkg/config/common/common.go b/pkg/config/common/common.go index 2bbdc210c..4c10fd003 100644 --- a/pkg/config/common/common.go +++ b/pkg/config/common/common.go @@ -120,12 +120,14 @@ type Configuration struct { AgileAggsEnabledConverted bool DualCaseCheck string `yaml:"dualCaseCheck"` // This is to support the old data that does not have case-insensitive search support. TODO: Remove this after 2 months from now: Aug 21st, 2024. DualCaseCheckConverted bool - QueryHostname string `yaml:"queryHostname"` // hostname of the query server. i.e. if DNS is https://cloud.siglens.com, this should be cloud.siglens.com - IngestUrl string `yaml:"ingestUrl"` // full address of the ingest server, including scheme and port, e.g. https://ingest.siglens.com:8080 - S3 S3Config `yaml:"s3"` // s3 related config - Log LogConfig `yaml:"log"` // Log related config - TLS TLSConfig `yaml:"tls"` // TLS related config - Tracing TracingConfig `yaml:"tracing"` // Tracing related config + QueryHostname string `yaml:"queryHostname"` // hostname of the query server. i.e. if DNS is https://cloud.siglens.com, this should be cloud.siglens.com + IngestUrl string `yaml:"ingestUrl"` // full address of the ingest server, including scheme and port, e.g. https://ingest.siglens.com:8080 + S3 S3Config `yaml:"s3"` // s3 related config + Log LogConfig `yaml:"log"` // Log related config + TLS TLSConfig `yaml:"tls"` // TLS related config + CompressStatic string `yaml:"compressStatic"` // compress static files + CompressStaticConverted bool + Tracing TracingConfig `yaml:"tracing"` // Tracing related config EmailConfig EmailConfig `yaml:"emailConfig"` DatabaseConfig DatabaseConfig `yaml:"minionSearch"` } diff --git a/pkg/config/config.go b/pkg/config/config.go index 5ea34060c..bf22a8583 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -200,6 +200,10 @@ func GetTLSPrivateKeyPath() string { return runningConfig.TLS.PrivateKeyPath } +func ShouldCompressStaticFiles() bool { + return runningConfig.CompressStaticConverted +} + // used by func GetQueryHostname() string { return runningConfig.QueryHostname @@ -518,6 +522,8 @@ func GetTestConfig(dataPath string) common.Configuration { QueryHostname: "", Log: common.LogConfig{LogPrefix: "", LogFileRotationSizeMB: 100, CompressLogFile: false}, TLS: common.TLSConfig{Enabled: false, CertificatePath: "", PrivateKeyPath: ""}, + CompressStatic: "false", + CompressStaticConverted: false, Tracing: common.TracingConfig{ServiceName: "", Endpoint: "", SamplingPercentage: 1}, DatabaseConfig: common.DatabaseConfig{Enabled: true, Provider: "sqlite"}, EmailConfig: common.EmailConfig{SmtpHost: "smtp.gmail.com", SmtpPort: 587, SenderEmail: "doe1024john@gmail.com", GmailAppPassword: " "}, @@ -792,6 +798,18 @@ func ExtractConfigData(yamlData []byte) (common.Configuration, error) { config.TLS.PrivateKeyPath = strings.Trim(config.TLS.PrivateKeyPath, "./") } + if len(config.CompressStatic) <= 0 { + config.CompressStatic = "true" + } + compressStatic, err := strconv.ParseBool(config.CompressStatic) + if err != nil { + compressStatic = true + config.CompressStatic = "true" + log.Errorf("ExtractConfigData: failed to parse compress static flag. Defaulting to %v. Error: %v", + compressStatic, err) + } + config.CompressStaticConverted = compressStatic + // Check for Tracing Config through environment variables if os.Getenv("TRACESTORE_ENDPOINT") != "" { config.Tracing.Endpoint = os.Getenv("TRACESTORE_ENDPOINT") diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index deb268232..95ec8d092 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -73,6 +73,7 @@ func Test_ExtractConfigData(t *testing.T) { logPrefix: "./pkg/ingestor/httpserver/" logFileRotationSizeMB: 100 compressLogFile: false + compressStatic: false `), false, common.Configuration{ @@ -110,6 +111,8 @@ func Test_ExtractConfigData(t *testing.T) { DualCaseCheckConverted: true, SafeServerStart: true, Log: common.LogConfig{LogPrefix: "./pkg/ingestor/httpserver/", LogFileRotationSizeMB: 100, CompressLogFile: false}, + CompressStatic: "false", + CompressStaticConverted: false, Tracing: common.TracingConfig{Endpoint: "http://localhost:4317", ServiceName: "siglens", SamplingPercentage: 100}, }, }, @@ -172,6 +175,8 @@ invalidField: "invalid" DualCaseCheck: "true", DualCaseCheckConverted: true, Log: common.LogConfig{LogPrefix: "", LogFileRotationSizeMB: 100, CompressLogFile: false}, + CompressStatic: "true", + CompressStaticConverted: true, Tracing: common.TracingConfig{Endpoint: "", ServiceName: "siglens", SamplingPercentage: 0}, }, }, diff --git a/pkg/server/query/server.go b/pkg/server/query/server.go index 33ceff414..1c4778a30 100644 --- a/pkg/server/query/server.go +++ b/pkg/server/query/server.go @@ -43,10 +43,11 @@ type queryserverCfg struct { Config config.WebConfig Addr string // Log *zap.Logger //ToDo implement debug logger - ln net.Listener - lnTls net.Listener - Router *router.Router - debug bool + ln net.Listener + lnTls net.Listener + Router *router.Router + staticHandler fasthttp.RequestHandler + debug bool } var ( @@ -57,12 +58,19 @@ var ( // ConstructHttpServer new fasthttp server func ConstructQueryServer(cfg config.WebConfig, ServerAddr string) *queryserverCfg { + staticFs := fasthttp.FS{ + Root: "./static", + IndexNames: []string{"index.html"}, + Compress: config.ShouldCompressStaticFiles(), + CompressBrotli: config.ShouldCompressStaticFiles(), + } s := &queryserverCfg{ - Config: cfg, - Addr: ServerAddr, - Router: router.New(), - debug: true, + Config: cfg, + Addr: ServerAddr, + Router: router.New(), + staticHandler: staticFs.NewRequestHandler(), + debug: true, } return s } @@ -285,7 +293,7 @@ func (hs *queryserverCfg) Run(htmlTemplate *htmltemplate.Template, textTemplate return } - fasthttp.ServeFile(ctx, "static/"+filepath) + hs.staticHandler(ctx) }) }