Skip to content

Commit

Permalink
Introducing the MaxTimeSeriesInBatch config option
Browse files Browse the repository at this point in the history
Moving cloud output v2 from MaxMetricSamplesPerPackage to
MaxTimeSeriesInBatch, to have a flexibility and better reflect the
actual usage of the option.
  • Loading branch information
olegbespalov committed Jun 30, 2023
1 parent 340b0da commit ecbe215
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
10 changes: 8 additions & 2 deletions cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ type Config struct {
StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"`
APIVersion null.Int `json:"apiVersion" envconfig:"K6_CLOUD_API_VERSION"`

// TODO: rename the config field to align to the new logic by time series
// when the migration from the version 1 is completed.
// TODO: remove this when migration from the cloud output v1 will be completed
MaxMetricSamplesPerPackage null.Int `json:"maxMetricSamplesPerPackage" envconfig:"K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE"`

// Defines the max allowed number of time series in a single batch.
MaxTimeSeriesInBatch null.Int `json:"maxTimeSeriesInBatch" envconfig:"K6_CLOUD_MAX_TIME_SERIES_IN_BATCH"`

// The time interval between periodic API calls for sending samples to the cloud ingest service.
MetricPushInterval types.NullDuration `json:"metricPushInterval" envconfig:"K6_CLOUD_METRIC_PUSH_INTERVAL"`

Expand Down Expand Up @@ -166,6 +168,7 @@ func NewConfig() Config {
TracesPushInterval: types.NewNullDuration(1*time.Second, false),

MaxMetricSamplesPerPackage: null.NewInt(100000, false),
MaxTimeSeriesInBatch: null.NewInt(100000, false),
Timeout: types.NewNullDuration(1*time.Minute, false),
APIVersion: null.NewInt(1, false),
// Aggregation is disabled by default, since AggregationPeriod has no default value
Expand Down Expand Up @@ -225,6 +228,9 @@ func (c Config) Apply(cfg Config) Config {
if cfg.MaxMetricSamplesPerPackage.Valid {
c.MaxMetricSamplesPerPackage = cfg.MaxMetricSamplesPerPackage
}
if cfg.MaxTimeSeriesInBatch.Valid {
c.MaxTimeSeriesInBatch = cfg.MaxTimeSeriesInBatch
}
if cfg.MetricPushInterval.Valid {
c.MetricPushInterval = cfg.MetricPushInterval
}
Expand Down
1 change: 1 addition & 0 deletions cloudapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestConfigApply(t *testing.T) {
StopOnError: null.NewBool(true, true),
APIVersion: null.NewInt(2, true),
MaxMetricSamplesPerPackage: null.NewInt(2, true),
MaxTimeSeriesInBatch: null.NewInt(3, true),
MetricPushInterval: types.NewNullDuration(1*time.Second, true),
MetricPushConcurrency: null.NewInt(3, true),
TracesEnabled: null.NewBool(true, true),
Expand Down
4 changes: 2 additions & 2 deletions output/cloud/expv2/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type metricsFlusher struct {
bq *bucketQ
client pusher
aggregationPeriodInSeconds uint32
maxSeriesInSingleBatch int
maxSeriesInBatch int
}

// flush flushes the queued buckets sending them to the remote Cloud service.
Expand All @@ -42,7 +42,7 @@ func (f *metricsFlusher) flush(_ context.Context) error {
msb := newMetricSetBuilder(f.referenceID, f.aggregationPeriodInSeconds)
for i := 0; i < len(buckets); i++ {
msb.addTimeBucket(buckets[i])
if len(msb.seriesIndex) < f.maxSeriesInSingleBatch {
if len(msb.seriesIndex) < f.maxSeriesInBatch {
continue
}

Expand Down
6 changes: 3 additions & 3 deletions output/cloud/expv2/flush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func TestMetricsFlusherFlushChunk(t *testing.T) {
bq := &bucketQ{}
pm := &pusherMock{}
mf := metricsFlusher{
bq: bq,
client: pm,
maxSeriesInSingleBatch: 3,
bq: bq,
client: pm,
maxSeriesInBatch: 3,
}

bq.buckets = make([]timeBucket, 0, tc.series)
Expand Down
4 changes: 1 addition & 3 deletions output/cloud/expv2/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ func (o *Output) Start() error {
bq: &o.collector.bq,
client: mc,
aggregationPeriodInSeconds: uint32(o.config.AggregationPeriod.TimeDuration().Seconds()),
// TODO: rename the config field to align to the new logic by time series
// when the migration from the version 1 is completed.
maxSeriesInSingleBatch: int(o.config.MaxMetricSamplesPerPackage.Int64),
maxSeriesInBatch: int(o.config.MaxTimeSeriesInBatch.Int64),
}

o.runFlushWorkers()
Expand Down

0 comments on commit ecbe215

Please sign in to comment.