config

package
v0.0.0-...-a6a90d4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

package config provides functions and values for reading and validating kava 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_HEIGHT_BASED_ROUTING_ENABLED_KEY             = "PROXY_HEIGHT_BASED_ROUTING_ENABLED"
	PROXY_PRUNING_BACKEND_HOST_URL_MAP_ENVIRONMENT_KEY = "PROXY_PRUNING_BACKEND_HOST_URL_MAP"
	PROXY_SHARDED_ROUTING_ENABLED_ENVIRONMENT_KEY      = "PROXY_SHARDED_ROUTING_ENABLED"
	PROXY_SHARD_BACKEND_HOST_URL_MAP_ENVIRONMENT_KEY   = "PROXY_SHARD_BACKEND_HOST_URL_MAP"
	PROXY_MAXIMUM_BATCH_SIZE_ENVIRONMENT_KEY           = "PROXY_MAXIMUM_REQ_BATCH_SIZE"
	DEFAULT_PROXY_MAXIMUM_BATCH_SIZE                   = 500
	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
	METRIC_PRUNING_ENABLED_ENVIRONMENT_KEY                      = "METRIC_PRUNING_ENABLED"
	DEFAULT_METRIC_PRUNING_ENABLED                              = true
	METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS_ENVIRONMENT_KEY     = "METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS"
	// 60 seconds * 60 minutes * 24 hours = 1 day
	DEFAULT_METRIC_PRUNING_ROUTINE_INTERVAL_SECONDS                   = 86400
	METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS_ENVIRONMENT_KEY    = "METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS"
	DEFAULT_METRIC_PRUNING_ROUTINE_DELAY_FIRST_RUN_SECONDS            = 10
	METRIC_PRUNING_MAX_REQUEST_METRICS_HISTORY_DAYS_ENVIRONMENT_KEY   = "METRIC_PRUNING_MAX_REQUEST_METRICS_HISTORY_DAYS"
	DEFAULT_METRIC_PRUNING_MAX_REQUEST_METRICS_HISTORY_DAYS           = 45
	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
	CACHE_ENABLED_ENVIRONMENT_KEY                                     = "CACHE_ENABLED"
	REDIS_ENDPOINT_URL_ENVIRONMENT_KEY                                = "REDIS_ENDPOINT_URL"
	REDIS_PASSWORD_ENVIRONMENT_KEY                                    = "REDIS_PASSWORD"
	CACHE_METHOD_HAS_BLOCK_NUMBER_PARAM_TTL_ENVIRONMENT_KEY           = "CACHE_METHOD_HAS_BLOCK_NUMBER_PARAM_TTL_SECONDS"
	CACHE_METHOD_HAS_BLOCK_HASH_PARAM_TTL_ENVIRONMENT_KEY             = "CACHE_METHOD_HAS_BLOCK_HASH_PARAM_TTL_SECONDS"
	CACHE_STATIC_METHOD_TTL_ENVIRONMENT_KEY                           = "CACHE_STATIC_METHOD_TTL_SECONDS"
	CACHE_METHOD_HAS_TX_HASH_PARAM_TTL_ENVIRONMENT_KEY                = "CACHE_METHOD_HAS_TX_HASH_PARAM_TTL_SECONDS"
	CACHE_PREFIX_ENVIRONMENT_KEY                                      = "CACHE_PREFIX"
	WHITELISTED_HEADERS_ENVIRONMENT_KEY                               = "WHITELISTED_HEADERS"
	DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE_ENVIRONMENT_KEY         = "DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE"
	HOSTNAME_TO_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE_MAP_ENVIRONMENT_KEY = "HOSTNAME_TO_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE_MAP"
)
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 (
	ErrEmptyHostMap                  = errors.New("backend host url map is empty")
	ErrEmptyHostnameToHeaderValueMap = errors.New("hostname to header value map is empty")
)
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 ParseRawHostnameToHeaderValueMap

func ParseRawHostnameToHeaderValueMap(raw string) (map[string]string, error)

ParseRawHostnameToHeaderValueMap attempts to parse mappings of hostname to corresponding header value. For example hostname to access-control-allow-origin header 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 ParseRawShardRoutingBackendHostURLMap

func ParseRawShardRoutingBackendHostURLMap(raw string) (map[string]IntervalURLMap, error)

ParseRawShardRoutingBackendHostURLMap attempts to parse backend host URL mapping for shards. The shard map is a map of host name => (map of end block => backend route) 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
	EnableHeightBasedRouting                      bool
	ProxyPruningBackendHostURLMapRaw              string
	ProxyPruningBackendHostURLMap                 map[string]url.URL
	EnableShardedRouting                          bool
	ProxyShardBackendHostURLMapRaw                string
	ProxyShardBackendHostURLMap                   map[string]IntervalURLMap
	ProxyMaximumBatchSize                         int
	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
	MetricPruningEnabled                          bool
	MetricPruningRoutineInterval                  time.Duration
	MetricPruningRoutineDelayFirstRun             time.Duration
	MetricPruningMaxRequestMetricsHistoryDays     int
	CacheEnabled                                  bool
	RedisEndpointURL                              string
	RedisPassword                                 string
	CacheMethodHasBlockNumberParamTTL             time.Duration
	CacheMethodHasBlockHashParamTTL               time.Duration
	CacheStaticMethodTTL                          time.Duration
	CacheMethodHasTxHashParamTTL                  time.Duration
	CachePrefix                                   string
	WhitelistedHeaders                            []string
	DefaultAccessControlAllowOriginValue          string
	HostnameToAccessControlAllowOriginValueMapRaw string
	HostnameToAccessControlAllowOriginValueMap    map[string]string
}

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

func (*Config) GetAccessControlAllowOriginValue

func (cfg *Config) GetAccessControlAllowOriginValue(hostname string) string

type IntervalURLMap

type IntervalURLMap struct {
	UrlByEndHeight map[uint64]*url.URL
	// contains filtered or unexported fields
}

IntervalURLMap stores URLs associated with a range of numbers. The intervals are defined by their endpoints and must not overlap. The intervals are inclusive of the endpoints.

func NewIntervalURLMap

func NewIntervalURLMap(urlByEndHeight map[uint64]*url.URL) IntervalURLMap

NewIntervalURLMap creates a new IntervalMap from a map of interval endpoint => url. The intervals are inclusive of their endpoint. ie. if the lowest value endpoint in the map is 10, the interval is for all numbers 1 through 10.

func (*IntervalURLMap) Lookup

func (im *IntervalURLMap) Lookup(num uint64) (*url.URL, uint64, bool)

Lookup finds the value associated with the interval containing the number, if it exists.

Jump to

Keyboard shortcuts

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