forked from TrueCloudLab/frostfs-http-gw
Merge pull request #5 from nspcc-dev/prepare-to-release
Prepare to release
This commit is contained in:
commit
b6a9654546
7 changed files with 90 additions and 89 deletions
|
@ -18,7 +18,7 @@ RUN set -x \
|
|||
-v \
|
||||
-mod=vendor \
|
||||
-trimpath \
|
||||
-ldflags "${LDFLAGS} -X main.Build=$(date -u +%s%N) -X main.Prefix=HTTP_GW" \
|
||||
-ldflags "${LDFLAGS} -X main.Build=$(date -u +%s%N)" \
|
||||
-o /go/bin/neofs-gw ./ \
|
||||
&& upx -3 /go/bin/neofs-gw
|
||||
|
||||
|
|
38
README.md
38
README.md
|
@ -24,21 +24,31 @@ You can download files from NeoFS Network using NeoFS Gate.
|
|||
|
||||
# Environments:
|
||||
|
||||
GW_KEY=stirng - "generated" to generate key, path to private key file, hex string or wif (default "generated")
|
||||
GW_REQUEST_TIMEOUT=Duration - timeout for request
|
||||
GW_CONNECT_TIMEOUT=Duration - timeout for connection
|
||||
GW_LISTEN_ADDRESS=host:port - address to listen connections
|
||||
GW_PEERS_<X>_ADDRESS=host:port - address of NeoFS Node
|
||||
GW_PEERS_<X>_WEIGHT=float - weight of NeoFS Node
|
||||
GW_PPROF=bool - enable/disable pprof (/debug/pprof)
|
||||
GW_METRICS=bool - enable/disable prometheus metrics endpoint (/metrics)
|
||||
GW_KEEPALIVE_TIME=Duration - аfter a duration of this time if the client doesn't see any activity
|
||||
HTTP_GW_KEY=string - "generated" to generate key, path to private key file, hex string or wif (default "generated")
|
||||
HTTP_GW_CONNECT_TIMEOUT=Duration - timeout for connection
|
||||
HTTP_GW_REQUEST_TIMEOUT=Duration - timeout for request
|
||||
HTTP_GW_REBALANCE_TIMER=Duration - time between connections checks
|
||||
HTTP_GW_LISTEN_ADDRESS=host:port - address to listen connections
|
||||
HTTP_GW_PEERS_<X>_ADDRESS=host:port - address of NeoFS Node
|
||||
HTTP_GW_PEERS_<X>_WEIGHT=float - weight of NeoFS Node
|
||||
HTTP_GW_PPROF=bool - enable/disable pprof (/debug/pprof)
|
||||
HTTP_GW_METRICS=bool - enable/disable prometheus metrics endpoint (/metrics)
|
||||
HTTP_GW_LOGGER_FORMAT=string - logger format
|
||||
HTTP_GW_LOGGER_LEVEL=string - logger level
|
||||
HTTP_GW_LOGGER_NO_CALLER=bool - logger don't show caller
|
||||
HTTP_GW_LOGGER_NO_DISCLAIMER=bool - logger don't show application name/version
|
||||
HTTP_GW_LOGGER_SAMPLING_INITIAL=int - logger sampling initial
|
||||
HTTP_GW_LOGGER_SAMPLING_THEREAFTER=int - logger sampling thereafter
|
||||
HTTP_GW_LOGGER_TRACE_LEVEL=string - logger show trace on level
|
||||
HTTP_GW_KEEPALIVE_TIME=Duration - аfter a duration of this time if the client doesn't see any activity
|
||||
it pings the server to see if the transport is still alive.
|
||||
GW_KEEPALIVE_TIMEOUT=Duration - after having pinged for keepalive check, the client waits for a duration
|
||||
HTTP_GW_KEEPALIVE_TIMEOUT=Duration - after having pinged for keepalive check, the client waits for a duration
|
||||
of Timeout and if no activity is seen even after that the connection is closed
|
||||
GW_KEEPALIVE_PERMIT_WITHOUT_STREAM=Bool - if true, client sends keepalive pings even with no active RPCs.
|
||||
HTTP_GW_KEEPALIVE_PERMIT_WITHOUT_STREAM=Bool - if true, client sends keepalive pings even with no active RPCs.
|
||||
If false, when there are no active RPCs, Time and Timeout will be ignored and no keepalive pings will be sent.
|
||||
```
|
||||
|
||||
### WARNING
|
||||
`generated` value for `GW_KEY` or `--key` is deprecated, you should use pre-generated keys.
|
||||
Peers preset:
|
||||
|
||||
HTTP_GW_PEERS_[N]_ADDRESS = string
|
||||
HTTP_GW_PEERS_[N]_WEIGHT = 0..1 (float)
|
||||
```
|
57
app.go
57
app.go
|
@ -3,8 +3,6 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"strconv"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
|
@ -12,7 +10,6 @@ import (
|
|||
"github.com/nspcc-dev/cdn-neofs-sdk/creds/neofs"
|
||||
"github.com/nspcc-dev/cdn-neofs-sdk/logger"
|
||||
"github.com/nspcc-dev/cdn-neofs-sdk/pool"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/valyala/fasthttp"
|
||||
"go.uber.org/zap"
|
||||
|
@ -79,20 +76,20 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
|
||||
a.wlog = logger.GRPC(a.log)
|
||||
|
||||
if a.cfg.GetBool("verbose") {
|
||||
if a.cfg.GetBool(cmdVerbose) {
|
||||
grpclog.SetLoggerV2(a.wlog)
|
||||
}
|
||||
|
||||
conTimeout := a.cfg.GetDuration("connect_timeout")
|
||||
reqTimeout := a.cfg.GetDuration("request_timeout")
|
||||
tckTimeout := a.cfg.GetDuration("rebalance_timer")
|
||||
conTimeout := a.cfg.GetDuration(cfgConTimeout)
|
||||
reqTimeout := a.cfg.GetDuration(cfgReqTimeout)
|
||||
tckTimeout := a.cfg.GetDuration(cfgRebalance)
|
||||
|
||||
// -- setup FastHTTP server: --
|
||||
a.web.Name = "neofs-http-gate"
|
||||
a.web.ReadBufferSize = a.cfg.GetInt("web.read_buffer_size")
|
||||
a.web.WriteBufferSize = a.cfg.GetInt("web.write_buffer_size")
|
||||
a.web.ReadTimeout = a.cfg.GetDuration("web.read_timeout")
|
||||
a.web.WriteTimeout = a.cfg.GetDuration("web.write_timeout")
|
||||
a.web.ReadBufferSize = a.cfg.GetInt(cfgWebReadBufferSize)
|
||||
a.web.WriteBufferSize = a.cfg.GetInt(cfgWebWriteBufferSize)
|
||||
a.web.ReadTimeout = a.cfg.GetDuration(cfgWebReadTimeout)
|
||||
a.web.WriteTimeout = a.cfg.GetDuration(cfgWebWriteTimeout)
|
||||
a.web.GetOnly = true
|
||||
a.web.DisableHeaderNamesNormalizing = true
|
||||
a.web.NoDefaultServerHeader = true
|
||||
|
@ -101,8 +98,8 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
|
||||
connections := make(map[string]float64)
|
||||
for i := 0; ; i++ {
|
||||
address := a.cfg.GetString("peers." + strconv.Itoa(i) + ".address")
|
||||
weight := a.cfg.GetFloat64("peers." + strconv.Itoa(i) + ".weight")
|
||||
address := a.cfg.GetString(cfgPeers + "." + strconv.Itoa(i) + ".address")
|
||||
weight := a.cfg.GetFloat64(cfgPeers + "." + strconv.Itoa(i) + ".weight")
|
||||
if address == "" {
|
||||
break
|
||||
}
|
||||
|
@ -113,7 +110,7 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
zap.Float64("weight", weight))
|
||||
}
|
||||
|
||||
cred, err := prepareCredentials(a.cfg.GetString("key"), a.log)
|
||||
cred, err := neofs.New(a.cfg.GetString(cmdNeoFSKey))
|
||||
if err != nil {
|
||||
a.log.Fatal("could not prepare credentials", zap.Error(err))
|
||||
}
|
||||
|
@ -130,9 +127,9 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
grpc.WithBlock(),
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
||||
Time: a.cfg.GetDuration("keepalive.time"),
|
||||
Timeout: a.cfg.GetDuration("keepalive.timeout"),
|
||||
PermitWithoutStream: a.cfg.GetBool("keepalive.permit_without_stream"),
|
||||
Time: a.cfg.GetDuration(cfgKeepaliveTime),
|
||||
Timeout: a.cfg.GetDuration(cfgKeepaliveTimeout),
|
||||
PermitWithoutStream: a.cfg.GetBool(cfgKeepalivePermitWithoutStream),
|
||||
})))
|
||||
|
||||
if err != nil {
|
||||
|
@ -151,26 +148,6 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
return a
|
||||
}
|
||||
|
||||
func prepareCredentials(key string, log *zap.Logger) (neofs.Credentials, error) {
|
||||
if key == generated {
|
||||
log.Fatal("Don't use generated key, deprecated")
|
||||
|
||||
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, err = crypto.WIFEncode(sk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Info("generate new key", zap.String("wif", key))
|
||||
}
|
||||
|
||||
return neofs.New(key)
|
||||
}
|
||||
|
||||
func (a *app) Wait() {
|
||||
a.log.Info("application started")
|
||||
|
||||
|
@ -204,18 +181,18 @@ func (a *app) Serve(ctx context.Context) {
|
|||
attachHealthy(r, a.pool.Status)
|
||||
|
||||
// enable metrics
|
||||
if a.cfg.GetBool("metrics") {
|
||||
if a.cfg.GetBool(cmdMetrics) {
|
||||
a.log.Info("enabled /metrics/")
|
||||
attachMetrics(r, a.wlog)
|
||||
}
|
||||
|
||||
// enable pprof
|
||||
if a.cfg.GetBool("pprof") {
|
||||
if a.cfg.GetBool(cmdPprof) {
|
||||
a.log.Info("enabled /debug/pprof/")
|
||||
attachProfiler(r)
|
||||
}
|
||||
|
||||
bind := a.cfg.GetString("listen_address")
|
||||
bind := a.cfg.GetString(cfgListenAddress)
|
||||
a.log.Info("run gateway server",
|
||||
zap.String("address", bind))
|
||||
|
||||
|
|
5
go.mod
5
go.mod
|
@ -4,9 +4,8 @@ go 1.13
|
|||
|
||||
require (
|
||||
github.com/fasthttp/router v1.3.3
|
||||
github.com/nspcc-dev/cdn-neofs-sdk v0.0.0
|
||||
github.com/nspcc-dev/cdn-neofs-sdk v0.1.0
|
||||
github.com/nspcc-dev/neofs-api-go v1.20.3
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.8.0
|
||||
github.com/prometheus/common v0.15.0
|
||||
|
@ -16,5 +15,3 @@ require (
|
|||
go.uber.org/zap v1.16.0
|
||||
google.golang.org/grpc v1.33.2
|
||||
)
|
||||
|
||||
replace github.com/nspcc-dev/cdn-neofs-sdk => ../sdk
|
||||
|
|
2
go.sum
2
go.sum
|
@ -292,6 +292,8 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE
|
|||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/nspcc-dev/cdn-neofs-sdk v0.1.0 h1:nexBQL32WeQC2mvVMiWlOqI2enKcIJlFyxejU1FeBNo=
|
||||
github.com/nspcc-dev/cdn-neofs-sdk v0.1.0/go.mod h1:ujzmbHoxhuyY4SgHUDSwtfZQNHu06izC4xOkPj+YziY=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191205084618-dacb1a30c254/go.mod h1:w1Ln2aT+dBlPhLnuZhBV+DfPEdS2CHWWLp5JTScY3bw=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA51EGfb5GS/HOv7VdmngNRTssSeQ729dvGY=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk=
|
||||
|
|
5
misc.go
5
misc.go
|
@ -1,9 +1,8 @@
|
|||
package main
|
||||
|
||||
const Prefix = "HTTP_GW"
|
||||
|
||||
var (
|
||||
Build = "now"
|
||||
Version = "dev"
|
||||
|
||||
// TODO should be replaced with HTTP_GW
|
||||
Prefix = "GW"
|
||||
)
|
||||
|
|
66
settings.go
66
settings.go
|
@ -19,10 +19,6 @@ const (
|
|||
devNull = empty(0)
|
||||
generated = "generated"
|
||||
|
||||
minimumTTLInMinutes = 5
|
||||
|
||||
defaultTTL = minimumTTLInMinutes * time.Minute
|
||||
|
||||
defaultRebalanceTimer = 15 * time.Second
|
||||
defaultRequestTimeout = 15 * time.Second
|
||||
defaultConnectTimeout = 30 * time.Second
|
||||
|
@ -30,6 +26,25 @@ const (
|
|||
defaultKeepaliveTime = 10 * time.Second
|
||||
defaultKeepaliveTimeout = 10 * time.Second
|
||||
|
||||
cfgListenAddress = "listen_address"
|
||||
|
||||
// KeepAlive
|
||||
cfgKeepaliveTime = "keepalive.time"
|
||||
cfgKeepaliveTimeout = "keepalive.timeout"
|
||||
cfgKeepalivePermitWithoutStream = "keepalive.permit_without_stream"
|
||||
|
||||
// Web
|
||||
cfgWebReadBufferSize = "web.read_buffer_size"
|
||||
cfgWebWriteBufferSize = "web.write_buffer_size"
|
||||
cfgWebReadTimeout = "web.read_timeout"
|
||||
cfgWebWriteTimeout = "web.write_timeout"
|
||||
cfgWebConnectionPerHost = "web.connection_per_host"
|
||||
|
||||
// Timeouts
|
||||
cfgConTimeout = "connect_timeout"
|
||||
cfgReqTimeout = "request_timeout"
|
||||
cfgRebalance = "rebalance_timer"
|
||||
|
||||
// Logger:
|
||||
cfgLoggerLevel = "logger.level"
|
||||
cfgLoggerFormat = "logger.format"
|
||||
|
@ -50,6 +65,10 @@ const (
|
|||
// command line args
|
||||
cmdHelp = "help"
|
||||
cmdVersion = "version"
|
||||
cmdVerbose = "verbose"
|
||||
cmdPprof = "pprof"
|
||||
cmdMetrics = "metrics"
|
||||
cmdNeoFSKey = "key"
|
||||
)
|
||||
|
||||
var ignore = map[string]struct{}{
|
||||
|
@ -74,25 +93,24 @@ func settings() *viper.Viper {
|
|||
|
||||
// flags setup:
|
||||
flags := pflag.NewFlagSet("commandline", pflag.ExitOnError)
|
||||
flags.SetOutput(os.Stdout)
|
||||
flags.SortFlags = false
|
||||
|
||||
flags.Bool("pprof", false, "enable pprof")
|
||||
flags.Bool("metrics", false, "enable prometheus")
|
||||
flags.Bool(cmdPprof, false, "enable pprof")
|
||||
flags.Bool(cmdMetrics, false, "enable prometheus")
|
||||
|
||||
help := flags.BoolP(cmdHelp, "h", false, "show help")
|
||||
version := flags.BoolP(cmdVersion, "v", false, "show version")
|
||||
|
||||
flags.String("key", generated, `"`+generated+`" to generate key, path to private key file, hex string or wif`)
|
||||
flags.String(cmdNeoFSKey, "", `"Path to private key file, hex string or wif`)
|
||||
|
||||
flags.Bool("verbose", false, "debug gRPC connections")
|
||||
flags.Duration("request_timeout", defaultRequestTimeout, "gRPC request timeout")
|
||||
flags.Duration("connect_timeout", defaultConnectTimeout, "gRPC connect timeout")
|
||||
flags.Duration("rebalance_timer", defaultRebalanceTimer, "gRPC connection rebalance timer")
|
||||
flags.Bool(cmdVerbose, false, "debug gRPC connections")
|
||||
flags.Duration(cfgConTimeout, defaultConnectTimeout, "gRPC connect timeout")
|
||||
flags.Duration(cfgReqTimeout, defaultRequestTimeout, "gRPC request timeout")
|
||||
flags.Duration(cfgRebalance, defaultRebalanceTimer, "gRPC connection rebalance timer")
|
||||
|
||||
ttl := flags.DurationP("conn_ttl", "t", defaultTTL, "gRPC connection time to live")
|
||||
|
||||
flags.String("listen_address", "0.0.0.0:8082", "HTTP Gateway listen address")
|
||||
peers := flags.StringArrayP("peers", "p", nil, "NeoFS nodes")
|
||||
flags.String(cfgListenAddress, "0.0.0.0:8082", "HTTP Gateway listen address")
|
||||
peers := flags.StringArrayP(cfgPeers, "p", nil, "NeoFS nodes")
|
||||
|
||||
// set prefers:
|
||||
v.Set(cfgApplicationName, "neofs-http-gw")
|
||||
|
@ -111,16 +129,16 @@ func settings() *viper.Viper {
|
|||
|
||||
// keepalive:
|
||||
// If set below 10s, a minimum value of 10s will be used instead.
|
||||
v.SetDefault("keepalive.time", defaultKeepaliveTime)
|
||||
v.SetDefault("keepalive.timeout", defaultKeepaliveTimeout)
|
||||
v.SetDefault("keepalive.permit_without_stream", true)
|
||||
v.SetDefault(cfgKeepaliveTime, defaultKeepaliveTime)
|
||||
v.SetDefault(cfgKeepaliveTimeout, defaultKeepaliveTimeout)
|
||||
v.SetDefault(cfgKeepalivePermitWithoutStream, true)
|
||||
|
||||
// web-server:
|
||||
v.SetDefault("web.read_buffer_size", 4096)
|
||||
v.SetDefault("web.write_buffer_size", 4096)
|
||||
v.SetDefault("web.read_timeout", time.Second*15)
|
||||
v.SetDefault("web.write_timeout", time.Minute)
|
||||
v.SetDefault("web.connection_per_host", 10)
|
||||
v.SetDefault(cfgWebReadBufferSize, 4096)
|
||||
v.SetDefault(cfgWebWriteBufferSize, 4096)
|
||||
v.SetDefault(cfgWebReadTimeout, time.Second*15)
|
||||
v.SetDefault(cfgWebWriteTimeout, time.Minute)
|
||||
v.SetDefault(cfgWebConnectionPerHost, 10)
|
||||
|
||||
if err := v.BindPFlags(flags); err != nil {
|
||||
panic(err)
|
||||
|
@ -165,8 +183,6 @@ func settings() *viper.Viper {
|
|||
case version != nil && *version:
|
||||
fmt.Printf("NeoFS HTTP Gateway %s (%s)\n", Version, Build)
|
||||
os.Exit(0)
|
||||
case ttl != nil && ttl.Minutes() < minimumTTLInMinutes:
|
||||
fmt.Printf("connection ttl should not be less than %s", defaultTTL)
|
||||
}
|
||||
|
||||
if peers != nil && len(*peers) > 0 {
|
||||
|
|
Loading…
Reference in a new issue