Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(propdefs): stop skewing write latency and label every batch outcome (#79318)

Eli Reisman880ac92e3a15
diff --git a/rust/property-defs-rs/src/batch_ingestion.rs b/rust/property-defs-rs/src/batch_ingestion.rs
index a48de380d068..34827b254dcd 100644
--- a/rust/property-defs-rs/src/batch_ingestion.rs
+++ b/rust/property-defs-rs/src/batch_ingestion.rs
@@ -532,6 +532,11 @@ async fn write_event_properties_batch(
"Dropped {removed} event property rows referencing missing {column}={value}"
);
if batch.is_empty() {
+ metrics::counter!(
+ V2_EVENT_PROPS_BATCH_ATTEMPT,
+ &[("result", "emptied_fk")]
+ )
+ .increment(1);
total_time.fin();
return Ok(());
}
@@ -590,7 +595,6 @@ async fn write_property_definitions_batch(
mut batch: PropertyDefinitionsBatch,
pool: &PgPool,
) -> Result<(), sqlx::Error> {
- let total_time = common_metrics::timing_guard(V2_PROP_DEFS_BATCH_WRITE_TIME, &[]);
let mut tries: u64 = 1;
let mut fk_strips: u64 = 0;
@@ -601,10 +605,15 @@ async fn write_property_definitions_batch(
#[allow(clippy::len_zero)]
if batch.len() == 0 {
batch.uncache_dropped(&cache);
- total_time.fin();
+ metrics::counter!(V2_PROP_DEFS_BATCH_ATTEMPT, &[("result", "noop")]).increment(1);
return Ok(());
}
+ // Started only once there are rows to write. Opening it above the early return would record a
+ // near-zero sample for a batch that issues no SQL at all, which drags down a histogram whose
+ // whole purpose is characterizing Postgres write latency.
+ let total_time = common_metrics::timing_guard(V2_PROP_DEFS_BATCH_WRITE_TIME, &[]);
+
loop {
// what if we just ditch properties without a property_type set? why update on conflict at all?
//
@@ -686,6 +695,11 @@ async fn write_property_definitions_batch(
// entries remain, and here we mean "no writable rows left".
#[allow(clippy::len_zero)]
if batch.len() == 0 {
+ metrics::counter!(
+ V2_PROP_DEFS_BATCH_ATTEMPT,
+ &[("result", "emptied_fk")]
+ )
+ .increment(1);
total_time.fin();
batch.uncache_dropped(&cache);
return Ok(());
@@ -822,6 +836,11 @@ async fn write_event_definitions_batch(
"Dropped {removed} event definition rows referencing missing {column}={value}"
);
if batch.is_empty() {
+ metrics::counter!(
+ V2_EVENT_DEFS_BATCH_ATTEMPT,
+ &[("result", "emptied_fk")]
+ )
+ .increment(1);
total_time.fin();
return Ok(());
}
diff --git a/rust/property-defs-rs/src/group_type_resolver.rs b/rust/property-defs-rs/src/group_type_resolver.rs
index a8f67dfb4cb7..0a98495159e8 100644
--- a/rust/property-defs-rs/src/group_type_resolver.rs
+++ b/rust/property-defs-rs/src/group_type_resolver.rs
@@ -24,6 +24,31 @@ use crate::{
const METHOD: &str = "GetGroupTypeMappingsByTeamIds";
const CLIENT: &str = "property-defs-rs";
+// Metric label for a gRPC status code, as a static string so the error path allocates nothing.
+// The values are the PascalCase variant names on purpose: the Node.js and Python personhog
+// clients emit the same `error_type` values, and these three metric names are shared with them.
+fn code_label(code: Code) -> &'static str {
+ match code {
+ Code::Ok => "Ok",
+ Code::Cancelled => "Cancelled",
+ Code::Unknown => "Unknown",
+ Code::InvalidArgument => "InvalidArgument",
+ Code::DeadlineExceeded => "DeadlineExceeded",
+ Code::NotFound => "NotFound",
+ Code::AlreadyExists => "AlreadyExists",
+ Code::PermissionDenied => "PermissionDenied",
+ Code::ResourceExhausted => "ResourceExhausted",
+ Code::FailedPrecondition => "FailedPrecondition",
+ Code::Aborted => "Aborted",
+ Code::OutOfRange => "OutOfRange",
+ Code::Unimplemented => "Unimplemented",
+ Code::Internal => "Internal",
+ Code::Unavailable => "Unavailable",
+ Code::DataLoss => "DataLoss",
+ Code::Unauthenticated => "Unauthenticated",
+ }
+}
+
fn is_retryable(code: Code) -> bool {
matches!(
code,
@@ -59,13 +84,13 @@ where
match make_call().await {
Ok(value) => return Ok(value),
Err(status) => {
- let error_type = format!("{:?}", status.code());
+ let error_type = code_label(status.code());
metrics::counter!(
PERSONHOG_ERRORS_TOTAL,
"method" => method,
"client" => client,
- "error_type" => error_type.clone(),
+ "error_type" => error_type,
)
.increment(1);
@@ -216,8 +241,8 @@ impl GroupTypeResolver {
Err(e) => {
let error_type = e
.downcast_ref::<Status>()
- .map(|s| format!("{:?}", s.code()))
- .unwrap_or_else(|| "unknown".to_string());
+ .map(|s| code_label(s.code()))
+ .unwrap_or("unknown");
warn!(error = %e, error_type = %error_type, "personhog group type resolution failed");
metrics::counter!(PERSONHOG_RESOLVE_ERRORS).increment(1);
return Err(e);
diff --git a/rust/property-defs-rs/src/metrics_buckets.rs b/rust/property-defs-rs/src/metrics_buckets.rs
index c94b6f7ef101..5698bc673ec3 100644
--- a/rust/property-defs-rs/src/metrics_buckets.rs
+++ b/rust/property-defs-rs/src/metrics_buckets.rs
@@ -18,8 +18,8 @@
use common_metrics::Matcher;
use crate::metrics_consts::{
- BATCH_ACQUIRE_TIME, V2_EVENT_DEFS_BATCH_WRITE_TIME, V2_EVENT_PROPS_BATCH_WRITE_TIME,
- V2_PROP_DEFS_BATCH_WRITE_TIME,
+ BATCH_ACQUIRE_TIME, UPDATES_PER_EVENT, V2_EVENT_DEFS_BATCH_WRITE_TIME,
+ V2_EVENT_PROPS_BATCH_WRITE_TIME, V2_PROP_DEFS_BATCH_WRITE_TIME,
};
// Batch-acquire spans "the channel already had a full batch waiting" to "we sat here until
@@ -39,12 +39,24 @@ const BATCH_WRITE_BUCKETS_MS: &[f64] = &[
1.0, 5.0, 10.0, 50.0, 100.0, 250.0, 500.0, 1_000.0, 2_000.0, 5_000.0, 10_000.0, 30_000.0,
];
+// Updates per event is a count, not a duration, so the millisecond ladder does not fit it at all:
+// its 10 to 50 gap sits exactly where the mass lives, and typical events yield single digits.
+// This ladder resolves the common range and still reaches update_count_skip_threshold (10000 by
+// default), above which the event is skipped entirely.
+const UPDATES_PER_EVENT_BUCKETS: &[f64] = &[
+ 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0, 55.0, 100.0, 250.0, 1_000.0, 10_000.0,
+];
+
pub fn bucket_overrides() -> Vec<(Matcher, &'static [f64])> {
vec![
(
Matcher::Full(BATCH_ACQUIRE_TIME.to_string()),
BATCH_ACQUIRE_BUCKETS_MS,
),
+ (
+ Matcher::Full(UPDATES_PER_EVENT.to_string()),
+ UPDATES_PER_EVENT_BUCKETS,
+ ),
(
Matcher::Full(V2_EVENT_DEFS_BATCH_WRITE_TIME.to_string()),
BATCH_WRITE_BUCKETS_MS,