{"record":{"id":"0d962a86e28f2d23","repo":"grafana/k6","slug":"aggregation-wait-period-is-not-allowed-to-be-zero","errorCode":null,"errorMessage":"aggregation wait period is not allowed to be zero","messagePattern":"aggregation wait period is not allowed to be zero","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/cloud/expv2/collect.go","lineNumber":76,"sourceCode":"\t// map, we can probably use a simple slice (or even an array!) as a ring buffer to store the\n\t// aggregation buckets. This should save us a some time, since it would make the lookups and WaitPeriod\n\t// checks basically O(1). And even if for some reason there are occasional metrics with past times that\n\t// don't fit in the chosen ring buffer size, we could just send them along to the buffer unaggregated\n\ttimeBuckets map[int64]map[metrics.TimeSeries]metricValue\n}\n\nfunc newCollector(aggrPeriod, waitPeriod time.Duration) (*collector, error) {\n\tif aggrPeriod == 0 {\n\t\treturn nil, errors.New(\"aggregation period is not allowed to be zero\")\n\t}\n\tif aggrPeriod != aggrPeriod.Truncate(time.Second) {\n\t\treturn nil, errors.New(\"aggregation period is not allowed to have sub-second precision\")\n\t}\n\tif waitPeriod == 0 {\n\t\t// TODO: we could simplify the expiring logic\n\t\t// just having an internal static logic.\n\t\t// Like skip only not closed buckets bucketEnd > now.\n\t\treturn nil, errors.New(\"aggregation wait period is not allowed to be zero\")\n\t}\n\tif waitPeriod != waitPeriod.Truncate(time.Second) {\n\t\treturn nil, errors.New(\"aggregation wait period is not allowed to have sub-second precision\")\n\t}\n\treturn &collector{\n\t\tbq:                bucketQ{},\n\t\tnowFunc:           time.Now,\n\t\ttimeBuckets:       make(map[int64]map[metrics.TimeSeries]metricValue),\n\t\taggregationPeriod: aggrPeriod,\n\t\twaitPeriod:        waitPeriod,\n\t}, nil\n}\n\n// CollectSamples drain the buffer and collect all the samples.\nfunc (c *collector) CollectSamples(containers []metrics.SampleContainer) {\n\t// Distribute all newly buffered samples into related buckets\n\tfor _, sampleContainer := range containers {\n\t\tsamples := sampleContainer.GetSamples()","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/output/cloud/expv2/collect.go#L58-L94","documentation":"Configuration guard in newCollector: the aggregation wait period is 0. The wait period controls how long finalized buckets linger before flushing, and a zero value would break the expiring logic.","triggerScenarios":"Thrown at output/cloud/expv2/collect.go:76 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set K6_CLOUD_API_METRIC_PUSH_INTERVAL_WAIT to a non-zero whole-second duration","Configure a positive wait period such as '5s' in the cloud output settings"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}