VictoriaMetrics/VictoriaMetrics · error

cannot read timestamp

Error message

cannot read timestamp

What it means

Thrown by Dogsketch.unmarshalProtobuf when field 1 (ts, int64 timestamp) cannot be read as a varint — easyproto's fc.Int64() returned false because the wire type is not varint (0). The failure aborts the Dogsketch and surfaces wrapped as 'cannot unmarshal Dogsketch: cannot read timestamp'.

Source

Thrown at lib/protoparser/datadogsketches/parser.go:270

	d.Ts = 0
	d.Cnt = 0
	d.Min = 0.0
	d.Max = 0.0
	d.Sum = 0.0
	d.K = nil
	d.N = nil

	var fc easyproto.FieldContext
	for len(src) > 0 {
		src, err = fc.NextField(src)
		if err != nil {
			return fmt.Errorf("cannot read next field in Dogsketch message: %w", err)
		}
		switch fc.FieldNum {
		case 1:
			ts, ok := fc.Int64()
			if !ok {
				return fmt.Errorf("cannot read timestamp")
			}
			d.Ts = ts
		case 2:
			cnt, ok := fc.Int64()
			if !ok {
				return fmt.Errorf("cannot read count")
			}
			d.Cnt = cnt
		case 3:
			v, ok := fc.Double()
			if !ok {
				return fmt.Errorf("cannot read min")
			}
			d.Min = v
		case 4:
			v, ok := fc.Double()
			if !ok {
				return fmt.Errorf("cannot read max")

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Fix the producer so `int64 ts = 1` is encoded as a varint (wire type 0).
  2. Verify field 1's wire type with protoc --decode_raw on the failing Dogsketch.
  3. Pin matching agent-payload proto versions across producer and consumer.
  4. Add round-trip serialization tests (marshal then unmarshal a known Dogsketch) to the producer's CI.

Example fix

// before (bad producer code)
buf = appendFixed64(buf, 1, uint64(ts))
// after
buf = appendVarintField(buf, 1, uint64(ts)) // wire type 0
Defensive patterns

Strategy: try-catch

Try / catch

if err := sp.UnmarshalProtobuf(buf); err != nil {
    if strings.Contains(err.Error(), "cannot read timestamp") {
        metrics.Inc("dogsketch_bad_timestamp_field")
        http.Error(w, "malformed dogsketch", http.StatusBadRequest)
        return
    }
    return err
}

Prevention

When it happens

Trigger: Dogsketch field 1 is encoded as length-delimited or fixed64 instead of varint, or earlier-field misalignment causes a non-varint value to be read as field 1.

Common situations: Custom serializer writing ts as a fixed-size or string field; proto field renumbering in a forked schema; corrupted bytes making the tag point at the wrong value.

Related errors


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/e70d1d69dee2613a. Report an issue: GitHub.