{"record":{"id":"e008e99bda7bbb6d","repo":"thanos-io/thanos","slug":"marshal-samples","errorCode":null,"errorMessage":"marshal samples","messagePattern":"marshal samples","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/receive/writecapnp/marshal.go","lineNumber":87,"sourceCode":"\t\treturn errors.Wrap(err, \"set tenant\")\n\t}\n\n\tseries, err := wr.NewTimeSeries(int32(len(tsreq)))\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor i, ts := range tsreq {\n\t\ttsc := series.At(i)\n\n\t\tlblsc, err := tsc.NewLabels(int32(len(ts.Labels)))\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"new labels\")\n\t\t}\n\t\tif err := marshalLabels(lblsc, ts.Labels, builder); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal labels\")\n\t\t}\n\t\tif err := marshalSamples(tsc, ts.Samples); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal samples\")\n\t\t}\n\t\tif err := marshalHistograms(tsc, ts.Histograms); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal histograms\")\n\t\t}\n\t\tif err := marshalExemplars(tsc, ts.Exemplars, builder); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal exemplars\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc BuildIntoSingleTenantWriteRequest(wr WriteRequest, tenant string, tsreq []prompb.TimeSeries) error {\n\tif err := wr.SetTenant(tenant); err != nil {\n\t\treturn errors.Wrap(err, \"set tenant\")\n\t}\n\n\tseries, err := wr.NewTimeSeries(int32(len(tsreq)))","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/writecapnp/marshal.go#L69-L105","documentation":"BuildInto calls marshalSamples to copy []prompb.Sample (timestamp/value pairs) into the capnp TimeSeries struct. A failure there — typically capnp list allocation or field-write failure — is wrapped as 'marshal samples'.","triggerScenarios":"marshalSamples fails while allocating the sample list or writing float64/int64 fields, e.g. with an enormous number of samples per series in one message.","commonSituations":"Very long time ranges batched into a single request; memory pressure on the sender; capnp message size limits hit mid-marshal.","solutions":["Limit samples per request / chunk the series before BuildInto","Downsample or truncate sample history per request","Increase capnp buffer limits if configurable","Check capnp library version for known list-size limits"],"exampleFix":"// before\nerr := marshalSamples(tsc, ts.Samples) // unbounded\n// after\nif len(ts.Samples) > maxSamplesPerSeries {\n    ts.Samples = ts.Samples[len(ts.Samples)-maxSamplesPerSeries:]\n}\nerr := marshalSamples(tsc, ts.Samples)","handlingStrategy":"validation","validationCode":"if len(ts.Samples) > maxSamplesPerSeries {\n    return errors.New(\"too many samples in one series for a single message\")\n}","typeGuard":null,"tryCatchPattern":"if err := BuildInto(tuple, tenant, tsreq, builder); err != nil && strings.Contains(err.Error(), \"marshal samples\") {\n    // chunk series into smaller batches and retry\n    return splitAndRetry(tsreq)\n}","preventionTips":["Limit samples per request","Downsample before sending large histories","Monitor batch sizes"],"tags":["capnp","serialization","samples"],"backgroundTag":"schema-validation-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}