grafana-iam: Adds config opts for RBACRemoteClient for load balancing (#110819)
This commit is contained in:
@@ -12,16 +12,16 @@ The `grpcserver` package provides the implementation of the gRPC server for hand
|
||||
|
||||
## Usage
|
||||
|
||||
Enable the gRPC server in Grafana by setting the `grpcServer` feature toggle to `true` in your `custom.ini` configuration file.
|
||||
Enable the gRPC server in Grafana by setting the `grpcServer` feature toggle to `true` in your `custom.ini` configuration file.
|
||||
|
||||
``` ini
|
||||
```ini
|
||||
[feature_toggles]
|
||||
grpcServer = true
|
||||
```
|
||||
|
||||
You can specify the gRPC server specific settings in the `grpc_server` section of the configuration file.
|
||||
|
||||
``` ini
|
||||
```ini
|
||||
[grpc_server]
|
||||
network = "tcp"
|
||||
address = "127.0.0.1:10000"
|
||||
@@ -36,6 +36,31 @@ max_recv_msg_size =
|
||||
max_send_msg_size =
|
||||
```
|
||||
|
||||
### Optional: Connection Management and Load Balancing
|
||||
|
||||
These settings help with:
|
||||
|
||||
- **Resource management**: Prevent resource leaks from idle connections
|
||||
- **Connection health**: Detect and clean up dead connections
|
||||
- **Load balancing**: Force connection recycling for better distribution across multiple server instances
|
||||
- **DoS protection**: Rate limit keepalive pings from clients
|
||||
|
||||
```ini
|
||||
# Connection management options
|
||||
# Maximum amount of time a connection may exist before it will be closed
|
||||
max_connection_age = 300s
|
||||
# Additional time to allow for pending RPCs to complete before forcibly closing connections
|
||||
max_connection_age_grace = 10s
|
||||
# Maximum amount of idle time before a connection is closed
|
||||
max_connection_idle = 300s
|
||||
# Frequency of server-to-client pings to check if a connection is still active
|
||||
keepalive_time = 30s
|
||||
# Amount of time the server waits for a response to keepalive pings before closing the connection
|
||||
keepalive_timeout = 5s
|
||||
# Minimum amount of time a client should wait before sending a keepalive ping
|
||||
keepalive_min_time = 5s
|
||||
```
|
||||
|
||||
## Example Services
|
||||
|
||||
View [health.go] and [reflection.go] for examples of how to implement gRPC services in Grafana. These services are currently initialized by the [background service registry](../../registry/backgroundsvcs/background_services.go).
|
||||
View [health.go] and [reflection.go] for examples of how to implement gRPC services in Grafana. These services are currently initialized by the [background service registry](../../registry/backgroundsvcs/background_services.go).
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
@@ -104,12 +105,43 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, authe
|
||||
opts = append(opts, grpc.MaxSendMsgSize(s.cfg.MaxSendMsgSize))
|
||||
}
|
||||
|
||||
// Apply connection management settings
|
||||
keepaliveParams := keepalive.ServerParameters{
|
||||
MaxConnectionAge: s.cfg.MaxConnectionAge,
|
||||
MaxConnectionAgeGrace: s.cfg.MaxConnectionAgeGrace,
|
||||
MaxConnectionIdle: s.cfg.MaxConnectionIdle,
|
||||
Time: s.cfg.KeepaliveTime,
|
||||
Timeout: s.cfg.KeepaliveTimeout,
|
||||
}
|
||||
keepalivePolicy := keepalive.EnforcementPolicy{
|
||||
MinTime: s.cfg.KeepaliveMinTime,
|
||||
}
|
||||
|
||||
// Only add keepalive options if any values are configured
|
||||
if s.cfg.MaxConnectionAge > 0 || s.cfg.MaxConnectionAgeGrace > 0 || s.cfg.MaxConnectionIdle > 0 ||
|
||||
s.cfg.KeepaliveTime > 0 || s.cfg.KeepaliveTimeout > 0 {
|
||||
opts = append(opts, grpc.KeepaliveParams(keepaliveParams))
|
||||
}
|
||||
if s.cfg.KeepaliveMinTime > 0 {
|
||||
opts = append(opts, grpc.KeepaliveEnforcementPolicy(keepalivePolicy))
|
||||
}
|
||||
|
||||
s.server = grpc.NewServer(opts...)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *gPRCServerService) Run(ctx context.Context) error {
|
||||
s.logger.Info("Running GRPC server", "address", s.cfg.Address, "network", s.cfg.Network, "tls", s.cfg.TLSConfig != nil, "max_recv_msg_size", s.cfg.MaxRecvMsgSize, "max_send_msg_size", s.cfg.MaxSendMsgSize)
|
||||
s.logger.Info("Running GRPC server",
|
||||
"address", s.cfg.Address,
|
||||
"network", s.cfg.Network,
|
||||
"tls", s.cfg.TLSConfig != nil,
|
||||
"max_recv_msg_size", s.cfg.MaxRecvMsgSize,
|
||||
"max_send_msg_size", s.cfg.MaxSendMsgSize,
|
||||
"max_connection_age", s.cfg.MaxConnectionAge,
|
||||
"max_connection_idle", s.cfg.MaxConnectionIdle,
|
||||
"keepalive_time", s.cfg.KeepaliveTime,
|
||||
"keepalive_timeout", s.cfg.KeepaliveTimeout,
|
||||
"keepalive_min_time", s.cfg.KeepaliveMinTime)
|
||||
|
||||
listener, err := net.Listen(s.cfg.Network, s.cfg.Address)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user