vectordotdev/vector · error

keys/counts were unexpectedly mismatched

Error message

keys/counts were unexpectedly mismatched

What it means

When decoding a DDSketch-aggregated metric from Vector's protobuf representation, AgentDDSketch::from_raw is called with parallel keys/counts arrays and .expect("keys/counts were unexpectedly mismatched") (lib/vector-core/src/event/proto.rs). from_raw validates that keys.len() == counts.len(); if the incoming metric sketch stores bins whose key and count vectors have different lengths, decoding panics.

Source

Thrown at lib/vector-core/src/event/proto.rs:566

                    .unwrap_or(if pos { i16::MAX } else { i16::MIN })
            })
            .collect::<Vec<_>>();
        let counts = sketch
            .n
            .into_iter()
            .map(|n| n.try_into().unwrap_or(u16::MAX))
            .collect::<Vec<_>>();
        MetricSketch::AgentDDSketch(
            AgentDDSketch::from_raw(
                sketch.count,
                sketch.min,
                sketch.max,
                sketch.sum,
                sketch.avg,
                &keys,
                &counts,
            )
            .expect("keys/counts were unexpectedly mismatched"),
        )
    }
}

impl From<super::metadata::Secrets> for Secrets {
    fn from(value: super::metadata::Secrets) -> Self {
        Self {
            entries: value.into_iter().map(|(k, v)| (k, v.to_string())).collect(),
        }
    }
}

impl From<Secrets> for super::metadata::Secrets {
    fn from(value: Secrets) -> Self {
        let mut secrets = Self::new();
        for (k, v) in value.entries {
            secrets.insert(k, v);
        }

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Align producer and consumer Vector versions so both sides agree on the sketch proto schema
  2. If you emit the proto yourself, always build keys and counts from the same bins iteration so lengths match by construction
  3. Validate incoming sketches (keys.len() == counts.len()) at the decode boundary and drop/skip malformed metrics instead of trusting them
  4. Capture the offending payload and open an issue in vectordot/vector if stock Vector produced it

Example fix

// before
MetricSketch::AgentDDSketch(
    AgentDDSketch::from_raw(sketch.count, sketch.min, sketch.max, sketch.sum, sketch.avg, &keys, &counts)
        .expect("keys/counts were unexpectedly mismatched"),
)

// after: propagate the decode error
let sketch = AgentDDSketch::from_raw(sketch.count, sketch.min, sketch.max, sketch.sum, sketch.avg, &keys, &counts)
    .map(MetricSketch::AgentDDSketch)
    .map_err(|e| DecodeError::invalid_sketch(e))?;
Defensive patterns

Strategy: validation

Validate before calling

// Before from_raw, check the invariant the function enforces
if keys.len() != counts.len() {
    return Err(DecodeError::invalid_sketch("keys/counts length mismatch"));
}

Try / catch

// Handle from_raw's Result instead of expect
match AgentDDSketch::from_raw(count, min, max, sum, avg, &keys, &counts) {
    Ok(sketch) => MetricSketch::AgentDDSketch(sketch),
    Err(e) => { warn!(error = %e, "dropping malformed sketch"); continue; }
}

Prevention

When it happens

Trigger: Receiving (via the event proto / v2v gRPC) an aggregated histogram sketch where the repeated keys field and counts field have unequal lengths — produced by a buggy or incompatible producer, hand-rolled proto emitters, or payload corruption. AgentDDSketch::from_raw returns Err on length mismatch and the expect converts it to a panic.

Common situations: Version skew between Vector nodes where the sketch proto layout changed; custom agents emitting Vector's metric proto with independently-written keys/counts loops; truncated/mangled payloads from proxies or buffers between Vector nodes.

Related errors


AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/afb8b257c5aa96b2. Report an issue: GitHub.