Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag & toml config for gRPC server #6933

Merged
merged 10 commits into from
Aug 5, 2020
7 changes: 5 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,8 +148,8 @@ func DefaultConfig() *Config {
RPCMaxBodyBytes: 1000000,
},
GRPC: GRPCConfig{
Enable: false,
Address: "0.0.0.0:9090",
Enable: true,
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
Address: DefaultGRPCAddress,
},
}
}
Expand Down
32 changes: 22 additions & 10 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ 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,
# an in-memory sink is also enabled by default. Operators may also enabled
# 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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ func (n *Network) Cleanup() {
if v.api != nil {
_ = v.api.Close()
}

if v.grpc != nil {
v.grpc.Stop()
}
}

if n.Config.CleanupDir {
Expand Down