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

RCHAIN-4089: Add configs for api server #2933

Merged
merged 2 commits into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions node/src/main/resources/defaults.conf
Expand Up @@ -123,6 +123,27 @@ api-server {

# Enable reporting API
enable-reporting = false

# Sets a custom keepalive time, the delay time for sending next keepalive ping
keep-alive-time = 2 hours
tgrospic marked this conversation as resolved.
Show resolved Hide resolved

# Sets a custom keepalive timeout, the timeout for keepalive ping requests
keep-alive-timeout = 20 seconds

# The most aggressive keep-alive time clients are permitted to configure.
# The server would close the connection if clients exceeding this rate
permit-keep-alive-time = 5 minutes

# Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated
max-connection-idle = 1 hours

# Sets a custom max connection age, connection lasting longer than which will be gracefully terminated
max-connection-age = 1 hours

# Sets a custom grace time for the graceful connection termination. Once the max connection age
# is reached, RPCs have the grace time to complete. RPCs that do not complete in time will be
# cancelled, allowing the connection to terminate
max-connection-age-grace = 1 hours
}

storage {
Expand Down
16 changes: 14 additions & 2 deletions node/src/main/scala/coop/rchain/node/NodeRuntime.scala
Expand Up @@ -566,7 +566,13 @@ class NodeRuntime private[node] (
nodeConf.apiServer.portGrpcExternal,
grpcScheduler,
apiServers.deploy,
nodeConf.apiServer.grpcMaxRecvMessageSize.toInt
nodeConf.apiServer.grpcMaxRecvMessageSize.toInt,
nodeConf.apiServer.keepAliveTime,
nodeConf.apiServer.keepAliveTimeout,
nodeConf.apiServer.permitKeepAliveTime,
nodeConf.apiServer.maxConnectionIdle,
nodeConf.apiServer.maxConnectionAge,
nodeConf.apiServer.maxConnectionAgeGrace
)
internalApiServer <- api
.acquireInternalServer(
Expand All @@ -576,7 +582,13 @@ class NodeRuntime private[node] (
apiServers.repl,
apiServers.deploy,
apiServers.propose,
nodeConf.apiServer.grpcMaxRecvMessageSize.toInt
nodeConf.apiServer.grpcMaxRecvMessageSize.toInt,
nodeConf.apiServer.keepAliveTime,
nodeConf.apiServer.keepAliveTimeout,
nodeConf.apiServer.permitKeepAliveTime,
nodeConf.apiServer.maxConnectionIdle,
nodeConf.apiServer.maxConnectionAge,
nodeConf.apiServer.maxConnectionAgeGrace
)

prometheusReporter = new NewPrometheusReporter()
Expand Down
31 changes: 29 additions & 2 deletions node/src/main/scala/coop/rchain/node/api/package.scala
@@ -1,6 +1,7 @@
package coop.rchain.node

import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit

import cats.effect.Concurrent
import coop.rchain.casper.protocol.deploy.v1.DeployServiceV1GrpcMonix
Expand All @@ -15,6 +16,8 @@ import io.netty.channel.local.LocalAddress
import monix.eval.Task
import monix.execution.Scheduler

import scala.concurrent.duration.FiniteDuration

package object api {

def acquireInternalServer(
Expand All @@ -24,7 +27,13 @@ package object api {
replGrpcService: ReplGrpcMonix.Repl,
deployGrpcService: DeployServiceV1GrpcMonix.DeployService,
proposeGrpcService: ProposeServiceV1GrpcMonix.ProposeService,
maxMessageSize: Int
maxMessageSize: Int,
keepAliveTime: FiniteDuration,
keepAliveTimeout: FiniteDuration,
permitKeepAliveTime: FiniteDuration,
maxConnectionIdle: FiniteDuration,
maxConnectionAge: FiniteDuration,
maxConnectionAgeGrace: FiniteDuration
): Task[Server[Task]] =
GrpcServer[Task](
NettyServerBuilder
Expand All @@ -42,6 +51,12 @@ package object api {
DeployServiceV1GrpcMonix
.bindService(deployGrpcService, grpcExecutor)
)
.keepAliveTime(keepAliveTime.length, keepAliveTime.unit)
.keepAliveTimeout(keepAliveTimeout.length, keepAliveTimeout.unit)
.permitKeepAliveTime(permitKeepAliveTime.length, permitKeepAliveTime.unit)
.maxConnectionIdle(maxConnectionIdle.length, maxConnectionIdle.unit)
.maxConnectionAge(maxConnectionAge.length, maxConnectionAge.unit)
.maxConnectionAgeGrace(maxConnectionAgeGrace.length, maxConnectionAgeGrace.unit)
.addService(ProtoReflectionService.newInstance())
.compressorRegistry(null)
.build
Expand All @@ -52,7 +67,13 @@ package object api {
port: Int,
grpcExecutor: Scheduler,
deployGrpcService: DeployServiceV1GrpcMonix.DeployService,
maxMessageSize: Int
maxMessageSize: Int,
keepAliveTime: FiniteDuration,
keepAliveTimeout: FiniteDuration,
permitKeepAliveTime: FiniteDuration,
maxConnectionIdle: FiniteDuration,
maxConnectionAge: FiniteDuration,
maxConnectionAgeGrace: FiniteDuration
): F[Server[F]] =
GrpcServer[F](
NettyServerBuilder
Expand All @@ -64,6 +85,12 @@ package object api {
.bindService(deployGrpcService, grpcExecutor)
)
.compressorRegistry(null)
.keepAliveTime(keepAliveTime.length, keepAliveTime.unit)
.keepAliveTimeout(keepAliveTimeout.length, keepAliveTimeout.unit)
.permitKeepAliveTime(permitKeepAliveTime.length, permitKeepAliveTime.unit)
.maxConnectionIdle(maxConnectionIdle.length, maxConnectionIdle.unit)
.maxConnectionAge(maxConnectionAge.length, maxConnectionAge.unit)
.maxConnectionAgeGrace(maxConnectionAgeGrace.length, maxConnectionAgeGrace.unit)
.addService(ProtoReflectionService.newInstance())
.build
)
Expand Down
Expand Up @@ -99,6 +99,12 @@ object ConfigMapper {
add("api-server.port-http", run.apiPortHttp)
add("api-server.enable-reporting", run.apiEnableReporting)
add("api-server.max-blocks-limit", run.apiMaxBlocksLimit)
add("api-server.keep-alive-time", run.apiKeepAliveTime)
add("api-server.keep-alive-timeout", run.apiKeepAliveTimeout)
add("api-server.permit-keep-alive-time", run.apiPermitKeepAliveTime)
add("api-server.max-connection-idle", run.apiMaxConnectionIdle)
add("api-server.max-connection-age", run.apiMaxConnectionAge)
add("api-server.max-connection-age-grace", run.apiMaxConnectionAgeGrace)

add("tls.key-path", run.tlsKeyPath)
add("tls.certificate-path", run.tlsCertificatePath)
Expand Down
Expand Up @@ -300,6 +300,35 @@ final case class Options(arguments: Seq[String]) extends ScallopConf(arguments)
descr = "Use this flag to enable reporting endpoints."
)

val apiKeepAliveTime = opt[FiniteDuration](
descr = "Sets a custom keepalive time, the delay time for sending next keepalive ping"
)

val apiKeepAliveTimeout = opt[FiniteDuration](
descr = "Sets a custom keepalive timeout, the timeout for keepalive ping requests"
)

val apiPermitKeepAliveTime = opt[FiniteDuration](
descr = "The most aggressive keep-alive time clients are permitted to configure.The server would close" +
"the connection if clients exceeding this rate "
)

val apiMaxConnectionIdle = opt[FiniteDuration](
descr =
"Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated"
)

val apiMaxConnectionAge = opt[FiniteDuration](
descr =
"Sets a custom max connection age, connection lasting longer than which will be gracefully terminated"
)

val apiMaxConnectionAgeGrace = opt[FiniteDuration](
descr = "Sets a custom grace time for the graceful connection termination. Once the max connection age" +
" is reached, RPCs have the grace time to complete. RPCs that do not complete in time will be" +
" cancelled, allowing the connection to terminate"
)

val dataDir = opt[Path](
required = false,
descr = "Path to data directory. Defaults to $HOME/.rnode"
Expand Down
Expand Up @@ -71,7 +71,13 @@ final case class ApiServer(
grpcMaxRecvMessageSize: Long,
portHttp: Int,
maxBlocksLimit: Int,
enableReporting: Boolean
enableReporting: Boolean,
keepAliveTime: FiniteDuration,
keepAliveTimeout: FiniteDuration,
permitKeepAliveTime: FiniteDuration,
maxConnectionIdle: FiniteDuration,
maxConnectionAge: FiniteDuration,
maxConnectionAgeGrace: FiniteDuration
)

final case class Storage(
Expand Down
Expand Up @@ -59,6 +59,12 @@ class ConfigMapperSpec extends FunSuite with Matchers {
"--api-grpc-max-recv-message-size 111111",
"--api-max-blocks-limit 111111",
"--api-enable-reporting",
"--api-keep-alive-time 111111seconds",
"--api-keep-alive-timeout 111111seconds",
"--api-permit-keep-alive-time 111111seconds",
"--api-max-connection-idle 111111seconds",
"--api-max-connection-age 111111seconds",
"--api-max-connection-age-grace 111111seconds",
"--data-dir /var/lib/rnode",
"--lmdb-map-size-rspace 111111",
"--lmdb-map-size-blockdagstore 111111",
Expand Down Expand Up @@ -172,7 +178,13 @@ class ConfigMapperSpec extends FunSuite with Matchers {
portHttp = 111111,
grpcMaxRecvMessageSize = 111111,
maxBlocksLimit = 111111,
enableReporting = true
enableReporting = true,
keepAliveTime = 111111L.seconds,
keepAliveTimeout = 111111L.seconds,
permitKeepAliveTime = 111111L.seconds,
maxConnectionAge = 111111L.seconds,
maxConnectionIdle = 111111L.seconds,
maxConnectionAgeGrace = 111111L.seconds
),
storage = Storage(
dataDir = Paths.get("/var/lib/rnode"),
Expand Down
Expand Up @@ -89,7 +89,13 @@ class HoconConfigurationSpec extends FunSuite with Matchers {
grpcMaxRecvMessageSize = 16777216,
portHttp = 40403,
maxBlocksLimit = 50,
enableReporting = false
enableReporting = false,
keepAliveTime = 2.hours,
keepAliveTimeout = 20.seconds,
permitKeepAliveTime = 5.minutes,
maxConnectionAge = 1.hours,
maxConnectionIdle = 1.hours,
maxConnectionAgeGrace = 1.hours
),
storage = Storage(
dataDir = Paths.get("/var/lib/rnode"),
Expand Down