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

feat(output): Allow keepalive config #378

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/output/xatu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ type Config struct {
Workers int `yaml:"workers" default:"1"`
Retry RetryConfig `yaml:"retry"`
AuthorizationSecret string `yaml:"authorizationSecret"`
KeepAlive KeepAliveConfig `yaml:"keepAlive"`
}

type KeepAliveConfig struct {
Enabled bool `yaml:"enabled" default:"true"`
Time time.Duration `yaml:"time" default:"10s"`
Timeout time.Duration `yaml:"timeout" default:"30s"`
}

func (c *Config) Validate() error {
Expand Down
22 changes: 17 additions & 5 deletions pkg/output/xatu/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,26 @@ type ItemExporter struct {
}

func NewItemExporter(name string, config *Config, log logrus.FieldLogger) (ItemExporter, error) {
log = log.WithField("output_name", name).WithField("output_type", SinkType)

opts := []grpc.DialOption{
grpc.WithChainUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor, retry.UnaryClientInterceptor()),
grpc.WithChainStreamInterceptor(grpc_prometheus.StreamClientInterceptor, retry.StreamClientInterceptor()),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 10 * time.Second,
Timeout: 30 * time.Second,
}

if config.KeepAlive.Enabled {
log.
WithField("keepalive_time", config.KeepAlive.Time).
WithField("keepalive_timeout", config.KeepAlive.Timeout).
Info("Enabling keepalive")

opts = append(opts, grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: config.KeepAlive.Time,
Timeout: config.KeepAlive.Timeout,
PermitWithoutStream: true,
}),
}))
} else {
log.Info("Disabling keepalive")
}

if config.TLS {
Expand All @@ -60,7 +72,7 @@ func NewItemExporter(name string, config *Config, log logrus.FieldLogger) (ItemE

return ItemExporter{
config: config,
log: log.WithField("output_name", name).WithField("output_type", SinkType),
log: log,
conn: conn,
client: pb.NewEventIngesterClient(conn),
}, nil
Expand Down
Loading