config

package
v0.0.0-...-96059aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

package config provides functions and values for reading and validating fury proxy service configuration

Index

Constants

View Source
const (
	LOG_LEVEL_ENVIRONMENT_KEY                          = "LOG_LEVEL"
	DEFAULT_LOG_LEVEL                                  = "INFO"
	PROXY_BACKEND_HOST_URL_MAP_ENVIRONMENT_KEY         = "PROXY_BACKEND_HOST_URL_MAP"
	PROXY_SERVICE_PORT_ENVIRONMENT_KEY                 = "PROXY_SERVICE_PORT"
	DATABASE_NAME_ENVIRONMENT_KEY                      = "DATABASE_NAME"
	DATABASE_ENDPOINT_URL_ENVIRONMENT_KEY              = "DATABASE_ENDPOINT_URL"
	DATABASE_USERNAME_ENVIRONMENT_KEY                  = "DATABASE_USERNAME"
	DATABASE_PASSWORD_ENVIRONMENT_KEY                  = "DATABASE_PASSWORD"
	DATABASE_SSL_ENABLED_ENVIRONMENT_KEY               = "DATABASE_SSL_ENABLED"
	DATABASE_QUERY_LOGGING_ENABLED_ENVIRONMENT_KEY     = "DATABASE_QUERY_LOGGING_ENABLED"
	RUN_DATABASE_MIGRATIONS_ENVIRONMENT_KEY            = "RUN_DATABASE_MIGRATIONS"
	DEFAULT_HTTP_READ_TIMEOUT                          = 30
	DEFAULT_HTTP_WRITE_TIMEOUT                         = 60
	HTTP_READ_TIMEOUT_ENVIRONMENT_KEY                  = "HTTP_READ_TIMEOUT_SECONDS"
	HTTP_WRITE_TIMEOUT_ENVIRONMENT_KEY                 = "HTTP_WRITE_TIMEOUT_SECONDS"
	METRIC_COMPACTION_ROUTINE_INTERVAL_ENVIRONMENT_KEY = "METRIC_COMPACTION_ROUTINE_INTERVAL_SECONDS"
	METRIC_COLLECTION_ENABLED_ENVIRONMENT_KEY          = "METRIC_COLLECTION_ENABLED"
	DEFAULT_METRIC_COLLECTION_ENABLED                  = true
	// 60 seconds / minute * 60 minutes = 1 hour
	DEFAULT_METRIC_COMPACTION_ROUTINE_INTERVAL_SECONDS           = 3600
	METRIC_PARTITIONING_ROUTINE_INTERVAL_SECONDS_ENVIRONMENT_KEY = "METRIC_PARTITIONING_ROUTINE_INTERVAL_SECONDS"
	// 24 hours
	DEFAULT_METRIC_PARTITIONING_ROUTINE_INTERVAL_SECONDS                = 86400
	METRIC_PARTITIONING_ROUTINE_DELAY_FIRST_RUN_SECONDS_ENVIRONMENT_KEY = "METRIC_PARTITIONING_ROUTINE_DELAY_FIRST_RUN_SECONDS"
	// 24 hours
	DEFAULT_METRIC_PARTITIONING_ROUTINE_DELAY_FIRST_RUN_SECONDS = 10
	METRIC_PARTITIONING_PREFILL_PERIOD_DAYS_ENVIRONMENT_KEY     = "METRIC_PARTITIONING_PREFILL_PERIOD_DAYS"
	DEFAULT_METRIC_PARTITIONING_PREFILL_PERIOD_DAYS             = 7
	EVM_QUERY_SERVICE_ENVIRONMENT_KEY                           = "EVM_QUERY_SERVICE_URL"
	DATABASE_MAX_IDLE_CONNECTIONS_ENVIRONMENT_KEY               = "DATABASE_MAX_IDLE_CONNECTIONS"
	DEFAULT_DATABASE_MAX_IDLE_CONNECTIONS                       = 20
	DATABASE_CONNECTION_MAX_IDLE_SECONDS_ENVIRONMENT_KEY        = "DATABASE_CONNECTION_MAX_IDLE_SECONDS"
	DEFAULT_DATABASE_CONNECTION_MAX_IDLE_SECONDS                = 5
	DATABASE_MAX_OPEN_CONNECTIONS_ENVIRONMENT_KEY               = "DATABASE_MAX_OPEN_CONNECTIONS"
	DEFAULT_DATABASE_MAX_OPEN_CONNECTIONS                       = 100
	DATABASE_READ_TIMEOUT_SECONDS_ENVIRONMENT_KEY               = "DATABASE_READ_TIMEOUT_SECONDS"
	DEFAULT_DATABASE_READ_TIMEOUT_SECONDS                       = 60
	DATABASE_WRITE_TIMEOUT_SECONDS_ENVIRONMENT_KEY              = "DATABASE_WRITE_TIMEOUT_SECONDS"
	DEFAULT_DATABASE_WRITE_TIMEOUT_SECONDS                      = 10
)
View Source
const PROXY_BACKEND_HOST_URL_MAP_ENTRY_DELIMITER = ","

