2020-07-06 09:18:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-08-21 06:49:24 +00:00
|
|
|
"encoding/json"
|
2020-07-06 09:18:16 +00:00
|
|
|
"fmt"
|
2023-08-30 18:24:22 +00:00
|
|
|
"math"
|
2020-07-06 09:18:16 +00:00
|
|
|
"os"
|
2023-02-03 10:00:18 +00:00
|
|
|
"path"
|
2022-07-13 12:27:05 +00:00
|
|
|
"runtime"
|
2020-10-19 08:47:13 +00:00
|
|
|
"sort"
|
2020-07-06 09:18:16 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
2023-08-17 21:04:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/handler"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/resolver"
|
2023-08-23 11:07:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/version"
|
2023-08-17 21:04:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
2023-11-09 06:07:11 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/zapjournald"
|
2020-07-06 09:18:16 +00:00
|
|
|
"github.com/spf13/pflag"
|
|
|
|
"github.com/spf13/viper"
|
2023-11-09 06:07:11 +00:00
|
|
|
"github.com/ssgreg/journald"
|
2020-07-06 09:18:16 +00:00
|
|
|
"go.uber.org/zap"
|
2022-09-12 09:45:54 +00:00
|
|
|
"go.uber.org/zap/zapcore"
|
2020-07-06 09:18:16 +00:00
|
|
|
)
|
|
|
|
|
2023-11-09 06:07:11 +00:00
|
|
|
const (
|
|
|
|
destinationStdout = "stdout"
|
|
|
|
destinationJournald = "journald"
|
2024-07-31 06:45:46 +00:00
|
|
|
|
|
|
|
wildcardPlaceholder = "<wildcard>"
|
2023-11-09 06:07:11 +00:00
|
|
|
)
|
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
const (
|
2022-07-18 13:11:25 +00:00
|
|
|
defaultRebalanceInterval = 60 * time.Second
|
2022-04-14 15:09:57 +00:00
|
|
|
defaultHealthcheckTimeout = 15 * time.Second
|
2022-07-18 13:11:25 +00:00
|
|
|
defaultConnectTimeout = 10 * time.Second
|
2022-11-15 14:19:21 +00:00
|
|
|
defaultStreamTimeout = 10 * time.Second
|
2022-04-14 15:09:57 +00:00
|
|
|
defaultShutdownTimeout = 15 * time.Second
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
defaultLoggerSamplerInterval = 1 * time.Second
|
|
|
|
|
2024-08-26 10:04:24 +00:00
|
|
|
defaultGracefulCloseOnSwitchTimeout = 10 * time.Second
|
|
|
|
|
2022-07-29 06:26:11 +00:00
|
|
|
defaultPoolErrorThreshold uint32 = 100
|
2023-08-21 06:49:24 +00:00
|
|
|
defaultPlacementPolicy = "REP 3"
|
2022-07-29 06:26:11 +00:00
|
|
|
|
2020-07-22 13:02:32 +00:00
|
|
|
defaultMaxClientsCount = 100
|
|
|
|
defaultMaxClientsDeadline = time.Second * 30
|
2023-08-30 18:24:22 +00:00
|
|
|
|
|
|
|
defaultSoftMemoryLimit = math.MaxInt64
|
2023-10-26 13:44:40 +00:00
|
|
|
|
|
|
|
defaultReadHeaderTimeout = 30 * time.Second
|
|
|
|
defaultIdleTimeout = 30 * time.Second
|
2023-11-16 12:10:51 +00:00
|
|
|
|
2024-02-06 13:44:49 +00:00
|
|
|
defaultAccessBoxCacheRemovingCheckInterval = 5 * time.Minute
|
|
|
|
|
2024-08-01 13:24:47 +00:00
|
|
|
defaultNamespaceHeader = "X-Frostfs-Namespace"
|
|
|
|
defaultVHSHeader = "X-Frostfs-S3-VHS"
|
|
|
|
defaultServernameHeader = "X-Frostfs-Servername"
|
2023-11-21 08:51:07 +00:00
|
|
|
|
|
|
|
defaultConstraintName = "default"
|
2023-12-01 11:16:19 +00:00
|
|
|
|
2023-11-30 08:25:05 +00:00
|
|
|
defaultNamespace = ""
|
2024-02-11 18:00:56 +00:00
|
|
|
|
|
|
|
defaultReconnectInterval = time.Minute
|
2024-05-30 13:02:27 +00:00
|
|
|
|
|
|
|
defaultRetryMaxAttempts = 4
|
|
|
|
defaultRetryMaxBackoff = 30 * time.Second
|
|
|
|
defaultRetryStrategy = handler.RetryStrategyExponential
|
2020-07-06 09:18:16 +00:00
|
|
|
)
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
var (
|
|
|
|
defaultCopiesNumbers = []uint32{0}
|
|
|
|
defaultDefaultNamespaces = []string{"", "root"}
|
|
|
|
)
|
2023-08-21 06:49:24 +00:00
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
const ( // Settings.
|
|
|
|
// Logger.
|
2023-11-09 06:07:11 +00:00
|
|
|
cfgLoggerLevel = "logger.level"
|
|
|
|
cfgLoggerDestination = "logger.destination"
|
2020-07-07 11:25:13 +00:00
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
cfgLoggerSamplingEnabled = "logger.sampling.enabled"
|
|
|
|
cfgLoggerSamplingInitial = "logger.sampling.initial"
|
|
|
|
cfgLoggerSamplingThereafter = "logger.sampling.thereafter"
|
|
|
|
cfgLoggerSamplingInterval = "logger.sampling.interval"
|
|
|
|
|
2024-07-12 12:31:43 +00:00
|
|
|
// HttpLogging.
|
|
|
|
cfgHTTPLoggingEnabled = "http_logging.enabled"
|
|
|
|
cfgHTTPLoggingMaxBody = "http_logging.max_body"
|
|
|
|
cfgHTTPLoggingMaxLogSize = "http_logging.max_log_size"
|
|
|
|
cfgHTTPLoggingDestination = "http_logging.destination"
|
|
|
|
cfgHTTPLoggingGzip = "http_logging.gzip"
|
|
|
|
cfgHTTPLoggingLogResponse = "http_logging.log_response"
|
|
|
|
|
2021-06-22 13:25:29 +00:00
|
|
|
// Wallet.
|
2022-07-28 13:26:42 +00:00
|
|
|
cfgWalletPath = "wallet.path"
|
|
|
|
cfgWalletAddress = "wallet.address"
|
2021-06-22 13:25:29 +00:00
|
|
|
cfgWalletPassphrase = "wallet.passphrase"
|
2022-07-28 13:26:42 +00:00
|
|
|
cmdWallet = "wallet"
|
|
|
|
cmdAddress = "address"
|
2020-07-15 20:16:27 +00:00
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
// Server.
|
|
|
|
cfgServer = "server"
|
|
|
|
cfgTLSEnabled = "tls.enabled"
|
2020-07-13 15:50:11 +00:00
|
|
|
cfgTLSKeyFile = "tls.key_file"
|
|
|
|
cfgTLSCertFile = "tls.cert_file"
|
|
|
|
|
2022-07-29 06:26:11 +00:00
|
|
|
// Pool config.
|
2022-04-14 15:09:57 +00:00
|
|
|
cfgConnectTimeout = "connect_timeout"
|
2022-11-15 14:19:21 +00:00
|
|
|
cfgStreamTimeout = "stream_timeout"
|
2022-04-14 15:09:57 +00:00
|
|
|
cfgHealthcheckTimeout = "healthcheck_timeout"
|
|
|
|
cfgRebalanceInterval = "rebalance_interval"
|
2022-07-29 06:26:11 +00:00
|
|
|
cfgPoolErrorThreshold = "pool_error_threshold"
|
2020-07-07 11:25:13 +00:00
|
|
|
|
2021-08-16 09:58:09 +00:00
|
|
|
// Caching.
|
2022-10-03 14:33:49 +00:00
|
|
|
cfgObjectsCacheLifetime = "cache.objects.lifetime"
|
|
|
|
cfgObjectsCacheSize = "cache.objects.size"
|
|
|
|
cfgListObjectsCacheLifetime = "cache.list.lifetime"
|
|
|
|
cfgListObjectsCacheSize = "cache.list.size"
|
2023-10-16 06:27:21 +00:00
|
|
|
cfgSessionListCacheLifetime = "cache.list_session.lifetime"
|
|
|
|
cfgSessionListCacheSize = "cache.list_session.size"
|
2022-10-03 14:33:49 +00:00
|
|
|
cfgBucketsCacheLifetime = "cache.buckets.lifetime"
|
|
|
|
cfgBucketsCacheSize = "cache.buckets.size"
|
|
|
|
cfgNamesCacheLifetime = "cache.names.lifetime"
|
|
|
|
cfgNamesCacheSize = "cache.names.size"
|
|
|
|
cfgSystemCacheLifetime = "cache.system.lifetime"
|
|
|
|
cfgSystemCacheSize = "cache.system.size"
|
|
|
|
cfgAccessBoxCacheLifetime = "cache.accessbox.lifetime"
|
|
|
|
cfgAccessBoxCacheSize = "cache.accessbox.size"
|
|
|
|
cfgAccessControlCacheLifetime = "cache.accesscontrol.lifetime"
|
|
|
|
cfgAccessControlCacheSize = "cache.accesscontrol.size"
|
2023-12-05 09:12:35 +00:00
|
|
|
cfgMorphPolicyCacheLifetime = "cache.morph_policy.lifetime"
|
|
|
|
cfgMorphPolicyCacheSize = "cache.morph_policy.size"
|
2024-03-12 08:28:24 +00:00
|
|
|
cfgFrostfsIDCacheLifetime = "cache.frostfsid.lifetime"
|
|
|
|
cfgFrostfsIDCacheSize = "cache.frostfsid.size"
|
2024-09-05 12:36:40 +00:00
|
|
|
cfgNetworkInfoCacheLifetime = "cache.network_info.lifetime"
|
2021-08-16 09:58:09 +00:00
|
|
|
|
2024-02-06 13:44:49 +00:00
|
|
|
cfgAccessBoxCacheRemovingCheckInterval = "cache.accessbox.removing_check_interval"
|
|
|
|
|
2021-08-23 18:39:15 +00:00
|
|
|
// Policy.
|
2022-11-03 06:34:18 +00:00
|
|
|
cfgPolicyDefault = "placement_policy.default"
|
|
|
|
cfgPolicyRegionMapFile = "placement_policy.region_mapping"
|
2023-04-24 23:49:12 +00:00
|
|
|
cfgCopiesNumbers = "placement_policy.copies_numbers"
|
2021-08-23 18:39:15 +00:00
|
|
|
|
2021-10-04 14:32:35 +00:00
|
|
|
// CORS.
|
|
|
|
cfgDefaultMaxAge = "cors.default_max_age"
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// MaxClients.
|
2020-07-22 13:02:32 +00:00
|
|
|
cfgMaxClientsCount = "max_clients_count"
|
|
|
|
cfgMaxClientsDeadline = "max_clients_deadline"
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Metrics / Profiler / Web.
|
2022-07-26 13:29:07 +00:00
|
|
|
cfgPrometheusEnabled = "prometheus.enabled"
|
|
|
|
cfgPrometheusAddress = "prometheus.address"
|
|
|
|
cfgPProfEnabled = "pprof.enabled"
|
|
|
|
cfgPProfAddress = "pprof.address"
|
|
|
|
|
2023-05-31 16:35:20 +00:00
|
|
|
// Tracing.
|
2024-09-10 07:31:01 +00:00
|
|
|
cfgTracingEnabled = "tracing.enabled"
|
|
|
|
cfgTracingExporter = "tracing.exporter"
|
|
|
|
cfgTracingEndpoint = "tracing.endpoint"
|
|
|
|
cfgTracingTrustedCa = "tracing.trusted_ca"
|
2023-05-31 16:35:20 +00:00
|
|
|
|
2022-07-26 13:29:07 +00:00
|
|
|
cfgListenDomains = "listen_domains"
|
2020-07-07 11:25:13 +00:00
|
|
|
|
2024-08-01 13:24:47 +00:00
|
|
|
// VHS.
|
|
|
|
cfgVHSEnabled = "vhs.enabled"
|
|
|
|
cfgVHSHeader = "vhs.vhs_header"
|
|
|
|
cfgServernameHeader = "vhs.servername_header"
|
|
|
|
cfgVHSNamespaces = "vhs.namespaces"
|
2024-07-31 06:45:46 +00:00
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Peers.
|
2020-10-19 08:47:13 +00:00
|
|
|
cfgPeers = "peers"
|
|
|
|
|
2022-01-11 10:09:34 +00:00
|
|
|
// NeoGo.
|
2022-04-14 18:10:57 +00:00
|
|
|
cfgRPCEndpoint = "rpc_endpoint"
|
2022-01-11 10:09:34 +00:00
|
|
|
|
|
|
|
// Resolving.
|
2022-04-14 18:10:57 +00:00
|
|
|
cfgResolveOrder = "resolve_order"
|
2022-01-11 10:09:34 +00:00
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Application.
|
2020-07-07 11:25:13 +00:00
|
|
|
cfgApplicationBuildTime = "app.build_time"
|
2020-10-19 08:47:13 +00:00
|
|
|
|
2023-03-02 14:54:33 +00:00
|
|
|
// Kludge.
|
2023-10-09 12:34:51 +00:00
|
|
|
cfgKludgeUseDefaultXMLNS = "kludge.use_default_xmlns"
|
|
|
|
cfgKludgeBypassContentEncodingCheckInChunks = "kludge.bypass_content_encoding_check_in_chunks"
|
2023-11-16 12:10:51 +00:00
|
|
|
cfgKludgeDefaultNamespaces = "kludge.default_namespaces"
|
2023-10-26 13:44:40 +00:00
|
|
|
// Web.
|
|
|
|
cfgWebReadTimeout = "web.read_timeout"
|
|
|
|
cfgWebReadHeaderTimeout = "web.read_header_timeout"
|
|
|
|
cfgWebWriteTimeout = "web.write_timeout"
|
|
|
|
cfgWebIdleTimeout = "web.idle_timeout"
|
|
|
|
|
2024-05-30 13:02:27 +00:00
|
|
|
// Retry.
|
|
|
|
cfgRetryMaxAttempts = "retry.max_attempts"
|
|
|
|
cfgRetryMaxBackoff = "retry.max_backoff"
|
|
|
|
cfgRetryStrategy = "retry.strategy"
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
// Namespaces.
|
|
|
|
cfgNamespacesConfig = "namespaces.config"
|
|
|
|
|
2024-04-17 14:08:55 +00:00
|
|
|
cfgSourceIPHeader = "source_ip_header"
|
|
|
|
|
2024-07-15 15:35:54 +00:00
|
|
|
// Containers.
|
2024-08-12 11:22:56 +00:00
|
|
|
cfgContainersCORS = "containers.cors"
|
|
|
|
cfgContainersLifecycle = "containers.lifecycle"
|
2024-07-15 15:35:54 +00:00
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Command line args.
|
2023-02-03 10:00:18 +00:00
|
|
|
cmdHelp = "help"
|
|
|
|
cmdVersion = "version"
|
|
|
|
cmdConfig = "config"
|
|
|
|
cmdConfigDir = "config-dir"
|
|
|
|
cmdPProf = "pprof"
|
|
|
|
cmdMetrics = "metrics"
|
2021-05-20 12:41:32 +00:00
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
cmdListenAddress = "listen_address"
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// Configuration of parameters of requests to FrostFS.
|
|
|
|
// Number of the object copies to consider PUT to FrostFS successful.
|
|
|
|
cfgSetCopiesNumber = "frostfs.set_copies_number"
|
2023-07-14 12:30:47 +00:00
|
|
|
// Enabling client side object preparing for PUT operations.
|
|
|
|
cfgClientCut = "frostfs.client_cut"
|
2023-08-25 10:07:59 +00:00
|
|
|
// Sets max buffer size for read payload in put operations.
|
|
|
|
cfgBufferMaxSizeForPut = "frostfs.buffer_max_size_for_put"
|
2023-10-23 14:06:42 +00:00
|
|
|
// Sets max attempt to make successful tree request.
|
|
|
|
cfgTreePoolMaxAttempts = "frostfs.tree_pool_max_attempts"
|
2022-08-11 22:48:56 +00:00
|
|
|
|
2024-08-26 10:04:24 +00:00
|
|
|
// Specifies the timeout after which unhealthy client be closed during rebalancing
|
|
|
|
// if it will become healthy back.
|
|
|
|
cfgGracefulCloseOnSwitchTimeout = "frostfs.graceful_close_on_switch_timeout"
|
|
|
|
|
2022-08-31 22:43:36 +00:00
|
|
|
// List of allowed AccessKeyID prefixes.
|
|
|
|
cfgAllowedAccessKeyIDPrefixes = "allowed_access_key_id_prefixes"
|
|
|
|
|
2023-02-10 12:19:29 +00:00
|
|
|
// Bucket resolving options.
|
2023-11-16 12:10:51 +00:00
|
|
|
cfgResolveNamespaceHeader = "resolve_bucket.namespace_header"
|
|
|
|
cfgResolveBucketAllow = "resolve_bucket.allow"
|
|
|
|
cfgResolveBucketDeny = "resolve_bucket.deny"
|
2023-02-10 12:19:29 +00:00
|
|
|
|
2023-08-30 18:24:22 +00:00
|
|
|
// Runtime.
|
|
|
|
cfgSoftMemoryLimit = "runtime.soft_memory_limit"
|
|
|
|
|
2023-10-02 08:52:07 +00:00
|
|
|
// Enable return MD5 checksum in ETag.
|
2023-12-05 12:49:13 +00:00
|
|
|
cfgMD5Enabled = "features.md5.enabled"
|
|
|
|
cfgPolicyDenyByDefault = "features.policy.deny_by_default"
|
2023-10-02 08:52:07 +00:00
|
|
|
|
2023-10-05 13:25:25 +00:00
|
|
|
// FrostfsID.
|
2023-12-13 14:44:18 +00:00
|
|
|
cfgFrostfsIDContract = "frostfsid.contract"
|
|
|
|
cfgFrostfsIDValidationEnabled = "frostfsid.validation.enabled"
|
2023-10-05 13:25:25 +00:00
|
|
|
|
2023-12-05 09:12:35 +00:00
|
|
|
// Policy.
|
|
|
|
cfgPolicyContract = "policy.contract"
|
|
|
|
|
2023-12-21 14:57:12 +00:00
|
|
|
// Proxy.
|
|
|
|
cfgProxyContract = "proxy.contract"
|
|
|
|
|
2024-02-11 18:00:56 +00:00
|
|
|
// Server.
|
|
|
|
cfgReconnectInterval = "reconnect_interval"
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// envPrefix is an environment variables prefix used for configuration.
|
2021-05-20 12:41:32 +00:00
|
|
|
envPrefix = "S3_GW"
|
2020-07-07 11:25:13 +00:00
|
|
|
)
|
|
|
|
|
2020-10-19 08:47:13 +00:00
|
|
|
var ignore = map[string]struct{}{
|
|
|
|
cfgApplicationBuildTime: {},
|
|
|
|
|
|
|
|
cfgPeers: {},
|
|
|
|
|
|
|
|
cmdHelp: {},
|
|
|
|
cmdVersion: {},
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
func fetchConnectTimeout(cfg *viper.Viper) time.Duration {
|
|
|
|
connTimeout := cfg.GetDuration(cfgConnectTimeout)
|
|
|
|
if connTimeout <= 0 {
|
|
|
|
connTimeout = defaultConnectTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return connTimeout
|
|
|
|
}
|
|
|
|
|
2024-02-11 18:00:56 +00:00
|
|
|
func fetchReconnectInterval(cfg *viper.Viper) time.Duration {
|
|
|
|
reconnect := cfg.GetDuration(cfgReconnectInterval)
|
|
|
|
if reconnect <= 0 {
|
|
|
|
reconnect = defaultReconnectInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
return reconnect
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
func fetchStreamTimeout(cfg *viper.Viper) time.Duration {
|
|
|
|
streamTimeout := cfg.GetDuration(cfgStreamTimeout)
|
|
|
|
if streamTimeout <= 0 {
|
|
|
|
streamTimeout = defaultStreamTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return streamTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchHealthCheckTimeout(cfg *viper.Viper) time.Duration {
|
|
|
|
healthCheckTimeout := cfg.GetDuration(cfgHealthcheckTimeout)
|
|
|
|
if healthCheckTimeout <= 0 {
|
|
|
|
healthCheckTimeout = defaultHealthcheckTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return healthCheckTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchRebalanceInterval(cfg *viper.Viper) time.Duration {
|
|
|
|
rebalanceInterval := cfg.GetDuration(cfgRebalanceInterval)
|
|
|
|
if rebalanceInterval <= 0 {
|
|
|
|
rebalanceInterval = defaultRebalanceInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
return rebalanceInterval
|
|
|
|
}
|
|
|
|
|
2024-08-26 10:04:24 +00:00
|
|
|
func fetchSetGracefulCloseOnSwitchTimeout(cfg *viper.Viper) time.Duration {
|
|
|
|
val := cfg.GetDuration(cfgGracefulCloseOnSwitchTimeout)
|
|
|
|
if val <= 0 {
|
|
|
|
val = defaultGracefulCloseOnSwitchTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
func fetchErrorThreshold(cfg *viper.Viper) uint32 {
|
|
|
|
errorThreshold := cfg.GetUint32(cfgPoolErrorThreshold)
|
|
|
|
if errorThreshold <= 0 {
|
|
|
|
errorThreshold = defaultPoolErrorThreshold
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorThreshold
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchMaxClientsCount(cfg *viper.Viper) int {
|
|
|
|
maxClientsCount := cfg.GetInt(cfgMaxClientsCount)
|
|
|
|
if maxClientsCount <= 0 {
|
|
|
|
maxClientsCount = defaultMaxClientsCount
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxClientsCount
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchMaxClientsDeadline(cfg *viper.Viper) time.Duration {
|
|
|
|
maxClientsDeadline := cfg.GetDuration(cfgMaxClientsDeadline)
|
|
|
|
if maxClientsDeadline <= 0 {
|
|
|
|
maxClientsDeadline = defaultMaxClientsDeadline
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxClientsDeadline
|
|
|
|
}
|
|
|
|
|
2023-08-30 18:24:22 +00:00
|
|
|
func fetchSoftMemoryLimit(cfg *viper.Viper) int64 {
|
|
|
|
softMemoryLimit := cfg.GetSizeInBytes(cfgSoftMemoryLimit)
|
|
|
|
if softMemoryLimit <= 0 {
|
|
|
|
softMemoryLimit = defaultSoftMemoryLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
return int64(softMemoryLimit)
|
|
|
|
}
|
|
|
|
|
2024-05-30 13:02:27 +00:00
|
|
|
func fetchRetryMaxAttempts(cfg *viper.Viper) int {
|
|
|
|
val := cfg.GetInt(cfgRetryMaxAttempts)
|
|
|
|
if val <= 0 {
|
|
|
|
val = defaultRetryMaxAttempts
|
|
|
|
}
|
|
|
|
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchRetryMaxBackoff(cfg *viper.Viper) time.Duration {
|
|
|
|
val := cfg.GetDuration(cfgRetryMaxBackoff)
|
|
|
|
if val <= 0 {
|
|
|
|
val = defaultRetryMaxBackoff
|
|
|
|
}
|
|
|
|
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchRetryStrategy(cfg *viper.Viper) handler.RetryStrategy {
|
|
|
|
val := handler.RetryStrategy(cfg.GetString(cfgRetryStrategy))
|
|
|
|
if val != handler.RetryStrategyExponential && val != handler.RetryStrategyConstant {
|
|
|
|
val = defaultRetryStrategy
|
|
|
|
}
|
|
|
|
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
func fetchDefaultPolicy(l *zap.Logger, cfg *viper.Viper) netmap.PlacementPolicy {
|
|
|
|
var policy netmap.PlacementPolicy
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
if cfg.IsSet(cfgPolicyDefault) {
|
2023-08-21 06:49:24 +00:00
|
|
|
policyStr := cfg.GetString(cfgPolicyDefault)
|
|
|
|
if err := policy.DecodeString(policyStr); err != nil {
|
|
|
|
l.Warn(logs.FailedToParseDefaultLocationConstraint,
|
|
|
|
zap.String("policy", policyStr), zap.String("default", defaultPlacementPolicy), zap.Error(err))
|
|
|
|
} else {
|
|
|
|
return policy
|
|
|
|
}
|
2023-08-17 21:04:52 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
if err := policy.DecodeString(defaultPlacementPolicy); err != nil {
|
2023-08-25 14:16:24 +00:00
|
|
|
l.Fatal(logs.FailedToParseDefaultDefaultLocationConstraint, zap.String("policy", defaultPlacementPolicy))
|
2023-08-17 21:04:52 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
return policy
|
2023-08-17 21:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func fetchCacheLifetime(v *viper.Viper, l *zap.Logger, cfgEntry string, defaultValue time.Duration) time.Duration {
|
|
|
|
if v.IsSet(cfgEntry) {
|
|
|
|
lifetime := v.GetDuration(cfgEntry)
|
|
|
|
if lifetime <= 0 {
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Error(logs.InvalidLifetimeUsingDefaultValue,
|
2023-08-17 21:04:52 +00:00
|
|
|
zap.String("parameter", cfgEntry),
|
|
|
|
zap.Duration("value in config", lifetime),
|
|
|
|
zap.Duration("default", defaultValue))
|
|
|
|
} else {
|
|
|
|
return lifetime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchCacheSize(v *viper.Viper, l *zap.Logger, cfgEntry string, defaultValue int) int {
|
|
|
|
if v.IsSet(cfgEntry) {
|
|
|
|
size := v.GetInt(cfgEntry)
|
|
|
|
if size <= 0 {
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Error(logs.InvalidCacheSizeUsingDefaultValue,
|
2023-08-17 21:04:52 +00:00
|
|
|
zap.String("parameter", cfgEntry),
|
|
|
|
zap.Int("value in config", size),
|
|
|
|
zap.Int("default", defaultValue))
|
|
|
|
} else {
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
|
2024-02-06 13:44:49 +00:00
|
|
|
func fetchRemovingCheckInterval(v *viper.Viper, l *zap.Logger) time.Duration {
|
|
|
|
if !v.IsSet(cfgAccessBoxCacheRemovingCheckInterval) {
|
|
|
|
return defaultAccessBoxCacheRemovingCheckInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
duration := v.GetDuration(cfgAccessBoxCacheRemovingCheckInterval)
|
|
|
|
if duration >= 0 {
|
|
|
|
return duration
|
|
|
|
}
|
|
|
|
|
|
|
|
l.Error(logs.InvalidAccessBoxCacheRemovingCheckInterval,
|
|
|
|
zap.String("parameter", cfgAccessBoxCacheRemovingCheckInterval),
|
|
|
|
zap.Duration("value in config", duration),
|
|
|
|
zap.Duration("default", defaultAccessBoxCacheRemovingCheckInterval))
|
|
|
|
|
|
|
|
return defaultAccessBoxCacheRemovingCheckInterval
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
func fetchDefaultMaxAge(cfg *viper.Viper, l *zap.Logger) int {
|
|
|
|
defaultMaxAge := handler.DefaultMaxAge
|
|
|
|
|
|
|
|
if cfg.IsSet(cfgDefaultMaxAge) {
|
|
|
|
defaultMaxAge = cfg.GetInt(cfgDefaultMaxAge)
|
|
|
|
|
|
|
|
if defaultMaxAge <= 0 && defaultMaxAge != -1 {
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Fatal(logs.InvalidDefaultMaxAge,
|
2023-08-17 21:04:52 +00:00
|
|
|
zap.String("parameter", cfgDefaultMaxAge),
|
|
|
|
zap.String("value in config", strconv.Itoa(defaultMaxAge)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultMaxAge
|
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
func fetchRegionMappingPolicies(l *zap.Logger, cfg *viper.Viper) map[string]netmap.PlacementPolicy {
|
|
|
|
filepath := cfg.GetString(cfgPolicyRegionMapFile)
|
|
|
|
regionPolicyMap, err := readRegionMap(filepath)
|
2023-08-17 21:04:52 +00:00
|
|
|
if err != nil {
|
2023-08-21 06:49:24 +00:00
|
|
|
l.Warn(logs.FailedToReadRegionMapFilePolicies, zap.String("file", filepath), zap.Error(err))
|
|
|
|
return make(map[string]netmap.PlacementPolicy)
|
2023-08-17 21:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
regionMap := make(map[string]netmap.PlacementPolicy, len(regionPolicyMap))
|
|
|
|
for region, policy := range regionPolicyMap {
|
2023-08-21 06:49:24 +00:00
|
|
|
if region == api.DefaultLocationConstraint {
|
|
|
|
l.Warn(logs.DefaultLocationConstraintCantBeOverriden, zap.String("policy", policy))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-08-17 21:04:52 +00:00
|
|
|
var pp netmap.PlacementPolicy
|
|
|
|
if err = pp.DecodeString(policy); err == nil {
|
|
|
|
regionMap[region] = pp
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = pp.UnmarshalJSON([]byte(policy)); err == nil {
|
|
|
|
regionMap[region] = pp
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
l.Warn(logs.FailedToParseLocationConstraint, zap.String("region", region), zap.String("policy", policy))
|
|
|
|
}
|
|
|
|
|
|
|
|
return regionMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func readRegionMap(filePath string) (map[string]string, error) {
|
|
|
|
regionMap := make(map[string]string)
|
|
|
|
|
|
|
|
if filePath == "" {
|
|
|
|
return regionMap, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := os.ReadFile(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("coudln't read file '%s'", filePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = json.Unmarshal(data, ®ionMap); err != nil {
|
|
|
|
return nil, fmt.Errorf("unmarshal policies: %w", err)
|
2023-08-17 21:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return regionMap, nil
|
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
func fetchDefaultCopiesNumbers(l *zap.Logger, v *viper.Viper) []uint32 {
|
2023-05-16 14:24:10 +00:00
|
|
|
unparsed := v.GetStringSlice(cfgSetCopiesNumber)
|
2023-08-21 06:49:24 +00:00
|
|
|
result := make([]uint32, len(unparsed))
|
2023-05-16 14:24:10 +00:00
|
|
|
for i := range unparsed {
|
|
|
|
parsedValue, err := strconv.ParseUint(unparsed[i], 10, 32)
|
|
|
|
if err != nil {
|
2023-08-21 06:49:24 +00:00
|
|
|
l.Warn(logs.FailedToParseDefaultCopiesNumbers,
|
|
|
|
zap.Strings("copies numbers", unparsed), zap.Uint32s("default", defaultCopiesNumbers), zap.Error(err))
|
|
|
|
return defaultCopiesNumbers
|
2023-05-16 14:24:10 +00:00
|
|
|
}
|
2023-08-21 06:49:24 +00:00
|
|
|
result[i] = uint32(parsedValue)
|
2023-05-16 14:24:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
return result
|
2023-05-16 14:24:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 06:49:24 +00:00
|
|
|
func fetchCopiesNumbers(l *zap.Logger, v *viper.Viper) map[string][]uint32 {
|
|
|
|
copiesNums := make(map[string][]uint32)
|
2023-04-24 23:49:12 +00:00
|
|
|
for i := 0; ; i++ {
|
|
|
|
key := cfgCopiesNumbers + "." + strconv.Itoa(i) + "."
|
|
|
|
constraint := v.GetString(key + "location_constraint")
|
|
|
|
vector := v.GetStringSlice(key + "vector")
|
|
|
|
|
2023-05-16 14:24:10 +00:00
|
|
|
if constraint == "" || len(vector) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2023-04-24 23:49:12 +00:00
|
|
|
vector32 := make([]uint32, len(vector))
|
|
|
|
for j := range vector {
|
|
|
|
parsedValue, err := strconv.ParseUint(vector[j], 10, 32)
|
|
|
|
if err != nil {
|
2023-08-21 06:49:24 +00:00
|
|
|
l.Warn(logs.FailedToParseCopiesNumbers, zap.String("location", constraint),
|
|
|
|
zap.Strings("copies numbers", vector), zap.Error(err))
|
|
|
|
continue
|
2023-04-24 23:49:12 +00:00
|
|
|
}
|
|
|
|
vector32[j] = uint32(parsedValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
copiesNums[constraint] = vector32
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Info(logs.ConstraintAdded, zap.String("location", constraint), zap.Strings("copies numbers", vector))
|
2023-04-24 23:49:12 +00:00
|
|
|
}
|
2023-08-21 06:49:24 +00:00
|
|
|
return copiesNums
|
2023-04-24 23:49:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
func fetchDefaultNamespaces(l *zap.Logger, v *viper.Viper) []string {
|
|
|
|
defaultNamespaces := v.GetStringSlice(cfgKludgeDefaultNamespaces)
|
|
|
|
if len(defaultNamespaces) == 0 {
|
|
|
|
defaultNamespaces = defaultDefaultNamespaces
|
|
|
|
l.Warn(logs.DefaultNamespacesCannotBeEmpty, zap.Strings("namespaces", defaultNamespaces))
|
|
|
|
}
|
|
|
|
|
2023-12-14 13:12:10 +00:00
|
|
|
for i := range defaultNamespaces { // to be set namespaces in env variable as `S3_GW_KLUDGE_DEFAULT_NAMESPACES="" 'root'`
|
|
|
|
defaultNamespaces[i] = strings.Trim(defaultNamespaces[i], "\"'")
|
|
|
|
}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
return defaultNamespaces
|
|
|
|
}
|
|
|
|
|
2024-02-09 14:38:14 +00:00
|
|
|
func fetchNamespacesConfig(l *zap.Logger, v *viper.Viper) (NamespacesConfig, []string) {
|
2023-11-21 08:51:07 +00:00
|
|
|
defaultNSRegionMap := fetchRegionMappingPolicies(l, v)
|
|
|
|
defaultNSRegionMap[defaultConstraintName] = fetchDefaultPolicy(l, v)
|
|
|
|
|
|
|
|
defaultNSCopiesNumbers := fetchCopiesNumbers(l, v)
|
|
|
|
defaultNSCopiesNumbers[defaultConstraintName] = fetchDefaultCopiesNumbers(l, v)
|
|
|
|
|
|
|
|
defaultNSValue := Namespace{
|
|
|
|
LocationConstraints: defaultNSRegionMap,
|
|
|
|
CopiesNumbers: defaultNSCopiesNumbers,
|
|
|
|
}
|
|
|
|
|
|
|
|
nsConfig, err := readNamespacesConfig(v.GetString(cfgNamespacesConfig))
|
|
|
|
if err != nil {
|
2023-12-01 12:42:50 +00:00
|
|
|
l.Warn(logs.FailedToParseNamespacesConfig, zap.Error(err))
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultNamespacesNames := fetchDefaultNamespaces(l, v)
|
|
|
|
|
|
|
|
var overrideDefaults []Namespace
|
|
|
|
for _, name := range defaultNamespacesNames {
|
|
|
|
if ns, ok := nsConfig.Namespaces[name]; ok {
|
|
|
|
overrideDefaults = append(overrideDefaults, ns)
|
|
|
|
delete(nsConfig.Namespaces, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(overrideDefaults) > 0 {
|
|
|
|
l.Warn(logs.DefaultNamespaceConfigValuesBeOverwritten)
|
|
|
|
defaultNSValue.LocationConstraints = overrideDefaults[0].LocationConstraints
|
|
|
|
defaultNSValue.CopiesNumbers = overrideDefaults[0].CopiesNumbers
|
|
|
|
if len(overrideDefaults) > 1 {
|
|
|
|
l.Warn(logs.MultipleDefaultOverridesFound, zap.String("name", overrideDefaults[0].Name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 14:38:14 +00:00
|
|
|
nsConfig.Namespaces[defaultNamespace] = Namespace{
|
|
|
|
Name: defaultNamespace,
|
|
|
|
LocationConstraints: defaultNSValue.LocationConstraints,
|
|
|
|
CopiesNumbers: defaultNSValue.CopiesNumbers,
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 14:38:14 +00:00
|
|
|
return nsConfig, defaultNamespacesNames
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func readNamespacesConfig(filepath string) (NamespacesConfig, error) {
|
2023-12-01 12:42:50 +00:00
|
|
|
nsConfig := NamespacesConfig{
|
|
|
|
Namespaces: make(Namespaces),
|
|
|
|
}
|
|
|
|
|
2023-11-21 08:51:07 +00:00
|
|
|
if filepath == "" {
|
2023-12-01 12:42:50 +00:00
|
|
|
return nsConfig, nil
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err := os.ReadFile(filepath)
|
|
|
|
if err != nil {
|
2023-12-01 12:42:50 +00:00
|
|
|
return nsConfig, fmt.Errorf("failed to read namespace config '%s': %w", filepath, err)
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = json.Unmarshal(data, &nsConfig); err != nil {
|
2023-12-01 12:42:50 +00:00
|
|
|
return nsConfig, fmt.Errorf("failed to parse namespace config: %w", err)
|
2023-11-21 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsConfig, nil
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
func fetchPeers(l *zap.Logger, v *viper.Viper) []pool.NodeParam {
|
|
|
|
var nodes []pool.NodeParam
|
2020-07-07 11:25:13 +00:00
|
|
|
for i := 0; ; i++ {
|
2020-10-19 08:47:13 +00:00
|
|
|
key := cfgPeers + "." + strconv.Itoa(i) + "."
|
2020-07-07 11:25:13 +00:00
|
|
|
address := v.GetString(key + "address")
|
|
|
|
weight := v.GetFloat64(key + "weight")
|
2021-12-29 13:38:23 +00:00
|
|
|
priority := v.GetInt(key + "priority")
|
2020-07-07 11:25:13 +00:00
|
|
|
|
|
|
|
if address == "" {
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Warn(logs.SkipEmptyAddress)
|
2020-07-07 11:25:13 +00:00
|
|
|
break
|
|
|
|
}
|
2021-05-26 16:48:27 +00:00
|
|
|
if weight <= 0 { // unspecified or wrong
|
|
|
|
weight = 1
|
|
|
|
}
|
2021-12-29 13:38:23 +00:00
|
|
|
if priority <= 0 { // unspecified or wrong
|
|
|
|
priority = 1
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
nodes = append(nodes, pool.NewNodeParam(priority, address, weight))
|
2020-07-07 11:25:13 +00:00
|
|
|
|
2023-08-23 11:07:52 +00:00
|
|
|
l.Info(logs.AddedStoragePeer,
|
2023-06-09 06:34:04 +00:00
|
|
|
zap.Int("priority", priority),
|
2020-11-24 07:09:58 +00:00
|
|
|
zap.String("address", address),
|
|
|
|
zap.Float64("weight", weight))
|
2020-07-07 11:25:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
return nodes
|
2020-07-07 11:25:13 +00:00
|
|
|
}
|
|
|
|
|
2024-02-11 18:00:56 +00:00
|
|
|
func fetchServers(v *viper.Viper, log *zap.Logger) []ServerInfo {
|
2022-11-09 10:07:18 +00:00
|
|
|
var servers []ServerInfo
|
2024-02-11 18:00:56 +00:00
|
|
|
seen := make(map[string]struct{})
|
2022-11-09 10:07:18 +00:00
|
|
|
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
key := cfgServer + "." + strconv.Itoa(i) + "."
|
|
|
|
|
|
|
|
var serverInfo ServerInfo
|
|
|
|
serverInfo.Address = v.GetString(key + "address")
|
|
|
|
serverInfo.TLS.Enabled = v.GetBool(key + cfgTLSEnabled)
|
|
|
|
serverInfo.TLS.KeyFile = v.GetString(key + cfgTLSKeyFile)
|
|
|
|
serverInfo.TLS.CertFile = v.GetString(key + cfgTLSCertFile)
|
|
|
|
|
|
|
|
if serverInfo.Address == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2024-02-11 18:00:56 +00:00
|
|
|
if _, ok := seen[serverInfo.Address]; ok {
|
|
|
|
log.Warn(logs.WarnDuplicateAddress, zap.String("address", serverInfo.Address))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[serverInfo.Address] = struct{}{}
|
2022-11-09 10:07:18 +00:00
|
|
|
servers = append(servers, serverInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
return servers
|
|
|
|
}
|
|
|
|
|
2024-07-31 06:45:46 +00:00
|
|
|
func fetchDomains(v *viper.Viper, log *zap.Logger) []string {
|
|
|
|
domains := validateDomains(v.GetStringSlice(cfgListenDomains), log)
|
|
|
|
|
|
|
|
countParts := func(domain string) int {
|
|
|
|
return strings.Count(domain, ".")
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(domains, func(i, j int) bool {
|
|
|
|
return countParts(domains[i]) > countParts(domains[j])
|
|
|
|
})
|
|
|
|
|
|
|
|
return domains
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchVHSNamespaces(v *viper.Viper, log *zap.Logger) map[string]bool {
|
|
|
|
vhsNamespacesEnabled := make(map[string]bool)
|
|
|
|
nsMap := v.GetStringMap(cfgVHSNamespaces)
|
|
|
|
for ns, val := range nsMap {
|
|
|
|
if _, ok := vhsNamespacesEnabled[ns]; ok {
|
|
|
|
log.Warn(logs.WarnDuplicateNamespaceVHS, zap.String("namespace", ns))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
enabledFlag, ok := val.(bool)
|
|
|
|
if !ok {
|
|
|
|
log.Warn(logs.WarnValueVHSEnabledFlagWrongType, zap.String("namespace", ns))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
vhsNamespacesEnabled[ns] = enabledFlag
|
|
|
|
}
|
|
|
|
|
|
|
|
return vhsNamespacesEnabled
|
|
|
|
}
|
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
func newSettings() *viper.Viper {
|
|
|
|
v := viper.New()
|
|
|
|
|
|
|
|
v.AutomaticEnv()
|
2021-05-20 12:41:32 +00:00
|
|
|
v.SetEnvPrefix(envPrefix)
|
2020-07-06 09:18:16 +00:00
|
|
|
v.SetConfigType("yaml")
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
2021-06-24 15:21:34 +00:00
|
|
|
v.AllowEmptyEnv(true)
|
2020-07-06 09:18:16 +00:00
|
|
|
|
|
|
|
// flags setup:
|
|
|
|
flags := pflag.NewFlagSet("commandline", pflag.ExitOnError)
|
2020-12-02 09:46:51 +00:00
|
|
|
flags.SetOutput(os.Stdout)
|
2020-07-06 09:18:16 +00:00
|
|
|
flags.SortFlags = false
|
|
|
|
|
2022-07-26 13:29:07 +00:00
|
|
|
flags.Bool(cmdPProf, false, "enable pprof")
|
|
|
|
flags.Bool(cmdMetrics, false, "enable prometheus metrics")
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2020-10-19 08:47:13 +00:00
|
|
|
help := flags.BoolP(cmdHelp, "h", false, "show help")
|
2021-05-20 12:41:32 +00:00
|
|
|
versionFlag := flags.BoolP(cmdVersion, "v", false, "show version")
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2022-07-28 13:26:42 +00:00
|
|
|
flags.StringP(cmdWallet, "w", "", `path to the wallet`)
|
|
|
|
flags.String(cmdAddress, "", `address of wallet account`)
|
2023-02-03 10:00:18 +00:00
|
|
|
flags.StringArray(cmdConfig, nil, "config paths")
|
|
|
|
flags.String(cmdConfigDir, "", "config dir path")
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2022-04-14 15:09:57 +00:00
|
|
|
flags.Duration(cfgHealthcheckTimeout, defaultHealthcheckTimeout, "set timeout to check node health during rebalance")
|
2022-12-20 08:38:58 +00:00
|
|
|
flags.Duration(cfgConnectTimeout, defaultConnectTimeout, "set timeout to connect to FrostFS nodes")
|
2022-04-14 15:09:57 +00:00
|
|
|
flags.Duration(cfgRebalanceInterval, defaultRebalanceInterval, "set rebalance interval")
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2020-07-22 13:02:32 +00:00
|
|
|
flags.Int(cfgMaxClientsCount, defaultMaxClientsCount, "set max-clients count")
|
|
|
|
flags.Duration(cfgMaxClientsDeadline, defaultMaxClientsDeadline, "set max-clients deadline")
|
|
|
|
|
2022-11-09 11:53:26 +00:00
|
|
|
flags.String(cmdListenAddress, "0.0.0.0:8080", "set the main address to listen")
|
2021-06-10 12:26:57 +00:00
|
|
|
flags.String(cfgTLSCertFile, "", "TLS certificate file to use")
|
|
|
|
flags.String(cfgTLSKeyFile, "", "TLS key file to use")
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
peers := flags.StringArrayP(cfgPeers, "p", nil, "set FrostFS nodes")
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2022-01-11 10:09:34 +00:00
|
|
|
flags.StringP(cfgRPCEndpoint, "r", "", "set RPC endpoint")
|
|
|
|
resolveMethods := flags.StringSlice(cfgResolveOrder, []string{resolver.DNSResolver}, "set bucket name resolve order")
|
|
|
|
|
2022-08-30 10:52:37 +00:00
|
|
|
domains := flags.StringSliceP(cfgListenDomains, "d", nil, "set domains to be listened")
|
2020-12-10 15:11:45 +00:00
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
// set defaults:
|
|
|
|
|
2024-02-06 13:44:49 +00:00
|
|
|
v.SetDefault(cfgAccessBoxCacheRemovingCheckInterval, defaultAccessBoxCacheRemovingCheckInterval)
|
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
// logger:
|
2020-07-07 11:25:13 +00:00
|
|
|
v.SetDefault(cfgLoggerLevel, "debug")
|
2023-11-09 06:07:11 +00:00
|
|
|
v.SetDefault(cfgLoggerDestination, "stdout")
|
2024-09-20 11:34:05 +00:00
|
|
|
v.SetDefault(cfgLoggerSamplingEnabled, false)
|
|
|
|
v.SetDefault(cfgLoggerSamplingThereafter, 100)
|
|
|
|
v.SetDefault(cfgLoggerSamplingInitial, 100)
|
|
|
|
v.SetDefault(cfgLoggerSamplingInterval, defaultLoggerSamplerInterval)
|
2020-07-06 09:18:16 +00:00
|
|
|
|
2024-07-12 12:31:43 +00:00
|
|
|
// http logger
|
|
|
|
v.SetDefault(cfgHTTPLoggingEnabled, false)
|
|
|
|
v.SetDefault(cfgHTTPLoggingMaxBody, 1024)
|
|
|
|
v.SetDefault(cfgHTTPLoggingMaxLogSize, 50)
|
|
|
|
v.SetDefault(cfgHTTPLoggingDestination, "stdout")
|
|
|
|
v.SetDefault(cfgHTTPLoggingGzip, false)
|
|
|
|
v.SetDefault(cfgHTTPLoggingLogResponse, true)
|
|
|
|
|
2022-07-29 06:26:11 +00:00
|
|
|
// pool:
|
|
|
|
v.SetDefault(cfgPoolErrorThreshold, defaultPoolErrorThreshold)
|
2022-11-15 14:19:21 +00:00
|
|
|
v.SetDefault(cfgStreamTimeout, defaultStreamTimeout)
|
2022-07-29 06:26:11 +00:00
|
|
|
|
2022-07-26 13:29:07 +00:00
|
|
|
v.SetDefault(cfgPProfAddress, "localhost:8085")
|
|
|
|
v.SetDefault(cfgPrometheusAddress, "localhost:8086")
|
|
|
|
|
2023-08-25 10:07:59 +00:00
|
|
|
// frostfs
|
|
|
|
v.SetDefault(cfgBufferMaxSizeForPut, 1024*1024) // 1mb
|
|
|
|
|
2023-03-02 14:54:33 +00:00
|
|
|
// kludge
|
2023-10-09 12:34:51 +00:00
|
|
|
v.SetDefault(cfgKludgeUseDefaultXMLNS, false)
|
2023-07-10 09:17:44 +00:00
|
|
|
v.SetDefault(cfgKludgeBypassContentEncodingCheckInChunks, false)
|
2023-11-21 08:51:07 +00:00
|
|
|
v.SetDefault(cfgKludgeDefaultNamespaces, defaultDefaultNamespaces)
|
2023-03-02 14:54:33 +00:00
|
|
|
|
2023-10-26 13:44:40 +00:00
|
|
|
// web
|
|
|
|
v.SetDefault(cfgWebReadHeaderTimeout, defaultReadHeaderTimeout)
|
|
|
|
v.SetDefault(cfgWebIdleTimeout, defaultIdleTimeout)
|
|
|
|
|
2023-10-05 13:25:25 +00:00
|
|
|
// frostfsid
|
|
|
|
v.SetDefault(cfgFrostfsIDContract, "frostfsid.frostfs")
|
|
|
|
|
2023-12-05 09:12:35 +00:00
|
|
|
// policy
|
|
|
|
v.SetDefault(cfgPolicyContract, "policy.frostfs")
|
|
|
|
|
2023-12-21 14:57:12 +00:00
|
|
|
// proxy
|
|
|
|
v.SetDefault(cfgProxyContract, "proxy.frostfs")
|
|
|
|
|
2023-11-16 12:10:51 +00:00
|
|
|
// resolve
|
|
|
|
v.SetDefault(cfgResolveNamespaceHeader, defaultNamespaceHeader)
|
|
|
|
|
2024-05-30 13:02:27 +00:00
|
|
|
// retry
|
|
|
|
v.SetDefault(cfgRetryMaxAttempts, defaultRetryMaxAttempts)
|
|
|
|
v.SetDefault(cfgRetryMaxBackoff, defaultRetryMaxBackoff)
|
|
|
|
|
2024-08-01 13:24:47 +00:00
|
|
|
// vhs
|
|
|
|
v.SetDefault(cfgVHSHeader, defaultVHSHeader)
|
|
|
|
v.SetDefault(cfgServernameHeader, defaultServernameHeader)
|
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
// Bind flags
|
|
|
|
if err := bindFlags(v, flags); err != nil {
|
|
|
|
panic(fmt.Errorf("bind flags: %w", err))
|
2020-07-06 09:18:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
if err := flags.Parse(os.Args); err != nil {
|
2022-07-28 13:26:42 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
if v.IsSet(cfgServer+".0."+cfgTLSKeyFile) && v.IsSet(cfgServer+".0."+cfgTLSCertFile) {
|
|
|
|
v.Set(cfgServer+".0."+cfgTLSEnabled, true)
|
2020-07-06 09:18:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 10:09:34 +00:00
|
|
|
if resolveMethods != nil {
|
|
|
|
v.SetDefault(cfgResolveOrder, *resolveMethods)
|
|
|
|
}
|
|
|
|
|
2020-10-19 08:47:13 +00:00
|
|
|
if peers != nil && len(*peers) > 0 {
|
|
|
|
for i := range *peers {
|
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".address", (*peers)[i])
|
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".weight", 1)
|
2022-11-09 10:07:18 +00:00
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".priority", 1)
|
2020-10-19 08:47:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 15:11:45 +00:00
|
|
|
if domains != nil && len(*domains) > 0 {
|
2022-08-30 10:52:37 +00:00
|
|
|
v.SetDefault(cfgListenDomains, *domains)
|
2020-12-10 15:11:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
switch {
|
|
|
|
case help != nil && *help:
|
2022-12-15 14:08:25 +00:00
|
|
|
fmt.Printf("FrostFS S3 gateway %s\n", version.Version)
|
2020-07-06 09:18:16 +00:00
|
|
|
flags.PrintDefaults()
|
2020-10-19 08:47:13 +00:00
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Default environments:")
|
|
|
|
fmt.Println()
|
|
|
|
keys := v.AllKeys()
|
|
|
|
sort.Strings(keys)
|
|
|
|
|
|
|
|
for i := range keys {
|
|
|
|
if _, ok := ignore[keys[i]]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:27:18 +00:00
|
|
|
defaultValue := v.GetString(keys[i])
|
|
|
|
if len(defaultValue) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-10-19 08:47:13 +00:00
|
|
|
k := strings.Replace(keys[i], ".", "_", -1)
|
2022-07-28 13:27:18 +00:00
|
|
|
fmt.Printf("%s_%s = %s\n", envPrefix, strings.ToUpper(k), defaultValue)
|
2020-10-19 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Peers preset:")
|
|
|
|
fmt.Println()
|
|
|
|
|
2021-05-20 12:41:32 +00:00
|
|
|
fmt.Printf("%s_%s_[N]_ADDRESS = string\n", envPrefix, strings.ToUpper(cfgPeers))
|
|
|
|
fmt.Printf("%s_%s_[N]_WEIGHT = 0..1 (float)\n", envPrefix, strings.ToUpper(cfgPeers))
|
2020-10-19 08:47:13 +00:00
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
os.Exit(0)
|
2021-05-20 12:41:32 +00:00
|
|
|
case versionFlag != nil && *versionFlag:
|
2022-12-15 14:08:25 +00:00
|
|
|
fmt.Printf("FrostFS S3 Gateway\nVersion: %s\nGoVersion: %s\n", version.Version, runtime.Version())
|
2020-07-06 09:18:16 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:00:18 +00:00
|
|
|
if err := readInConfig(v); err != nil {
|
|
|
|
panic(err)
|
2021-06-28 10:44:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 09:18:16 +00:00
|
|
|
return v
|
|
|
|
}
|
2022-09-12 09:45:54 +00:00
|
|
|
|
2022-11-09 10:07:18 +00:00
|
|
|
func bindFlags(v *viper.Viper, flags *pflag.FlagSet) error {
|
|
|
|
if err := v.BindPFlag(cfgPProfEnabled, flags.Lookup(cmdPProf)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgPrometheusEnabled, flags.Lookup(cmdMetrics)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cmdConfig, flags.Lookup(cmdConfig)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-03 10:00:18 +00:00
|
|
|
if err := v.BindPFlag(cmdConfigDir, flags.Lookup(cmdConfigDir)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-09 10:07:18 +00:00
|
|
|
if err := v.BindPFlag(cfgWalletPath, flags.Lookup(cmdWallet)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgWalletAddress, flags.Lookup(cmdAddress)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgHealthcheckTimeout, flags.Lookup(cfgHealthcheckTimeout)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgConnectTimeout, flags.Lookup(cfgConnectTimeout)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgRebalanceInterval, flags.Lookup(cfgRebalanceInterval)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgMaxClientsCount, flags.Lookup(cfgMaxClientsCount)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgMaxClientsDeadline, flags.Lookup(cfgMaxClientsDeadline)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgRPCEndpoint, flags.Lookup(cfgRPCEndpoint)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.BindPFlag(cfgServer+".0.address", flags.Lookup(cmdListenAddress)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgServer+".0."+cfgTLSKeyFile, flags.Lookup(cfgTLSKeyFile)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-05-31 16:39:35 +00:00
|
|
|
return v.BindPFlag(cfgServer+".0."+cfgTLSCertFile, flags.Lookup(cfgTLSCertFile))
|
2022-11-09 10:07:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 10:00:18 +00:00
|
|
|
func readInConfig(v *viper.Viper) error {
|
|
|
|
if v.IsSet(cmdConfig) {
|
|
|
|
if err := readConfig(v); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.IsSet(cmdConfigDir) {
|
|
|
|
if err := readConfigDir(v); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func readConfigDir(v *viper.Viper) error {
|
|
|
|
cfgSubConfigDir := v.GetString(cmdConfigDir)
|
|
|
|
entries, err := os.ReadDir(cfgSubConfigDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
if entry.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ext := path.Ext(entry.Name())
|
|
|
|
if ext != ".yaml" && ext != ".yml" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = mergeConfig(v, path.Join(cfgSubConfigDir, entry.Name())); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-12 09:45:54 +00:00
|
|
|
func readConfig(v *viper.Viper) error {
|
2023-02-03 10:00:18 +00:00
|
|
|
for _, fileName := range v.GetStringSlice(cmdConfig) {
|
|
|
|
if err := mergeConfig(v, fileName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeConfig(v *viper.Viper, fileName string) error {
|
|
|
|
cfgFile, err := os.Open(fileName)
|
2022-09-12 09:45:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-03 10:00:18 +00:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if errClose := cfgFile.Close(); errClose != nil {
|
|
|
|
panic(errClose)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-05-31 16:39:35 +00:00
|
|
|
return v.MergeConfig(cfgFile)
|
2022-09-12 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 06:07:11 +00:00
|
|
|
func pickLogger(v *viper.Viper) *Logger {
|
|
|
|
lvl, err := getLogLevel(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dest := v.GetString(cfgLoggerDestination)
|
|
|
|
|
|
|
|
switch dest {
|
|
|
|
case destinationStdout:
|
2024-09-20 11:34:05 +00:00
|
|
|
return newStdoutLogger(v, lvl)
|
2023-11-09 06:07:11 +00:00
|
|
|
case destinationJournald:
|
2024-09-20 11:34:05 +00:00
|
|
|
return newJournaldLogger(v, lvl)
|
2023-11-09 06:07:11 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("wrong destination for logger: %s", dest))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// newStdoutLogger constructs a Logger instance for the current application.
|
2022-09-12 09:45:54 +00:00
|
|
|
// Panics on failure.
|
|
|
|
//
|
|
|
|
// Logger contains a logger is built from zap's production logging configuration with:
|
|
|
|
// - parameterized level (debug by default)
|
|
|
|
// - console encoding
|
|
|
|
// - ISO8601 time encoding
|
2024-09-20 11:34:05 +00:00
|
|
|
// - sampling intervals
|
2022-09-12 09:45:54 +00:00
|
|
|
//
|
|
|
|
// and atomic log level to dynamically change it.
|
|
|
|
//
|
|
|
|
// Logger records a stack trace for all messages at or above fatal level.
|
|
|
|
//
|
|
|
|
// See also zapcore.Level, zap.NewProductionConfig, zap.AddStacktrace.
|
2024-09-20 11:34:05 +00:00
|
|
|
func newStdoutLogger(v *viper.Viper, lvl zapcore.Level) *Logger {
|
|
|
|
stdout := zapcore.AddSync(os.Stderr)
|
|
|
|
level := zap.NewAtomicLevelAt(lvl)
|
|
|
|
|
|
|
|
consoleOutCore := zapcore.NewCore(newLogEncoder(), stdout, level)
|
|
|
|
|
|
|
|
consoleOutCore = samplingEnabling(v, consoleOutCore)
|
2022-09-12 09:45:54 +00:00
|
|
|
|
|
|
|
return &Logger{
|
2024-09-20 11:34:05 +00:00
|
|
|
logger: zap.New(consoleOutCore, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))),
|
|
|
|
lvl: level,
|
2022-09-12 09:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
func newJournaldLogger(v *viper.Viper, lvl zapcore.Level) *Logger {
|
|
|
|
level := zap.NewAtomicLevelAt(lvl)
|
2023-11-09 06:07:11 +00:00
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
encoder := zapjournald.NewPartialEncoder(newLogEncoder(), zapjournald.SyslogFields)
|
2023-11-09 06:07:11 +00:00
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
core := zapjournald.NewCore(level, encoder, &journald.Journal{}, zapjournald.SyslogFields)
|
2023-11-09 06:07:11 +00:00
|
|
|
coreWithContext := core.With([]zapcore.Field{
|
|
|
|
zapjournald.SyslogFacility(zapjournald.LogDaemon),
|
|
|
|
zapjournald.SyslogIdentifier(),
|
|
|
|
zapjournald.SyslogPid(),
|
|
|
|
})
|
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
coreWithContext = samplingEnabling(v, coreWithContext)
|
|
|
|
|
2023-11-09 06:07:11 +00:00
|
|
|
l := zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)))
|
|
|
|
|
|
|
|
return &Logger{
|
|
|
|
logger: l,
|
2024-09-20 11:34:05 +00:00
|
|
|
lvl: level,
|
2023-11-09 06:07:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 11:34:05 +00:00
|
|
|
func newLogEncoder() zapcore.Encoder {
|
|
|
|
c := zap.NewProductionEncoderConfig()
|
|
|
|
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
|
|
|
|
|
|
|
return zapcore.NewConsoleEncoder(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func samplingEnabling(v *viper.Viper, core zapcore.Core) zapcore.Core {
|
|
|
|
// Zap samples by logging the first cgfLoggerSamplingInitial entries with a given level
|
|
|
|
// and message within the specified time interval.
|
|
|
|
// In the above config, only the first cgfLoggerSamplingInitial log entries with the same level and message
|
|
|
|
// are recorded in cfgLoggerSamplingInterval interval. Every other log entry will be dropped within the interval since
|
|
|
|
// cfgLoggerSamplingThereafter is specified here.
|
|
|
|
if v.GetBool(cfgLoggerSamplingEnabled) {
|
|
|
|
core = zapcore.NewSamplerWithOptions(
|
|
|
|
core,
|
|
|
|
v.GetDuration(cfgLoggerSamplingInterval),
|
|
|
|
v.GetInt(cfgLoggerSamplingInitial),
|
|
|
|
v.GetInt(cfgLoggerSamplingThereafter),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return core
|
|
|
|
}
|
|
|
|
|
2022-09-12 09:45:54 +00:00
|
|
|
func getLogLevel(v *viper.Viper) (zapcore.Level, error) {
|
|
|
|
var lvl zapcore.Level
|
|
|
|
lvlStr := v.GetString(cfgLoggerLevel)
|
|
|
|
err := lvl.UnmarshalText([]byte(lvlStr))
|
|
|
|
if err != nil {
|
|
|
|
return lvl, fmt.Errorf("incorrect logger level configuration %s (%v), "+
|
|
|
|
"value should be one of %v", lvlStr, err, [...]zapcore.Level{
|
|
|
|
zapcore.DebugLevel,
|
|
|
|
zapcore.InfoLevel,
|
|
|
|
zapcore.WarnLevel,
|
|
|
|
zapcore.ErrorLevel,
|
|
|
|
zapcore.DPanicLevel,
|
|
|
|
zapcore.PanicLevel,
|
|
|
|
zapcore.FatalLevel,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return lvl, nil
|
|
|
|
}
|
2024-07-31 06:45:46 +00:00
|
|
|
|
|
|
|
func validateDomains(domains []string, log *zap.Logger) []string {
|
|
|
|
validDomains := make([]string, 0, len(domains))
|
|
|
|
LOOP:
|
|
|
|
for _, domain := range domains {
|
|
|
|
domainParts := strings.Split(domain, ".")
|
|
|
|
for _, part := range domainParts {
|
|
|
|
if strings.ContainsAny(part, "<>") && part != wildcardPlaceholder {
|
|
|
|
log.Warn(logs.WarnDomainContainsInvalidPlaceholder, zap.String("domain", domain))
|
|
|
|
continue LOOP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
validDomains = append(validDomains, domain)
|
|
|
|
}
|
|
|
|
return validDomains
|
|
|
|
}
|