2019-12-13 16:02:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-06-09 06:39:01 +00:00
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2019-12-13 16:02:48 +00:00
|
|
|
"fmt"
|
2024-10-24 13:17:28 +00:00
|
|
|
"io"
|
2023-08-31 16:19:57 +00:00
|
|
|
"math"
|
2019-12-13 16:02:48 +00:00
|
|
|
"os"
|
2023-02-03 09:46:25 +00:00
|
|
|
"path"
|
2022-07-18 08:52:30 +00:00
|
|
|
"runtime"
|
2020-11-27 15:18:53 +00:00
|
|
|
"sort"
|
2019-12-21 10:26:14 +00:00
|
|
|
"strconv"
|
2019-12-13 16:02:48 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2023-10-04 11:50:37 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/cache"
|
2023-08-27 15:09:02 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
2024-10-29 11:41:49 +00:00
|
|
|
internalnet "git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/net"
|
2023-03-07 14:08:53 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/resolver"
|
2023-06-14 08:27:33 +00:00
|
|
|
grpctracing "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing/grpc"
|
2023-06-09 06:39:01 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
|
|
|
treepool "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree"
|
2023-11-09 08:11:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/zapjournald"
|
2023-06-09 06:39:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2019-12-13 16:02:48 +00:00
|
|
|
"github.com/spf13/pflag"
|
|
|
|
"github.com/spf13/viper"
|
2023-11-09 08:11:30 +00:00
|
|
|
"github.com/ssgreg/journald"
|
2021-02-12 12:24:52 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
2022-09-08 14:57:22 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
2023-06-09 06:39:01 +00:00
|
|
|
"google.golang.org/grpc"
|
2019-12-13 16:02:48 +00:00
|
|
|
)
|
|
|
|
|
2023-11-09 08:11:30 +00:00
|
|
|
const (
|
|
|
|
destinationStdout = "stdout"
|
|
|
|
destinationJournald = "journald"
|
|
|
|
)
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
const (
|
2022-07-19 14:06:32 +00:00
|
|
|
defaultRebalanceTimer = 60 * time.Second
|
2020-02-19 10:47:21 +00:00
|
|
|
defaultRequestTimeout = 15 * time.Second
|
2022-07-19 14:06:32 +00:00
|
|
|
defaultConnectTimeout = 10 * time.Second
|
2022-11-15 15:06:53 +00:00
|
|
|
defaultStreamTimeout = 10 * time.Second
|
2020-02-19 10:47:21 +00:00
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
defaultLoggerSamplerInterval = 1 * time.Second
|
|
|
|
|
2022-07-27 06:52:08 +00:00
|
|
|
defaultShutdownTimeout = 15 * time.Second
|
|
|
|
|
2022-07-29 06:34:26 +00:00
|
|
|
defaultPoolErrorThreshold uint32 = 100
|
|
|
|
|
2023-08-31 16:19:57 +00:00
|
|
|
defaultSoftMemoryLimit = math.MaxInt64
|
|
|
|
|
2023-08-25 11:53:59 +00:00
|
|
|
defaultBufferMaxSizeForPut = 1024 * 1024 // 1mb
|
|
|
|
|
2023-11-28 08:29:08 +00:00
|
|
|
defaultNamespaceHeader = "X-Frostfs-Namespace"
|
|
|
|
|
2024-03-26 11:34:20 +00:00
|
|
|
defaultReconnectInterval = time.Minute
|
|
|
|
|
2024-10-24 14:27:32 +00:00
|
|
|
defaultCORSMaxAge = 600 // seconds
|
|
|
|
|
2024-10-29 11:41:49 +00:00
|
|
|
defaultMultinetFallbackDelay = 300 * time.Millisecond
|
|
|
|
|
2022-11-24 14:49:21 +00:00
|
|
|
cfgServer = "server"
|
|
|
|
cfgTLSEnabled = "tls.enabled"
|
|
|
|
cfgTLSCertFile = "tls.cert_file"
|
|
|
|
cfgTLSKeyFile = "tls.key_file"
|
2020-12-02 09:09:46 +00:00
|
|
|
|
2024-03-26 11:34:20 +00:00
|
|
|
cfgReconnectInterval = "reconnect_interval"
|
|
|
|
|
2024-09-26 14:32:27 +00:00
|
|
|
cfgIndexPageEnabled = "index_page.enabled"
|
|
|
|
cfgIndexPageTemplatePath = "index_page.template_path"
|
|
|
|
|
2021-05-13 09:41:25 +00:00
|
|
|
// Web.
|
2021-02-12 12:24:52 +00:00
|
|
|
cfgWebReadBufferSize = "web.read_buffer_size"
|
|
|
|
cfgWebWriteBufferSize = "web.write_buffer_size"
|
|
|
|
cfgWebReadTimeout = "web.read_timeout"
|
|
|
|
cfgWebWriteTimeout = "web.write_timeout"
|
|
|
|
cfgWebStreamRequestBody = "web.stream_request_body"
|
|
|
|
cfgWebMaxRequestBodySize = "web.max_request_body_size"
|
2020-12-02 09:09:46 +00:00
|
|
|
|
2022-07-27 06:52:08 +00:00
|
|
|
// Metrics / Profiler.
|
|
|
|
cfgPrometheusEnabled = "prometheus.enabled"
|
|
|
|
cfgPrometheusAddress = "prometheus.address"
|
|
|
|
cfgPprofEnabled = "pprof.enabled"
|
|
|
|
cfgPprofAddress = "pprof.address"
|
|
|
|
|
2023-03-15 08:07:44 +00:00
|
|
|
// Tracing ...
|
2024-11-15 07:53:46 +00:00
|
|
|
cfgTracingEnabled = "tracing.enabled"
|
|
|
|
cfgTracingExporter = "tracing.exporter"
|
|
|
|
cfgTracingEndpoint = "tracing.endpoint"
|
|
|
|
cfgTracingTrustedCa = "tracing.trusted_ca"
|
|
|
|
cfgTracingAttributes = "tracing.attributes"
|
2023-03-15 08:07:44 +00:00
|
|
|
|
2022-07-29 06:34:26 +00:00
|
|
|
// Pool config.
|
|
|
|
cfgConTimeout = "connect_timeout"
|
2022-11-15 15:06:53 +00:00
|
|
|
cfgStreamTimeout = "stream_timeout"
|
2022-07-29 06:34:26 +00:00
|
|
|
cfgReqTimeout = "request_timeout"
|
|
|
|
cfgRebalance = "rebalance_timer"
|
|
|
|
cfgPoolErrorThreshold = "pool_error_threshold"
|
2020-12-02 09:09:46 +00:00
|
|
|
|
2021-05-13 09:41:25 +00:00
|
|
|
// Logger.
|
2023-11-09 08:11:30 +00:00
|
|
|
cfgLoggerLevel = "logger.level"
|
|
|
|
cfgLoggerDestination = "logger.destination"
|
2020-11-27 15:18:53 +00:00
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
cfgLoggerSamplingEnabled = "logger.sampling.enabled"
|
|
|
|
cfgLoggerSamplingInitial = "logger.sampling.initial"
|
|
|
|
cfgLoggerSamplingThereafter = "logger.sampling.thereafter"
|
|
|
|
cfgLoggerSamplingInterval = "logger.sampling.interval"
|
|
|
|
|
2021-06-22 11:53:59 +00:00
|
|
|
// Wallet.
|
|
|
|
cfgWalletPassphrase = "wallet.passphrase"
|
2022-04-08 09:01:57 +00:00
|
|
|
cfgWalletPath = "wallet.path"
|
|
|
|
cfgWalletAddress = "wallet.address"
|
2021-06-22 11:53:59 +00:00
|
|
|
|
2021-05-13 09:41:25 +00:00
|
|
|
// Uploader Header.
|
2021-01-26 09:40:01 +00:00
|
|
|
cfgUploaderHeaderEnableDefaultTimestamp = "upload_header.use_default_timestamp"
|
2021-01-25 19:36:46 +00:00
|
|
|
|
2021-05-13 09:41:25 +00:00
|
|
|
// Peers.
|
2020-11-27 15:18:53 +00:00
|
|
|
cfgPeers = "peers"
|
|
|
|
|
2022-04-20 09:17:20 +00:00
|
|
|
// NeoGo.
|
|
|
|
cfgRPCEndpoint = "rpc_endpoint"
|
|
|
|
|
|
|
|
// Resolving.
|
|
|
|
cfgResolveOrder = "resolve_order"
|
|
|
|
|
2021-10-29 13:11:34 +00:00
|
|
|
// Zip compression.
|
|
|
|
cfgZipCompression = "zip.compression"
|
|
|
|
|
2023-08-31 16:19:57 +00:00
|
|
|
// Runtime.
|
|
|
|
cfgSoftMemoryLimit = "runtime.soft_memory_limit"
|
|
|
|
|
2023-08-21 13:50:23 +00:00
|
|
|
// Enabling client side object preparing for PUT operations.
|
|
|
|
cfgClientCut = "frostfs.client_cut"
|
2023-08-25 11:53:59 +00:00
|
|
|
// Sets max buffer size for read payload in put operations.
|
|
|
|
cfgBufferMaxSizeForPut = "frostfs.buffer_max_size_for_put"
|
2023-11-07 08:07:27 +00:00
|
|
|
// Configuration of parameters of requests to FrostFS.
|
|
|
|
// Sets max attempt to make successful tree request.
|
|
|
|
cfgTreePoolMaxAttempts = "frostfs.tree_pool_max_attempts"
|
2023-08-21 13:50:23 +00:00
|
|
|
|
2023-10-04 11:50:37 +00:00
|
|
|
// Caching.
|
|
|
|
cfgBucketsCacheLifetime = "cache.buckets.lifetime"
|
|
|
|
cfgBucketsCacheSize = "cache.buckets.size"
|
|
|
|
|
2023-11-28 08:29:08 +00:00
|
|
|
// Bucket resolving options.
|
|
|
|
cfgResolveNamespaceHeader = "resolve_bucket.namespace_header"
|
|
|
|
cfgResolveDefaultNamespaces = "resolve_bucket.default_namespaces"
|
|
|
|
|
2024-10-24 14:27:32 +00:00
|
|
|
// CORS.
|
|
|
|
cfgCORSAllowOrigin = "cors.allow_origin"
|
|
|
|
cfgCORSAllowMethods = "cors.allow_methods"
|
|
|
|
cfgCORSAllowHeaders = "cors.allow_headers"
|
|
|
|
cfgCORSExposeHeaders = "cors.expose_headers"
|
|
|
|
cfgCORSAllowCredentials = "cors.allow_credentials"
|
|
|
|
cfgCORSMaxAge = "cors.max_age"
|
|
|
|
|
2024-10-29 11:41:49 +00:00
|
|
|
// Multinet.
|
|
|
|
cfgMultinetEnabled = "multinet.enabled"
|
|
|
|
cfgMultinetBalancer = "multinet.balancer"
|
|
|
|
cfgMultinetRestrict = "multinet.restrict"
|
|
|
|
cfgMultinetFallbackDelay = "multinet.fallback_delay"
|
|
|
|
cfgMultinetSubnets = "multinet.subnets"
|
|
|
|
|
2021-05-13 09:41:25 +00:00
|
|
|
// Command line args.
|
2022-11-24 14:49:21 +00:00
|
|
|
cmdHelp = "help"
|
|
|
|
cmdVersion = "version"
|
|
|
|
cmdPprof = "pprof"
|
|
|
|
cmdMetrics = "metrics"
|
|
|
|
cmdWallet = "wallet"
|
|
|
|
cmdAddress = "address"
|
|
|
|
cmdConfig = "config"
|
2023-02-03 09:46:25 +00:00
|
|
|
cmdConfigDir = "config-dir"
|
2022-11-24 14:49:21 +00:00
|
|
|
cmdListenAddress = "listen_address"
|
2019-12-13 16:02:48 +00:00
|
|
|
)
|
|
|
|
|
2020-11-27 15:18:53 +00:00
|
|
|
var ignore = map[string]struct{}{
|
2022-03-25 13:06:33 +00:00
|
|
|
cfgPeers: {},
|
|
|
|
cmdHelp: {},
|
|
|
|
cmdVersion: {},
|
2020-11-27 15:18:53 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
func settings() *viper.Viper {
|
|
|
|
v := viper.New()
|
|
|
|
v.AutomaticEnv()
|
2020-11-27 15:18:53 +00:00
|
|
|
v.SetEnvPrefix(Prefix)
|
2021-06-28 10:24:46 +00:00
|
|
|
v.AllowEmptyEnv(true)
|
2019-12-13 16:02:48 +00:00
|
|
|
v.SetConfigType("yaml")
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
|
|
|
|
|
|
// flags setup:
|
2019-12-21 10:26:14 +00:00
|
|
|
flags := pflag.NewFlagSet("commandline", pflag.ExitOnError)
|
2020-12-02 08:52:07 +00:00
|
|
|
flags.SetOutput(os.Stdout)
|
2019-12-13 16:02:48 +00:00
|
|
|
flags.SortFlags = false
|
|
|
|
|
2020-12-02 09:09:46 +00:00
|
|
|
flags.Bool(cmdPprof, false, "enable pprof")
|
|
|
|
flags.Bool(cmdMetrics, false, "enable prometheus")
|
2019-12-21 10:26:14 +00:00
|
|
|
|
2020-11-27 15:18:53 +00:00
|
|
|
help := flags.BoolP(cmdHelp, "h", false, "show help")
|
|
|
|
version := flags.BoolP(cmdVersion, "v", false, "show version")
|
2019-12-13 16:02:48 +00:00
|
|
|
|
2021-06-22 11:53:59 +00:00
|
|
|
flags.StringP(cmdWallet, "w", "", `path to the wallet`)
|
|
|
|
flags.String(cmdAddress, "", `address of wallet account`)
|
2023-02-03 09:46:25 +00:00
|
|
|
flags.StringArray(cmdConfig, nil, "config paths")
|
|
|
|
flags.String(cmdConfigDir, "", "config dir path")
|
2020-12-02 09:09:46 +00:00
|
|
|
flags.Duration(cfgConTimeout, defaultConnectTimeout, "gRPC connect timeout")
|
2022-11-15 15:06:53 +00:00
|
|
|
flags.Duration(cfgStreamTimeout, defaultStreamTimeout, "gRPC individual message timeout")
|
2020-12-02 09:09:46 +00:00
|
|
|
flags.Duration(cfgReqTimeout, defaultRequestTimeout, "gRPC request timeout")
|
|
|
|
flags.Duration(cfgRebalance, defaultRebalanceTimer, "gRPC connection rebalance timer")
|
2019-12-13 16:02:48 +00:00
|
|
|
|
2022-11-24 14:49:21 +00:00
|
|
|
flags.String(cmdListenAddress, "0.0.0.0:8080", "addresses to listen")
|
|
|
|
flags.String(cfgTLSCertFile, "", "TLS certificate path")
|
|
|
|
flags.String(cfgTLSKeyFile, "", "TLS key path")
|
2022-12-16 08:45:27 +00:00
|
|
|
peers := flags.StringArrayP(cfgPeers, "p", nil, "FrostFS nodes")
|
2019-12-13 16:02:48 +00:00
|
|
|
|
2022-04-20 09:17:20 +00:00
|
|
|
resolveMethods := flags.StringSlice(cfgResolveOrder, []string{resolver.NNSResolver, resolver.DNSResolver}, "set container name resolve order")
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
// set defaults:
|
|
|
|
|
|
|
|
// logger:
|
2020-11-27 15:18:53 +00:00
|
|
|
v.SetDefault(cfgLoggerLevel, "debug")
|
2023-11-09 08:11:30 +00:00
|
|
|
v.SetDefault(cfgLoggerDestination, "stdout")
|
2024-09-26 14:48:19 +00:00
|
|
|
v.SetDefault(cfgLoggerSamplingEnabled, false)
|
|
|
|
v.SetDefault(cfgLoggerSamplingThereafter, 100)
|
|
|
|
v.SetDefault(cfgLoggerSamplingInitial, 100)
|
|
|
|
v.SetDefault(cfgLoggerSamplingInterval, defaultLoggerSamplerInterval)
|
2019-12-13 16:02:48 +00:00
|
|
|
|
2022-07-29 06:34:26 +00:00
|
|
|
// pool:
|
|
|
|
v.SetDefault(cfgPoolErrorThreshold, defaultPoolErrorThreshold)
|
|
|
|
|
2024-09-26 14:32:27 +00:00
|
|
|
v.SetDefault(cfgIndexPageEnabled, false)
|
|
|
|
v.SetDefault(cfgIndexPageTemplatePath, "")
|
|
|
|
|
2023-08-25 11:53:59 +00:00
|
|
|
// frostfs:
|
|
|
|
v.SetDefault(cfgBufferMaxSizeForPut, defaultBufferMaxSizeForPut)
|
|
|
|
|
2020-04-15 08:10:42 +00:00
|
|
|
// web-server:
|
2020-12-02 09:09:46 +00:00
|
|
|
v.SetDefault(cfgWebReadBufferSize, 4096)
|
|
|
|
v.SetDefault(cfgWebWriteBufferSize, 4096)
|
2022-04-21 15:53:17 +00:00
|
|
|
v.SetDefault(cfgWebReadTimeout, time.Minute*10)
|
|
|
|
v.SetDefault(cfgWebWriteTimeout, time.Minute*5)
|
2021-02-12 12:24:52 +00:00
|
|
|
v.SetDefault(cfgWebStreamRequestBody, true)
|
|
|
|
v.SetDefault(cfgWebMaxRequestBodySize, fasthttp.DefaultMaxRequestBodySize)
|
2020-04-15 08:10:42 +00:00
|
|
|
|
2021-01-26 09:40:01 +00:00
|
|
|
// upload header
|
|
|
|
v.SetDefault(cfgUploaderHeaderEnableDefaultTimestamp, false)
|
|
|
|
|
2021-10-29 13:11:34 +00:00
|
|
|
// zip:
|
|
|
|
v.SetDefault(cfgZipCompression, false)
|
|
|
|
|
2022-07-27 06:52:08 +00:00
|
|
|
// metrics
|
|
|
|
v.SetDefault(cfgPprofAddress, "localhost:8083")
|
|
|
|
v.SetDefault(cfgPrometheusAddress, "localhost:8084")
|
|
|
|
|
2023-11-28 08:29:08 +00:00
|
|
|
// resolve bucket
|
|
|
|
v.SetDefault(cfgResolveNamespaceHeader, defaultNamespaceHeader)
|
|
|
|
v.SetDefault(cfgResolveDefaultNamespaces, []string{"", "root"})
|
|
|
|
|
2024-10-29 11:41:49 +00:00
|
|
|
// multinet
|
|
|
|
v.SetDefault(cfgMultinetFallbackDelay, defaultMultinetFallbackDelay)
|
|
|
|
|
2022-07-27 06:52:08 +00:00
|
|
|
// Binding flags
|
|
|
|
if err := v.BindPFlag(cfgPprofEnabled, flags.Lookup(cmdPprof)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgPrometheusEnabled, flags.Lookup(cmdMetrics)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-08-01 20:52:07 +00:00
|
|
|
if err := v.BindPFlag(cfgWalletPath, flags.Lookup(cmdWallet)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := v.BindPFlag(cfgWalletAddress, flags.Lookup(cmdAddress)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
if err := v.BindPFlags(flags); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-11-24 14:49:21 +00:00
|
|
|
if err := v.BindPFlag(cfgServer+".0.address", flags.Lookup(cmdListenAddress)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgServer+".0."+cfgTLSKeyFile, flags.Lookup(cfgTLSKeyFile)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := v.BindPFlag(cfgServer+".0."+cfgTLSCertFile, flags.Lookup(cfgTLSCertFile)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
if err := flags.Parse(os.Args); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-11-24 14:49:21 +00:00
|
|
|
if v.IsSet(cfgServer+".0."+cfgTLSKeyFile) && v.IsSet(cfgServer+".0."+cfgTLSCertFile) {
|
|
|
|
v.Set(cfgServer+".0."+cfgTLSEnabled, true)
|
|
|
|
}
|
|
|
|
|
2022-04-20 09:17:20 +00:00
|
|
|
if resolveMethods != nil {
|
|
|
|
v.SetDefault(cfgResolveOrder, *resolveMethods)
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
switch {
|
|
|
|
case help != nil && *help:
|
2022-12-16 08:45:27 +00:00
|
|
|
fmt.Printf("FrostFS HTTP Gateway %s\n", Version)
|
2019-12-13 16:02:48 +00:00
|
|
|
flags.PrintDefaults()
|
2020-11-27 15:18:53 +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-08-01 20:47:20 +00:00
|
|
|
defaultValue := v.GetString(keys[i])
|
|
|
|
if len(defaultValue) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-11-27 15:18:53 +00:00
|
|
|
k := strings.Replace(keys[i], ".", "_", -1)
|
2022-08-01 20:47:20 +00:00
|
|
|
fmt.Printf("%s_%s = %s\n", Prefix, strings.ToUpper(k), defaultValue)
|
2020-11-27 15:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Peers preset:")
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Printf("%s_%s_[N]_ADDRESS = string\n", Prefix, strings.ToUpper(cfgPeers))
|
2021-04-14 20:53:47 +00:00
|
|
|
fmt.Printf("%s_%s_[N]_WEIGHT = float\n", Prefix, strings.ToUpper(cfgPeers))
|
2020-11-27 15:18:53 +00:00
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
os.Exit(0)
|
|
|
|
case version != nil && *version:
|
2022-12-16 08:45:27 +00:00
|
|
|
fmt.Printf("FrostFS HTTP Gateway\nVersion: %s\nGoVersion: %s\n", Version, runtime.Version())
|
2019-12-13 16:02:48 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2023-02-03 09:46:25 +00:00
|
|
|
if err := readInConfig(v); err != nil {
|
|
|
|
panic(err)
|
2021-06-28 10:24:46 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 10:26:14 +00:00
|
|
|
if peers != nil && len(*peers) > 0 {
|
|
|
|
for i := range *peers {
|
2020-11-27 15:18:53 +00:00
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".address", (*peers)[i])
|
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".weight", 1)
|
2021-12-07 11:57:16 +00:00
|
|
|
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".priority", 1)
|
2019-12-21 10:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:02:48 +00:00
|
|
|
return v
|
|
|
|
}
|
2022-09-08 14:57:22 +00:00
|
|
|
|
2023-02-03 09:46:25 +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-08 14:57:22 +00:00
|
|
|
func readConfig(v *viper.Viper) error {
|
2023-02-03 09:46:25 +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-08 14:57:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-03 09:46:25 +00:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if errClose := cfgFile.Close(); errClose != nil {
|
|
|
|
panic(errClose)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-05-31 13:34:04 +00:00
|
|
|
return v.MergeConfig(cfgFile)
|
2022-09-08 14:57:22 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 08:11:30 +00:00
|
|
|
func pickLogger(v *viper.Viper) (*zap.Logger, zap.AtomicLevel) {
|
|
|
|
lvl, err := getLogLevel(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dest := v.GetString(cfgLoggerDestination)
|
|
|
|
|
|
|
|
switch dest {
|
|
|
|
case destinationStdout:
|
2024-09-26 14:48:19 +00:00
|
|
|
return newStdoutLogger(v, lvl)
|
2023-11-09 08:11:30 +00:00
|
|
|
case destinationJournald:
|
2024-09-26 14:48:19 +00:00
|
|
|
return newJournaldLogger(v, lvl)
|
2023-11-09 08:11:30 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("wrong destination for logger: %s", dest))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// newStdoutLogger constructs a zap.Logger instance for current application.
|
2022-09-08 14:57:22 +00:00
|
|
|
// Panics on failure.
|
|
|
|
//
|
|
|
|
// Logger is built from zap's production logging configuration with:
|
|
|
|
// - parameterized level (debug by default)
|
|
|
|
// - console encoding
|
|
|
|
// - ISO8601 time encoding
|
|
|
|
//
|
|
|
|
// Logger records a stack trace for all messages at or above fatal level.
|
|
|
|
//
|
|
|
|
// See also zapcore.Level, zap.NewProductionConfig, zap.AddStacktrace.
|
2024-09-26 14:48:19 +00:00
|
|
|
func newStdoutLogger(v *viper.Viper, lvl zapcore.Level) (*zap.Logger, zap.AtomicLevel) {
|
|
|
|
stdout := zapcore.AddSync(os.Stderr)
|
|
|
|
level := zap.NewAtomicLevelAt(lvl)
|
2022-09-08 14:57:22 +00:00
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
consoleOutCore := zapcore.NewCore(newLogEncoder(), stdout, level)
|
|
|
|
consoleOutCore = samplingEnabling(v, consoleOutCore)
|
|
|
|
|
|
|
|
l := zap.New(consoleOutCore, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)))
|
|
|
|
return l, level
|
2022-09-08 14:57:22 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
func newJournaldLogger(v *viper.Viper, lvl zapcore.Level) (*zap.Logger, zap.AtomicLevel) {
|
|
|
|
level := zap.NewAtomicLevelAt(lvl)
|
2023-11-09 08:11:30 +00:00
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
encoder := zapjournald.NewPartialEncoder(newLogEncoder(), zapjournald.SyslogFields)
|
2023-11-09 08:11:30 +00:00
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
core := zapjournald.NewCore(level, encoder, &journald.Journal{}, zapjournald.SyslogFields)
|
2023-11-09 08:11:30 +00:00
|
|
|
coreWithContext := core.With([]zapcore.Field{
|
|
|
|
zapjournald.SyslogFacility(zapjournald.LogDaemon),
|
|
|
|
zapjournald.SyslogIdentifier(),
|
|
|
|
zapjournald.SyslogPid(),
|
|
|
|
})
|
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
coreWithContext = samplingEnabling(v, coreWithContext)
|
|
|
|
|
2023-11-09 08:11:30 +00:00
|
|
|
l := zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)))
|
|
|
|
|
2024-09-26 14:48:19 +00:00
|
|
|
return l, level
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-11-09 08:11:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:57:22 +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
|
|
|
|
}
|
2022-11-24 14:49:21 +00:00
|
|
|
|
2024-03-26 11:34:20 +00:00
|
|
|
func fetchReconnectInterval(cfg *viper.Viper) time.Duration {
|
|
|
|
reconnect := cfg.GetDuration(cfgReconnectInterval)
|
|
|
|
if reconnect <= 0 {
|
|
|
|
reconnect = defaultReconnectInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
return reconnect
|
|
|
|
}
|
|
|
|
|
2024-10-24 13:17:28 +00:00
|
|
|
func fetchIndexPageTemplate(v *viper.Viper, l *zap.Logger) (string, bool) {
|
|
|
|
if !v.GetBool(cfgIndexPageEnabled) {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
reader, err := os.Open(v.GetString(cfgIndexPageTemplatePath))
|
|
|
|
if err != nil {
|
|
|
|
l.Warn(logs.FailedToReadIndexPageTemplate, zap.Error(err))
|
|
|
|
return "", true
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpl, err := io.ReadAll(reader)
|
|
|
|
if err != nil {
|
|
|
|
l.Warn(logs.FailedToReadIndexPageTemplate, zap.Error(err))
|
|
|
|
return "", true
|
|
|
|
}
|
|
|
|
|
|
|
|
l.Info(logs.SetCustomIndexPageTemplate)
|
|
|
|
return string(tmpl), true
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchDefaultNamespaces(v *viper.Viper) []string {
|
|
|
|
namespaces := v.GetStringSlice(cfgResolveDefaultNamespaces)
|
|
|
|
|
|
|
|
for i := range namespaces { // to be set namespaces in env variable as `HTTP_GW_RESOLVE_BUCKET_DEFAULT_NAMESPACES="" "root"`
|
|
|
|
namespaces[i] = strings.Trim(namespaces[i], "\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
return namespaces
|
|
|
|
}
|
|
|
|
|
2024-10-24 14:27:32 +00:00
|
|
|
func fetchCORSMaxAge(v *viper.Viper) int {
|
|
|
|
maxAge := v.GetInt(cfgCORSMaxAge)
|
|
|
|
if maxAge <= 0 {
|
|
|
|
maxAge = defaultCORSMaxAge
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxAge
|
|
|
|
}
|
|
|
|
|
2024-03-26 11:34:20 +00:00
|
|
|
func fetchServers(v *viper.Viper, log *zap.Logger) []ServerInfo {
|
2022-11-24 14:49:21 +00:00
|
|
|
var servers []ServerInfo
|
2024-03-26 11:34:20 +00:00
|
|
|
seen := make(map[string]struct{})
|
2022-11-24 14:49:21 +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-03-26 11:34:20 +00:00
|
|
|
if _, ok := seen[serverInfo.Address]; ok {
|
|
|
|
log.Warn(logs.WarnDuplicateAddress, zap.String("address", serverInfo.Address))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[serverInfo.Address] = struct{}{}
|
2022-11-24 14:49:21 +00:00
|
|
|
servers = append(servers, serverInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
return servers
|
|
|
|
}
|
2023-06-09 06:39:01 +00:00
|
|
|
|
2024-10-29 11:41:49 +00:00
|
|
|
func getPools(ctx context.Context, logger *zap.Logger, cfg *viper.Viper, dialSource *internalnet.DialerSource) (*pool.Pool, *treepool.Pool, *keys.PrivateKey) {
|
2023-06-09 06:39:01 +00:00
|
|
|
key, err := getFrostFSKey(cfg, logger)
|
|
|
|
if err != nil {
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Fatal(logs.CouldNotLoadFrostFSPrivateKey, zap.Error(err))
|
2023-06-09 06:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var prm pool.InitParameters
|
|
|
|
var prmTree treepool.InitParameters
|
|
|
|
|
|
|
|
prm.SetKey(&key.PrivateKey)
|
|
|
|
prmTree.SetKey(key)
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Info(logs.UsingCredentials, zap.String("FrostFS", hex.EncodeToString(key.PublicKey().Bytes())))
|
2023-06-09 06:39:01 +00:00
|
|
|
|
|
|
|
for _, peer := range fetchPeers(logger, cfg) {
|
|
|
|
prm.AddNode(peer)
|
|
|
|
prmTree.AddNode(peer)
|
|
|
|
}
|
|
|
|
|
|
|
|
connTimeout := cfg.GetDuration(cfgConTimeout)
|
|
|
|
if connTimeout <= 0 {
|
|
|
|
connTimeout = defaultConnectTimeout
|
|
|
|
}
|
|
|
|
prm.SetNodeDialTimeout(connTimeout)
|
|
|
|
prmTree.SetNodeDialTimeout(connTimeout)
|
|
|
|
|
|
|
|
streamTimeout := cfg.GetDuration(cfgStreamTimeout)
|
|
|
|
if streamTimeout <= 0 {
|
|
|
|
streamTimeout = defaultStreamTimeout
|
|
|
|
}
|
|
|
|
prm.SetNodeStreamTimeout(streamTimeout)
|
|
|
|
prmTree.SetNodeStreamTimeout(streamTimeout)
|
|
|
|
|
|
|
|
healthCheckTimeout := cfg.GetDuration(cfgReqTimeout)
|
|
|
|
if healthCheckTimeout <= 0 {
|
|
|
|
healthCheckTimeout = defaultRequestTimeout
|
|
|
|
}
|
|
|
|
prm.SetHealthcheckTimeout(healthCheckTimeout)
|
|
|
|
prmTree.SetHealthcheckTimeout(healthCheckTimeout)
|
|
|
|
|
|
|
|
rebalanceInterval := cfg.GetDuration(cfgRebalance)
|
|
|
|
if rebalanceInterval <= 0 {
|
|
|
|
rebalanceInterval = defaultRebalanceTimer
|
|
|
|
}
|
|
|
|
prm.SetClientRebalanceInterval(rebalanceInterval)
|
|
|
|
prmTree.SetClientRebalanceInterval(rebalanceInterval)
|
|
|
|
|
|
|
|
errorThreshold := cfg.GetUint32(cfgPoolErrorThreshold)
|
|
|
|
if errorThreshold <= 0 {
|
|
|
|
errorThreshold = defaultPoolErrorThreshold
|
|
|
|
}
|
|
|
|
prm.SetErrorThreshold(errorThreshold)
|
|
|
|
prm.SetLogger(logger)
|
|
|
|
prmTree.SetLogger(logger)
|
|
|
|
|
2023-11-07 08:07:27 +00:00
|
|
|
prmTree.SetMaxRequestAttempts(cfg.GetInt(cfgTreePoolMaxAttempts))
|
|
|
|
|
2024-10-21 08:39:14 +00:00
|
|
|
interceptors := []grpc.DialOption{
|
|
|
|
grpc.WithUnaryInterceptor(grpctracing.NewUnaryClientInteceptor()),
|
|
|
|
grpc.WithStreamInterceptor(grpctracing.NewStreamClientInterceptor()),
|
2024-10-29 11:41:49 +00:00
|
|
|
grpc.WithContextDialer(dialSource.GrpcContextDialer()),
|
2023-06-14 08:27:33 +00:00
|
|
|
}
|
2024-10-21 08:39:14 +00:00
|
|
|
prm.SetGRPCDialOptions(interceptors...)
|
|
|
|
prmTree.SetGRPCDialOptions(interceptors...)
|
2023-06-14 08:27:33 +00:00
|
|
|
|
2023-06-09 06:39:01 +00:00
|
|
|
p, err := pool.NewPool(prm)
|
|
|
|
if err != nil {
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Fatal(logs.FailedToCreateConnectionPool, zap.Error(err))
|
2023-06-09 06:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = p.Dial(ctx); err != nil {
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Fatal(logs.FailedToDialConnectionPool, zap.Error(err))
|
2023-06-09 06:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
treePool, err := treepool.NewPool(prmTree)
|
|
|
|
if err != nil {
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Fatal(logs.FailedToCreateTreePool, zap.Error(err))
|
2023-06-09 06:39:01 +00:00
|
|
|
}
|
|
|
|
if err = treePool.Dial(ctx); err != nil {
|
2023-08-27 15:09:02 +00:00
|
|
|
logger.Fatal(logs.FailedToDialTreePool, zap.Error(err))
|
2023-06-09 06:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return p, treePool, key
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchPeers(l *zap.Logger, v *viper.Viper) []pool.NodeParam {
|
|
|
|
var nodes []pool.NodeParam
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
key := cfgPeers + "." + strconv.Itoa(i) + "."
|
|
|
|
address := v.GetString(key + "address")
|
|
|
|
weight := v.GetFloat64(key + "weight")
|
|
|
|
priority := v.GetInt(key + "priority")
|
|
|
|
|
|
|
|
if address == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if weight <= 0 { // unspecified or wrong
|
|
|
|
weight = 1
|
|
|
|
}
|
|
|
|
if priority <= 0 { // unspecified or wrong
|
|
|
|
priority = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes = append(nodes, pool.NewNodeParam(priority, address, weight))
|
|
|
|
|
2023-08-27 15:09:02 +00:00
|
|
|
l.Info(logs.AddedStoragePeer,
|
2023-06-09 06:39:01 +00:00
|
|
|
zap.Int("priority", priority),
|
|
|
|
zap.String("address", address),
|
|
|
|
zap.Float64("weight", weight))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|
2023-08-31 16:19:57 +00:00
|
|
|
|
|
|
|
func fetchSoftMemoryLimit(cfg *viper.Viper) int64 {
|
|
|
|
softMemoryLimit := cfg.GetSizeInBytes(cfgSoftMemoryLimit)
|
|
|
|
if softMemoryLimit <= 0 {
|
|
|
|
softMemoryLimit = defaultSoftMemoryLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
return int64(softMemoryLimit)
|
|
|
|
}
|
2023-10-04 11:50:37 +00:00
|
|
|
|
|
|
|
func getCacheOptions(v *viper.Viper, l *zap.Logger) *cache.Config {
|
|
|
|
cacheCfg := cache.DefaultBucketConfig(l)
|
|
|
|
|
|
|
|
cacheCfg.Lifetime = fetchCacheLifetime(v, l, cfgBucketsCacheLifetime, cacheCfg.Lifetime)
|
|
|
|
cacheCfg.Size = fetchCacheSize(v, l, cfgBucketsCacheSize, cacheCfg.Size)
|
|
|
|
|
|
|
|
return cacheCfg
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-06 13:14:09 +00:00
|
|
|
l.Error(logs.InvalidLifetimeUsingDefaultValue,
|
2023-10-04 11:50:37 +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-10-06 13:14:09 +00:00
|
|
|
l.Error(logs.InvalidCacheSizeUsingDefaultValue,
|
2023-10-04 11:50:37 +00:00
|
|
|
zap.String("parameter", cfgEntry),
|
|
|
|
zap.Int("value in config", size),
|
|
|
|
zap.Int("default", defaultValue))
|
|
|
|
} else {
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
}
|
2024-10-29 11:41:49 +00:00
|
|
|
|
|
|
|
func getDialerSource(logger *zap.Logger, cfg *viper.Viper) *internalnet.DialerSource {
|
|
|
|
source, err := internalnet.NewDialerSource(fetchMultinetConfig(cfg, logger))
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal(logs.FailedToLoadMultinetConfig, zap.Error(err))
|
|
|
|
}
|
|
|
|
return source
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchMultinetConfig(v *viper.Viper, l *zap.Logger) (cfg internalnet.Config) {
|
|
|
|
cfg.Enabled = v.GetBool(cfgMultinetEnabled)
|
|
|
|
cfg.Balancer = v.GetString(cfgMultinetBalancer)
|
|
|
|
cfg.Restrict = v.GetBool(cfgMultinetRestrict)
|
|
|
|
cfg.FallbackDelay = v.GetDuration(cfgMultinetFallbackDelay)
|
|
|
|
cfg.Subnets = make([]internalnet.Subnet, 0, 5)
|
|
|
|
cfg.EventHandler = internalnet.NewLogEventHandler(l)
|
|
|
|
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
key := cfgMultinetSubnets + "." + strconv.Itoa(i) + "."
|
|
|
|
subnet := internalnet.Subnet{}
|
|
|
|
|
|
|
|
subnet.Prefix = v.GetString(key + "mask")
|
|
|
|
if subnet.Prefix == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
subnet.SourceIPs = v.GetStringSlice(key + "source_ips")
|
|
|
|
cfg.Subnets = append(cfg.Subnets, subnet)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2024-11-15 07:53:46 +00:00
|
|
|
|
|
|
|
func fetchTracingAttributes(v *viper.Viper) (map[string]string, error) {
|
|
|
|
attributes := make(map[string]string)
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
key := cfgTracingAttributes + "." + strconv.Itoa(i) + "."
|
|
|
|
attrKey := v.GetString(key + "key")
|
|
|
|
attrValue := v.GetString(key + "value")
|
|
|
|
if attrKey == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := attributes[attrKey]; ok {
|
|
|
|
return nil, fmt.Errorf("tracing attribute key %s defined more than once", attrKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
if attrValue == "" {
|
|
|
|
return nil, fmt.Errorf("empty tracing attribute value for key %s", attrKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes[attrKey] = attrValue
|
|
|
|
}
|
|
|
|
|
|
|
|
return attributes, nil
|
|
|
|
}
|