{"record":{"id":"35c21e32936ba922","repo":"grafana/k6","slug":"aggregation-period-is-not-allowed-to-have-sub-seco","errorCode":null,"errorMessage":"aggregation period is not allowed to have sub-second precision","messagePattern":"aggregation period is not allowed to have sub-second precision","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/cloud/expv2/collect.go","lineNumber":70,"sourceCode":"\tnowFunc func() time.Time\n\n\taggregationPeriod time.Duration\n\twaitPeriod        time.Duration\n\n\t// we should no longer have to handle metrics that have times long in the past. So instead of a\n\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}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/output/cloud/expv2/collect.go#L52-L88","documentation":"Configuration guard in newCollector: the aggregation period has a fractional-second component (aggrPeriod != aggrPeriod.Truncate(time.Second)). The bucketing logic keys on whole seconds, so sub-second precision is rejected.","triggerScenarios":"Thrown at output/cloud/expv2/collect.go:70 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Round the aggregation period to whole seconds, e.g. '10s' instead of '10.5s' or '1500ms'","Set K6_CLOUD_API_METRIC_PUSH_INTERVAL_AGGREGATION to a whole-second value"],"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"}