{"record":{"id":"b450948055e7af31","repo":"thanos-io/thanos","slug":"marshal-histograms","errorCode":null,"errorMessage":"marshal histograms","messagePattern":"marshal histograms","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/receive/writecapnp/marshal.go","lineNumber":90,"sourceCode":"\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)))\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/writecapnp/marshal.go#L72-L108","documentation":"BuildInto calls marshalHistograms to convert prompb.Histogram data (native histograms) into capnp structures. Failure during histogram list allocation or field encoding is wrapped as 'marshal histograms'.","triggerScenarios":"marshalHistograms fails allocating/encoding histogram buckets or counts — common with high-bucket-count native histograms or many histograms per series.","commonSituations":"Sender and receiver on mismatched versions where native histogram schemas differ; extremely fine histogram bucket resolutions; capnp arena exhaustion.","solutions":["Verify sender and receiver support the same native histogram capnp schema (upgrade/downgrade to match)","Reduce histogram bucket resolution/count","Chunk batches to reduce allocation pressure","Update the capnp/prompb dependencies to compatible versions"],"exampleFix":"// before\n histograms forwarded as-is\n// after\nif len(h.BucketCounts) > maxBuckets { merge adjacent buckets }\nerr := marshalHistograms(tsc, ts.Histograms)","handlingStrategy":"validation","validationCode":"for _, h := range ts.Histograms {\n    if len(h.GetPositiveCounts())+len(h.GetNegativeCounts()) > maxBuckets {\n        return errors.New(\"histogram bucket count too large\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := BuildInto(tuple, tenant, tsreq, builder); err != nil && strings.Contains(err.Error(), \"marshal histograms\") {\n    // check schema compatibility, reduce bucket resolution, retry\n    return retryWithCoarserHistograms(tsreq)\n}","preventionTips":["Match native histogram schema versions between sender and receiver","Cap histogram bucket resolution","Test version upgrades end-to-end"],"tags":["capnp","serialization","histograms"],"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"}