Skip to content

Commit f2b32ed

Browse files
committed
feat: added sink batch size config for sink concurrency
1 parent 0d02ea1 commit f2b32ed

File tree

7 files changed

+11
-4
lines changed

7 files changed

+11
-4
lines changed

agent/agent.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"github.com/raystack/salt/log"
1818
)
1919

20-
const defaultBatchSize = 1
21-
2220
// TimerFn of function type
2321
type TimerFn func() func() int
2422

@@ -32,6 +30,7 @@ type Agent struct {
3230
retrier *retrier
3331
stopOnSinkError bool
3432
timerFn TimerFn
33+
sinkBatchSize int
3534
}
3635

3736
// NewAgent returns an Agent with plugin factories.
@@ -53,6 +52,7 @@ func NewAgent(config Config) *Agent {
5352
logger: config.Logger,
5453
retrier: retrier,
5554
timerFn: timerFn,
55+
sinkBatchSize: config.SinkBatchSize,
5656
}
5757
}
5858

@@ -313,7 +313,7 @@ func (r *Agent) setupSink(ctx context.Context, sr recipe.PluginRecipe, stream *s
313313

314314
r.logger.Info("Successfully published record", "sink", sr.Name, "recipe", recipeName)
315315
return nil
316-
}, defaultBatchSize)
316+
}, r.sinkBatchSize)
317317

318318
stream.onClose(func() {
319319
if err := sink.Close(); err != nil {

agent/agent_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ func TestAgentRun(t *testing.T) {
772772
Monitor: monitor,
773773
MaxRetries: 2, // need to retry "at least" 2 times since Extractor returns RetryError twice
774774
RetryInitialInterval: 1 * time.Millisecond, // this is to override default retry interval to reduce test time
775+
SinkBatchSize: 1,
775776
})
776777
run := r.Run(ctx, validRecipe)
777778
assert.NoError(t, run.Error)

agent/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ type Config struct {
1717
RetryInitialInterval time.Duration
1818
StopOnSinkError bool
1919
TimerFn TimerFn
20+
SinkBatchSize int
2021
}

cmd/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func RunCmd() *cobra.Command {
9191
MaxRetries: cfg.MaxRetries,
9292
RetryInitialInterval: time.Duration(cfg.RetryInitialIntervalSeconds) * time.Second,
9393
StopOnSinkError: cfg.StopOnSinkError,
94+
SinkBatchSize: cfg.SinkBatchSize,
9495
})
9596

9697
recipes, err := recipe.NewReader(lg, pathToConfig).Read(args[0])

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Config struct {
1717
OtelEnabled bool `mapstructure:"OTEL_ENABLED" default:"false"`
1818
OtelCollectorAddr string `mapstructure:"OTEL_COLLECTOR_ADDR" default:"localhost:4317"`
1919
OtelTraceSampleProbability float64 `mapstructure:"OTEL_TRACE_SAMPLE_PROBABILITY" default:"1"`
20+
SinkBatchSize int `mapstructure:"SINK_BATCH_SIZE" default:"1"`
2021
}
2122

2223
func Load(configFile string) (Config, error) {

config/config_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestLoad(t *testing.T) {
3131
MaxRetries: 5,
3232
RetryInitialIntervalSeconds: 5,
3333
StopOnSinkError: false,
34+
SinkBatchSize: 1,
3435
},
3536
},
3637
{
@@ -46,6 +47,7 @@ func TestLoad(t *testing.T) {
4647
OtelTraceSampleProbability: 1,
4748
MaxRetries: 5,
4849
RetryInitialIntervalSeconds: 5,
50+
SinkBatchSize: 1,
4951
},
5052
expectedErr: "",
5153
},

config/meteor.yaml.sample

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ STOP_ON_SINK_ERROR: false
55
APP_NAME: meteor
66
OTEL_ENABLED: false
77
OTEL_COLLECTOR_ADDR: "localhost:4317"
8-
OTEL_TRACE_SAMPLE_PROBABILITY: 1
8+
OTEL_TRACE_SAMPLE_PROBABILITY: 1
9+
SINK_BATCH_SIZE: 10

0 commit comments

Comments
 (0)