seperator for a single entry mapping the <host to proxy for> to <backend server for host>

View Source
const PROXY_BACKEND_HOST_URL_MAP_SUB_COMPONENT_DELIMITER = ">"

seperator for

Variables

View Source
var (
	ValidLogLevels = [4]string{"TRACE", "DEBUG", "INFO", "ERROR"}
	// restrict to max 1 month to guarantee constraint that
	// metric partitioning routine never needs to create partitions
	// spanning more than 2 calendar months
	MaxMetricPartitioningPrefillPeriodDays = 28
)

Functions

func EnvOrDefault

func EnvOrDefault(key string, fallback string) string

EnvOrDefault fetches an environment variable value, or if not set returns the fallback value

func EnvOrDefaultBool

func EnvOrDefaultBool(key string, fallback bool) bool

EnvOrDefaultBool fetches a boolean environment variable value, or if not set returns the fallback value

func EnvOrDefaultInt

func EnvOrDefaultInt(key string, fallback int) int

EnvOrDefaultInt fetches an int environment variable value, or if not set returns the fallback value

func EnvOrDefaultInt64

func EnvOrDefaultInt64(key string, fallback int64) int64

EnvOrDefaultInt64 fetches an int64 environment variable value, or if not set returns the fallback value

func ParseRawProxyBackendHostURLMap

func ParseRawProxyBackendHostURLMap(raw string) (map[string]url.URL, error)

ParseRawProxyBackendHostURLMap attempts to parse mappings of hostname to proxy for and the backend servers to proxy the request to, returning the mapping and error (if any).

func Validate

func Validate(config Config) error

Validate validates the provided config returning a list of errors that can be unwrapped with `errors.Unwrap` or nil if the config is valid

Types

type Config

type Config struct {
	ProxyServicePort                       string
	LogLevel                               string
	ProxyBackendHostURLMapRaw              string
	ProxyBackendHostURLMapParsed           map[string]url.URL
	EvmQueryServiceURL                     string
	DatabaseName                           string
	DatabaseEndpointURL                    string
	DatabaseUserName                       string
	DatabasePassword                       string
	DatabaseReadTimeoutSeconds             int64
	DatabaseWriteTimeoutSeconds            int64
	DatabaseSSLEnabled                     bool
	DatabaseQueryLoggingEnabled            bool
	DatabaseMaxIdleConnections             int64
	DatabaseConnectionMaxIdleSeconds       int64
	DatabaseMaxOpenConnections             int64
	RunDatabaseMigrations                  bool
	HTTPReadTimeoutSeconds                 int64
	HTTPWriteTimeoutSeconds                int64
	MetricCompactionRoutineInterval        time.Duration
	MetricCollectionEnabled                bool
	MetricPartitioningRoutineInterval      time.Duration
	MetricPartitioningRoutineDelayFirstRun time.Duration
	MetricPartitioningPrefillPeriodDays    int
}

func ReadConfig

func ReadConfig() Config

ReadConfig attempts to parse service config from environment values the returned config may be invalid and should be validated via the `Validate` function of the Config package before use

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL