thanos-io/thanos · error

set tenant

Error message

set tenant

What it means

BuildInto serializes a multi-tenant WriteRequest into a capnp message. The first step, wr.SetTenant(tenant), sets the tenant string field on the TimeSeriesTenantTuple; if the capnp arena cannot allocate or write the string, the error is wrapped with 'set tenant'.

Solutions

  1. Reduce the batch size of tsreq passed to BuildInto
  2. Validate tenant is non-empty and of sane length before calling BuildInto
  3. Increase the capnp message buffer/arena size if configured
  4. Check the underlying capnp library version for known allocation limits
  5. If persistent, fall back to BuildIntoSingleTenantWriteRequest per-tenant batches

Example fix

// before
err := BuildInto(tuple, tenant, tsreq, builder)
// after
if tenant == "" || len(tenant) > 255 {
    return fmt.Errorf("invalid tenant %q", tenant)
}
err := BuildInto(tuple, tenant, tsreq, builder)
Defensive patterns

Strategy: validation

Validate before calling

func validateTenant(t string) error {
    if t == "" { return errors.New("tenant must not be empty") }
    if len(t) > 255 { return errors.New("tenant too long") }
    return nil
}

Try / catch

if err := BuildInto(tuple, tenant, tsreq, builder); err != nil && strings.Contains(err.Error(), "set tenant") {
    // tenant field write failed: fall back to smaller batch or per-tenant split
    return handleMarshalFailure(err, tenant, tsreq)
}

Prevention

When it happens

Trigger: SetTenant fails on the capnp struct — typically message/arena allocation failure because the buffer is exhausted, or (depending on the capnp binding) an invalid/oversized tenant string.

Common situations: Very large batched writes exhausting the capnp segment size limit; a tenant id that is empty or abnormally large; running against a capnp version where string setters allocate eagerly.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/4732febeb93fd0ce. Report an issue: GitHub.

Appendix: source

Thrown at pkg/receive/writecapnp/marshal.go:69

	if err != nil {
		return WriteRequest{}, err
	}
	if err := wr.SetData(t); err != nil {
		return WriteRequest{}, err
	}
	ttd := t.At(0)
	if err := BuildInto(&ttd, tenant, tsreq, builder); err != nil {
		return WriteRequest{}, err
	}
	if err := marshalSymbols(builder, sym); err != nil {
		return WriteRequest{}, err
	}
	return wr, nil
}

func BuildInto(wr *TimeSeriesTenantTuple, tenant string, tsreq []prompb.TimeSeries, builder *symboltable.Builder) error {
	if err := wr.SetTenant(tenant); err != nil {
		return errors.Wrap(err, "set tenant")
	}

	series, err := wr.NewTimeSeries(int32(len(tsreq)))
	if err != nil {
		return err
	}
	for i, ts := range tsreq {
		tsc := series.At(i)

		lblsc, err := tsc.NewLabels(int32(len(ts.Labels)))
		if err != nil {
			return errors.Wrap(err, "new labels")
		}
		if err := marshalLabels(lblsc, ts.Labels, builder); err != nil {
			return errors.Wrap(err, "marshal labels")
		}
		if err := marshalSamples(tsc, ts.Samples); err != nil {
			return errors.Wrap(err, "marshal samples")

View on GitHub (pinned to 35b8b99117)