thanos-io/thanos · error

add series

Error message

add series

What it means

sWriter.AddSeries failed when registering a series (labels + chunk metas) into the destination index after its chunks were written. The index writer validates labelsets and refs; failures here abort the compaction output.

Solutions

  1. Inspect the wrapped cause for 'duplicate' or 'empty labelset'; fix relabeling configs that can strip all labels from series.
  2. Ensure the input series set is sorted and deduplicated before WriteSeries (compactv2 expects sorted input).
  3. Retry compaction with fresh output; check the wrapped error for IO issues (disk full) if not a validation failure.
  4. If triggered by custom code, verify chunk metas were written via WriteChunks before AddSeries with matching refs.

Example fix

// before: empty labelsets slip through relabeling and fail AddSeries
// after: filter degenerate series before compaction
if labels.IsEmpty() {
    p.SeriesProcessed()
    continue
}
Defensive patterns

Strategy: validation

Validate before calling

// reject series that would fail AddSeries before writing
if labels.IsEmpty() || hasDuplicateSeries(seen, labels) {
    p.SeriesProcessed()
    continue
}

Type guard

func isValidSeriesSet(lset labels.Labels) bool {
    return lset != nil && lset.Len() > 0 && lset.IsValid()
}

Try / catch

if err := WriteSeries(ctx, set, symbols); err != nil {
    if strings.Contains(err.Error(), "duplicate") || strings.Contains(err.Error(), "empty") {
        return errors.Wrap(err, "input series not sorted/deduplicated; check relabel config")
    }
    return err
}

Prevention

When it happens

Trigger: write() calls sWriter.AddSeries(ref, s.Labels(), chks...) after WriteChunks; failure on invalid/duplicate label sets (empty or duplicate series), invalid chunk refs written out of order, or underlying index file IO error.

Common situations: Duplicate or out-of-order series in the input stream (unsorted series set bug or deduplication failure), empty labelset series after label removal/external relabeling, index writer invariant violations.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at pkg/compactv2/chunk_series_set.go:223

			chks = append(chks, chksIter.At())
		}

		if chksIter.Err() != nil {
			return errors.Wrap(chksIter.Err(), "chunk iter")
		}

		// Skip the series with all deleted chunks.
		if len(chks) == 0 {
			// All series will be ignored.
			p.SeriesProcessed()
			continue
		}

		if err := sWriter.WriteChunks(chks...); err != nil {
			return errors.Wrap(err, "write chunks")
		}
		if err := sWriter.AddSeries(ref, s.Labels(), chks...); err != nil {
			return errors.Wrap(err, "add series")
		}
		for _, chk := range chks {
			// ChunkPool is used by tsdb.OpenBlock BlockReader.
			if err := w.chunkPool.Put(chk.Chunk); err != nil {
				return errors.Wrap(err, "put chunk")
			}
		}
		ref++
		p.SeriesProcessed()
	}
	if populatedSet.Err() != nil {
		return errors.Wrap(populatedSet.Err(), "iterate populated chunk series set")
	}

	return nil
}

View on GitHub (pinned to 35b8b99117)