Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asap-precompute-rs/src/answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn gauge(
count: template.count,
aggregation_temporality: 0,
value,
lineage: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions asap-precompute-rs/src/bin/stream_bench/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Meta {
count: 0,
aggregation_temporality: 0,
value,
lineage: None,
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions asap-precompute-rs/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ impl SketchType {
}
}

/// A collector view state's place in its lineage: the records one collector
/// instance (`producer_epoch`) sends for one (view, series, window), numbered
/// from 0. Record 0 is a full state (the samples folded into the window when
/// it was sent); record `n ≥ 1` is a delta on record `n − 1` (the state of the
/// samples folded since). The OTAP codec writes the epoch as the metric's
/// `asap.producer_epoch` metadata and the rest as the point's
/// `asap.sequence`, `asap.state_kind` and `asap.base_sequence` attributes.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Lineage {
/// The collector instance: a random number drawn at start.
pub producer_epoch: u64,
/// 0 for a full; a delta's base is `sequence − 1`.
pub sequence: u64,
}

impl Lineage {
/// A delta's base sequence; `None` for a full.
pub fn base_sequence(&self) -> Option<u64> {
self.sequence.checked_sub(1)
}
}

/// One emitted sketch (or scalar estimate) plus its runtime metadata.
///
/// `payload` is the sketch's ASAPv1 envelope bytes and is what
Expand Down Expand Up @@ -153,6 +175,9 @@ pub struct SketchEnvelope {
/// Encode writes it to the `value` column.
#[serde(default)]
pub value: f64,
/// A collector view state's lineage; `None` outside `planner_views`.
#[serde(default)]
pub lineage: Option<Lineage>,
}

#[cfg(test)]
Expand Down Expand Up @@ -183,6 +208,10 @@ mod tests {
count: 100,
aggregation_temporality: 1,
value: 88.0,
lineage: Some(Lineage {
producer_epoch: 9,
sequence: 2,
}),
};
let json = serde_json::to_string(&env).expect("serialize");
let decoded: SketchEnvelope = serde_json::from_str(&json).expect("deserialize");
Expand Down
1 change: 1 addition & 0 deletions asap-precompute-rs/src/kll_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ impl KllWindowStore {
count: entry.count,
aggregation_temporality: 1,
value: 0.0,
lineage: None,
})
})
.collect()
Expand Down
Loading
Loading