Add flag & toml config for gRPC server (#6933)

* Enable gRPC by default

* Add grpc flags

* Consistent comments in toml

* Stop grpc in test network cleaup

* Expose ports on Docker

* Fix tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Amaury Martiny 2020-08-05 17:45:22 +02:00 committed by GitHub
parent dfa0642fdc
commit d2661a4692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 19 deletions

View File

@ -38,7 +38,7 @@ WORKDIR /root
# Copy over binaries from the build-env
COPY --from=build-env /go/bin/simd /usr/bin/simd
EXPOSE 26656 26657 1317
EXPOSE 26656 26657 1317 9090
# Run simd by default, omit entrypoint to ease using container with simcli
CMD ["simd"]

View File

@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
simdnode0:
@ -7,6 +7,7 @@ services:
ports:
- "26656-26657:26656-26657"
- "1317:1317"
- "9090:9090"
environment:
- ID=0
- LOG=${LOG:-simd.log}
@ -22,6 +23,7 @@ services:
ports:
- "26659-26660:26656-26657"
- "1318:1317"
- "9090:9090"
environment:
- ID=1
- LOG=${LOG:-simd.log}
@ -40,6 +42,7 @@ services:
ports:
- "26661-26662:26656-26657"
- "1319:1317"
- "9090:9090"
volumes:
- ./build:/simd:Z
networks:
@ -55,6 +58,7 @@ services:
ports:
- "26663-26664:26656-26657"
- "1320:1317"
- "9090:9090"
volumes:
- ./build:/simd:Z
networks:
@ -67,5 +71,4 @@ networks:
ipam:
driver: default
config:
-
subnet: 192.168.10.0/16
- subnet: 192.168.10.0/16

View File

@ -13,6 +13,9 @@ import (
const (
defaultMinGasPrices = ""
// DefaultGRPCAddress is the default address the gRPC server binds to.
DefaultGRPCAddress = "0.0.0.0:9090"
)
// BaseConfig defines the server's basic configuration
@ -145,8 +148,8 @@ func DefaultConfig() *Config {
RPCMaxBodyBytes: 1000000,
},
GRPC: GRPCConfig{
Enable: false,
Address: "0.0.0.0:9090",
Enable: true,
Address: DefaultGRPCAddress,
},
}
}

View File

@ -53,7 +53,7 @@ inter-block-cache = {{ .BaseConfig.InterBlockCache }}
[telemetry]
# Prefixed with keys to separate services
# Prefixed with keys to separate services.
service-name = "{{ .Telemetry.ServiceName }}"
# Enabled enables the application telemetry functionality. When enabled,
@ -61,13 +61,13 @@ service-name = "{{ .Telemetry.ServiceName }}"
# other sinks such as Prometheus.
enabled = {{ .Telemetry.Enabled }}
# Enable prefixing gauge values with hostname
# Enable prefixing gauge values with hostname.
enable-hostname = {{ .Telemetry.EnableHostname }}
# Enable adding hostname to labels
# Enable adding hostname to labels.
enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }}
# Enable adding service to labels
# Enable adding service to labels.
enable-service-label = {{ .Telemetry.EnableServiceLabel }}
# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink.
@ -94,23 +94,35 @@ enable = {{ .API.Enable }}
# Swagger defines if swagger documentation should automatically be registered.
swagger = {{ .API.Swagger }}
# Address defines the API server to listen on
# Address defines the API server to listen on.
address = "{{ .API.Address }}"
# MaxOpenConnections defines the number of maximum open connections
# MaxOpenConnections defines the number of maximum open connections.
max-open-connections = {{ .API.MaxOpenConnections }}
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds)
# RPCReadTimeout defines the Tendermint RPC read timeout (in seconds).
rpc-read-timeout = {{ .API.RPCReadTimeout }}
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds)
# RPCWriteTimeout defines the Tendermint RPC write timeout (in seconds).
rpc-write-timeout = {{ .API.RPCWriteTimeout }}
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes)
# RPCMaxBodyBytes defines the Tendermint maximum response body (in bytes).
rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }}
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }}
###############################################################################
### gRPC Configuration ###
###############################################################################
[grpc]
# Enable defines if the gRPC server should be enabled.
enable = {{ .GRPC.Enable }}
# Address defines the gRPC server address to bind to.
address = "{{ .GRPC.Address }}"
`
var configTemplate *template.Template

View File

@ -68,7 +68,7 @@ func (s *IntegrationTestSuite) TestGRPC() {
*bankRes.GetBalance(),
)
blockHeight := header.Get(servergrpc.GRPCBlockHeightHeader)
s.Require().NotEqual("", blockHeight[0]) // Should contain the block height
s.Require().NotEmpty(blockHeight[0]) // Should contain the block height
// Request metadata should work
bankRes, err = bankClient.Balance(

View File

@ -50,6 +50,12 @@ const (
FlagPruningInterval = "pruning-interval"
)
// GRPC-related flags.
const (
flagGRPCEnable = "grpc.enable"
flagGRPCAddress = "grpc.address"
)
// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
func StartCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
@ -123,6 +129,9 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")
cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled")
cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on")
// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
return cmd

View File

@ -193,10 +193,11 @@ func New(t *testing.T, cfg Config) *Network {
tmCfg := ctx.Config
tmCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit
// Only allow the first validator to expose an RPC and API server/client
// due to Tendermint in-process constraints.
// Only allow the first validator to expose an RPC, API and gRPC
// server/client due to Tendermint in-process constraints.
apiAddr := ""
tmCfg.RPC.ListenAddress = ""
appCfg.GRPC.Enable = false
if i == 0 {
apiListenAddr, _, err := server.FreeTCPAddr()
require.NoError(t, err)
@ -439,6 +440,10 @@ func (n *Network) Cleanup() {
if v.api != nil {
_ = v.api.Close()
}
if v.grpc != nil {
v.grpc.Stop()
}
}
if n.Config.CleanupDir {