chore: standardize env for query service
Summary
Standardize ENV variable for query service
Related Issues / PR's
fixes #5266
Welcome to the SigNoz community! Thank you for your first pull request and making this project better. 🤗
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
@shivanshuraj1333 Can you please review it.
This is not what I intended, add something like this, and then do a bootstrap load at query service start, handle errors if there is any access issue.
package config
import (
"os"
)
type Config struct {
SignozJwtSecret string
StorageType string
ClickHouseUrl string
ClickHouseOptimizeReadInOrderRegex string
ClickHouseMaxExecutionTimeLeaf string
ClickHouseTimeoutBeforeCheckingExecutionSpeed string
ClickHouseMaxBytesToRead string
SmtpEnabled string
DeploymentType string
SmtpHost string
SmtpPort string
SmtpUsername string
SmtpPassword string
SmtpFrom string
}
var AppConfig Config
func LoadConfig() {
AppConfig = Config{
SignozJwtSecret: os.Getenv("SIGNOZ_JWT_SECRET"),
StorageType: os.Getenv("STORAGE"),
ClickHouseUrl: os.Getenv("CLICKHOUSE_URL"),
ClickHouseOptimizeReadInOrderRegex: os.Getenv("CLICKHOUSE_OPTIMIZE_READ_IN_ORDER_REGEX"),
ClickHouseMaxExecutionTimeLeaf: os.Getenv("CLICKHOUSE_MAX_EXECUTION_TIME_LEAF"),
ClickHouseTimeoutBeforeCheckingExecutionSpeed: os.Getenv("CLICKHOUSE_TIMEOUT_BEFORE_CHECKING_EXECUTION_SPEED"),
ClickHouseMaxBytesToRead: os.Getenv("CLICKHOUSE_MAX_BYTES_TO_READ"),
SmtpEnabled: os.Getenv("SMTP_ENABLED"),
DeploymentType: os.Getenv("DEPLOYMENT_TYPE"),
SmtpHost: os.Getenv("SMTP_HOST"),
SmtpPort: os.Getenv("SMTP_PORT"),
SmtpUsername: os.Getenv("SMTP_USERNAME"),
SmtpPassword: os.Getenv("SMTP_PASSWORD"),
SmtpFrom: os.Getenv("SMTP_FROM"),
}
}
and use it like below
jwtSecret := config.AppConfig.SignozJwtSecret
Ok, make sense. About handle errors part do we want to have something like below ?
// validateConfig checks if the configuration is valid
func validateConfig(config Config) error {
if config.SignozJwtSecret == "" {
return errors.New("missing SIGNOZ_JWT_SECRET")
}
if config.StorageType == "" {
return errors.New("missing STORAGE_TYPE")
}
if config.ClickHouseUrl == "" {
return errors.New("missing CLICKHOUSE_URL")
}
if config.SmtpHost == "" {
return errors.New("missing SMTP_HOST")
}
if config.SmtpPort == 0 {
return errors.New("invalid SMTP_PORT")
}
if config.SmtpUsername == "" {
return errors.New("missing SMTP_USERNAME")
}
if config.SmtpPassword == "" {
return errors.New("missing SMTP_PASSWORD")
}
if config.SmtpFrom == "" {
return errors.New("missing SMTP_FROM")
}
return nil
}
No, before accessing the flags in the code, handle the error there using existing error handling (mostly log the error).
Shouldn't this check and alert all errors on load? I don't think the system is much use without a ClickhouseServer variable defined.
Hi @slayer321, Thank you for the PR! We are however in the middle of a major codebase revamp where we will also be standardising config as per https://github.com/SigNoz/signoz/issues/6805.
As part of the config being created, we are also going to validate and fail fast. That should take care of @Aeolun's point!