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.

chore(propdefs): remove dead metrics, config, and stale comments (#79315)

Eli Reismanc06895ea45b2
diff --git a/rust/property-defs-rs/.sqlx/query-7fa314878d358c78204cdc1b6282897bcdd5f798d153e263dae6385be787afe4.json b/rust/property-defs-rs/.sqlx/query-7fa314878d358c78204cdc1b6282897bcdd5f798d153e263dae6385be787afe4.json
deleted file mode 100644
index 90ca2967cfbf..000000000000
--- a/rust/property-defs-rs/.sqlx/query-7fa314878d358c78204cdc1b6282897bcdd5f798d153e263dae6385be787afe4.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO posthog_eventdefinition (id, name, volume_30_day, query_usage_30_day, team_id, project_id, last_seen_at, created_at)\n VALUES ($1, $2, NULL, NULL, $3, $4, $5, NOW())\n ON CONFLICT (coalesce(project_id, team_id::bigint), name)\n DO UPDATE SET last_seen_at = $5\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Varchar",
- "Int4",
- "Int8",
- "Timestamptz"
- ]
- },
- "nullable": []
- },
- "hash": "7fa314878d358c78204cdc1b6282897bcdd5f798d153e263dae6385be787afe4"
-}
diff --git a/rust/property-defs-rs/README.md b/rust/property-defs-rs/README.md
index 33c17103289a..7a645da32713 100644
--- a/rust/property-defs-rs/README.md
+++ b/rust/property-defs-rs/README.md
@@ -1,12 +1,26 @@
# Event and property definitions generator (propdefs for short)
-This consumes events from `clickhouse_events_json` and writes event and property definitions to postgres. It filters DB updates to avoid duplicate writes (writes are idempotent, but the DB load of writing every property definition every time would be too high).
+This consumes events from Kafka, introspects on their names and properties, and writes definition metadata to postgres for the read-side filters in the product.
+It filters DB updates to avoid duplicate writes, because writes are idempotent but writing every property definition on every event would be far too much DB load.
-Hoglets should check out [the runbook](http://runbooks/ingestion/property-defs-rs) for a detailed breakdown of how it's tuned for our current scale, and what metrics to look at and levers to pull if responding to an incident.
+Three tables are written: `posthog_eventdefinition`, `posthog_propertydefinition`, and `posthog_eventproperty`.
+
+Hoglets should check out [the runbook](https://runbooks.posthog.com/services/ingestion/concepts/property-defs-rs) for a detailed breakdown of how it's tuned for our current scale, and what metrics to look at and levers to pull if responding to an incident.
+
+## Topic
+
+Production consumes `team_event_partitioned_events_json`, set via `KAFKA_CONSUMER_TOPIC`.
+That topic is produced by a WarpStream Bento pipeline that repartitions `clickhouse_events_json` by team, under the separate `property-defs-rs-ws` consumer group.
+The in-code default is `clickhouse_events_json`, which is what a local run gets.
+
+## Dependencies worth knowing about
+
+- **personhog** resolves group names to group type indexes over gRPC. With `PERSONHOG_ADDR` unset there is no client, resolution fails, and every group property definition is dropped before the write. Definitions for events and non-group properties are unaffected.
+- **`FILTERED_TEAMS` and `FILTER_MODE`** are the first lever to reach for in an incident. `FILTER_MODE` picks whether the team list is an allow-list (`opt_in`) or a block-list (`opt_out`).
## Tests
-Tests use sqlx for database interactions. When tests are changed, you need to run in the property-defs-rs directory:
+Tests use sqlx for database interactions. The `.sqlx` offline cache covers the whole crate, so regenerate it after changing any `sqlx::query!` in `src/` or `tests/`:
```bash
cargo sqlx prepare -- --tests
diff --git a/rust/property-defs-rs/src/api/v1/constants.rs b/rust/property-defs-rs/src/api/v1/constants.rs
index b32b2005e288..e56461cfdf84 100644
--- a/rust/property-defs-rs/src/api/v1/constants.rs
+++ b/rust/property-defs-rs/src/api/v1/constants.rs
@@ -14,8 +14,6 @@ pub const PROPERTY_DEFS_TABLE: &str = "posthog_propertydefinition";
pub const EVENT_PROPERTY_TABLE: &str = "posthog_eventproperty";
pub const EVENT_PROPERTY_TABLE_ALIAS: &str = "check_for_matching_event_property";
-pub const PARENT_PROPERTY_TYPES: [&str; 4] = ["event", "person", "group", "session"];
-
pub const PROPERTY_DEFS_TABLE_COLUMNS: [&str; 6] = [
"id",
"project_id",
diff --git a/rust/property-defs-rs/src/api/v1/query.rs b/rust/property-defs-rs/src/api/v1/query.rs
index fec68147aace..14ccbad8167a 100644
--- a/rust/property-defs-rs/src/api/v1/query.rs
+++ b/rust/property-defs-rs/src/api/v1/query.rs
@@ -7,7 +7,6 @@ use crate::{
},
routing::Params,
},
- //metrics_consts::{},
types::PropertyParentType,
};
diff --git a/rust/property-defs-rs/src/api/v1/routing.rs b/rust/property-defs-rs/src/api/v1/routing.rs
index 2f262c5e70ba..4d1795b3aa84 100644
--- a/rust/property-defs-rs/src/api/v1/routing.rs
+++ b/rust/property-defs-rs/src/api/v1/routing.rs
@@ -1,7 +1,6 @@
use crate::{
api::v1::{constants::*, errors::ApiError, query::Manager},
types::PropertyParentType,
- //metrics_consts::{},
AppContext,
};
diff --git a/rust/property-defs-rs/src/app_context.rs b/rust/property-defs-rs/src/app_context.rs
index 17bca2aead2d..6001cd0efe2c 100644
--- a/rust/property-defs-rs/src/app_context.rs
+++ b/rust/property-defs-rs/src/app_context.rs
@@ -8,16 +8,8 @@ pub struct AppContext {
pub pool: PgPool,
pub query_manager: Manager,
- pub skip_writes: bool,
pub skip_reads: bool,
- // sentinel flag used to identify the "mirror" deployments (property-defs-rs-v2) in
- // production environments to special case code that only works in those envs. Primary
- // use so far is to condition which database the service writes to. When disabled, it
- // targets the shared PostHog cloud DB. When enabled, it targets the new, isolated
- // property definitions database instace.
- pub enable_mirror: bool,
-
group_type_resolver: GroupTypeResolver,
}
@@ -31,9 +23,7 @@ impl AppContext {
Ok(Self {
pool,
query_manager: qmgr,
- skip_writes: config.skip_writes,
skip_reads: config.skip_reads,
- enable_mirror: config.enable_mirror,
group_type_resolver,
})
}
diff --git a/rust/property-defs-rs/src/batch_ingestion.rs b/rust/property-defs-rs/src/batch_ingestion.rs
index 4b48eb954c4b..a48de380d068 100644
--- a/rust/property-defs-rs/src/batch_ingestion.rs
+++ b/rust/property-defs-rs/src/batch_ingestion.rs
@@ -152,7 +152,6 @@ pub struct EventDefinitionsBatch {
pub names: Vec<String>,
pub team_ids: Vec<i32>,
pub project_ids: Vec<i64>,
- pub last_seen_ats: Vec<DateTime<Utc>>,
pub cached: Vec<Update>,
}
@@ -165,7 +164,6 @@ impl EventDefinitionsBatch {
names: Vec::with_capacity(batch_size),
team_ids: Vec::with_capacity(batch_size),
project_ids: Vec::with_capacity(batch_size),
- last_seen_ats: Vec::with_capacity(batch_size),
cached: Vec::with_capacity(batch_size),
}
}
@@ -175,7 +173,6 @@ impl EventDefinitionsBatch {
self.names.push(ed.name.clone());
self.team_ids.push(ed.team_id);
self.project_ids.push(ed.project_id);
- self.last_seen_ats.push(ed.last_seen_at);
self.cached.push(Update::Event(ed));
}
@@ -222,7 +219,6 @@ impl EventDefinitionsBatch {
retain_by_mask(&mut self.names, &keep);
retain_by_mask(&mut self.team_ids, &keep);
retain_by_mask(&mut self.project_ids, &keep);
- retain_by_mask(&mut self.last_seen_ats, &keep);
retain_by_mask(&mut self.cached, &keep);
removed
}
@@ -758,10 +754,10 @@ async fn write_event_definitions_batch(
let mut fk_strips: u64 = 0;
loop {
- // last_seen_ats are manipulated on event defs for cache expiration
- // at the moment; as in v1 writes, let's keep these fresh per-attempt
- // to ensure the values in the UI are more accurate, and avoid PG 21000
- // errors (constraint violations) when retrying writes w/o tx wrapper
+ // The floored last_seen_at on EventDefinition is a dedup-cache key, not the value we
+ // store. Generate a fresh timestamp per attempt so the value shown in the UI is accurate,
+ // and so a retry cannot replay a stale one and trip PG 21000 (constraint violation)
+ // without a transaction wrapper to roll it back.
let mut per_attempt_last_seen_ats: Vec<DateTime<Utc>> = Vec::with_capacity(batch.len());
let per_attempt_ts = Utc::now();
for _ in 0..batch.len() {
@@ -891,9 +887,6 @@ mod tests {
property_type: None,
event_type: PropertyParentType::Group,
group_type_index: Some(GroupType::Unresolved(group_name.to_string())),
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
}
}
diff --git a/rust/property-defs-rs/src/config.rs b/rust/property-defs-rs/src/config.rs
index 1db0488b2515..969b3a7b4e77 100644
--- a/rust/property-defs-rs/src/config.rs
+++ b/rust/property-defs-rs/src/config.rs
@@ -22,21 +22,18 @@ pub struct Config {
#[envconfig(nested = true)]
pub consumer: ConsumerConfig,
- #[envconfig(default = "10")]
- pub max_concurrent_transactions: usize,
-
#[envconfig(default = "1000")]
pub update_batch_size: usize,
- // We issue updates in batches of update_batch_size, or when we haven't
- // received a new update in this many seconds
+ // Ceiling on how long the consumer will wait for a batch to reach update_batch_size before
+ // issuing it short. Measured from the start of the fill, not from the last update received,
+ // so a batch that trickles in one update at a time still breaks out after this many seconds.
#[envconfig(default = "300")]
pub max_issue_period: u64,
- // Propdefs spawns N workers to pull events from kafka,
- // marshal, and convert to updates. The number of
- // concurrent update batches sent to postgres is controlled
- // by max_concurrent_transactions
+ // Propdefs spawns N workers to pull events from kafka, marshal, and convert to updates.
+ // Write concurrency is not bounded by any semaphore: process_batch spawns a task per chunk,
+ // so max_pg_connections is the only thing applying backpressure to Postgres.
#[envconfig(default = "4")]
pub worker_loop_count: usize,
@@ -60,10 +57,11 @@ pub struct Config {
#[envconfig(default = "10")]
pub producer_drain_interval_secs: u64,
- // Workers send updates back to the main thread over a channel,
- // which has a depth of this many slots. If the main thread slows,
- // which usually means if postgres is slow, the workers will block
- // after filling this channel.
+ // Multiplier on update_batch_size for the depth of the single channel workers send updates
+ // back to the main thread over, so the real depth is update_batch_size * this. The channel is
+ // shared across all workers and its size does not vary with worker_loop_count, despite the
+ // name. If the main thread slows, which usually means postgres is slow, workers block once
+ // the channel fills.
#[envconfig(default = "1000")]
pub channel_slots_per_worker: usize,
@@ -82,18 +80,14 @@ pub struct Config {
#[envconfig(from = "EVENTDEF_LAST_SEEN_FLOOR_SECS", default = "3600")]
pub eventdef_last_seen_floor_secs: i64,
- // Do everything except actually write to the DB
- #[envconfig(default = "true")]
- pub skip_writes: bool,
-
- // Do everything except actually read or write from the DB
+ // Skip group-type resolution, which is the only read this service performs. Writes are
+ // unaffected: process_batch runs regardless of this setting.
#[envconfig(default = "true")]
pub skip_reads: bool,
- // We maintain a small cache for mapping from group names to group type indexes.
- // You have very few reasons to ever change this... group type index resolution
- // is done as a final step before writing an update, and is low-cost even without
- // caching, compared to the rest of the process.
+ // Cache mapping group names to group type indexes. Resolution runs once per consumer batch,
+ // before the batch is written, and is a gRPC round trip to personhog with retries and
+ // backoff, so caching matters more than the size of this value usually does.
#[envconfig(default = "100000")]
pub group_type_cache_size: usize,
@@ -124,14 +118,6 @@ pub struct Config {
#[envconfig(default = "opt_out")]
pub filter_mode: TeamFilterMode,
- // this enables codepaths used by the new mirror deployment
- // property-defs-rs-v2 in ArgoCD. NOTE: this is likely to be
- // removed in the future since the v2 deployment is no longer
- // part of the future plan for propdefs service.
- #[envconfig(default = "false")]
- pub enable_mirror: bool,
-
- // TODO: rename deploy cfg var to "write_batch_size" and update this after to complete the cutover!
#[envconfig(default = "100")]
pub write_batch_size: usize,
@@ -207,6 +193,9 @@ impl TeamFilterMode {
impl Config {
pub fn init_with_defaults() -> Result<Self, envconfig::Error> {
+ // Production overrides KAFKA_CONSUMER_TOPIC to team_event_partitioned_events_json, which
+ // a WarpStream Bento pipeline repartitions out of clickhouse_events_json. This default is
+ // only what a local run gets.
ConsumerConfig::set_defaults("property-defs-rs", "clickhouse_events_json", true);
Config::init_from_env()
}
diff --git a/rust/property-defs-rs/src/lib.rs b/rust/property-defs-rs/src/lib.rs
index 30b7b0249f3d..eaac0d903261 100644
--- a/rust/property-defs-rs/src/lib.rs
+++ b/rust/property-defs-rs/src/lib.rs
@@ -246,11 +246,9 @@ pub async fn update_producer_loop(
continue;
}
- // TEMPORARY: both old (v1) and new (v2) write paths will utilize the old
- // not-great caching strategy for now: optimistically add entries before
- // they are safely persisted to Postgres, and painfully extract them
- // when batch writes fail. This may be a fine trade for now, since
- // v2 batch writes fail much less often than v1
+ // Optimistic caching: entries go in before they are persisted, and are evicted
+ // again if the batch write fails. That trade is acceptable because batch writes
+ // rarely fail, and the alternative costs a second pass over every batch.
shared_cache.insert(update.clone());
match channel.try_send(update) {
diff --git a/rust/property-defs-rs/src/main.rs b/rust/property-defs-rs/src/main.rs
index 869a6e0d4557..1854c809d359 100644
--- a/rust/property-defs-rs/src/main.rs
+++ b/rust/property-defs-rs/src/main.rs
@@ -94,9 +94,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let consumer = SingleTopicConsumer::new(config.kafka.clone(), config.consumer.clone())?;
- // dedicated PG conn pool for serving propdefs API queries only (not currently live in prod)
- // TODO: update this to conditionally point to new isolated propdefs & persons (grouptypemapping)
- // DBs after those migrations are completed, prior to deployment
+ // Dedicated PG conn pool for serving propdefs API queries only. The API is mounted but
+ // receives no production traffic today.
let options = PgPoolOptions::new().max_connections(config.max_pg_connections);
let api_pool = options.connect(&config.database_url).await?;
let query_manager = QueryManager::new(api_pool).await?;
diff --git a/rust/property-defs-rs/src/measuring_channel.rs b/rust/property-defs-rs/src/measuring_channel.rs
index 3cb5ac426234..17605f8e9348 100644
--- a/rust/property-defs-rs/src/measuring_channel.rs
+++ b/rust/property-defs-rs/src/measuring_channel.rs
@@ -73,10 +73,6 @@ impl<T> MeasuringSender<T> {
pub fn max_capacity(&self) -> usize {
self.sender.max_capacity()
}
-
- pub fn inner(&self) -> &Sender<T> {
- &self.sender
- }
}
impl<T> MeasuringReceiver<T> {
@@ -96,10 +92,6 @@ impl<T> MeasuringReceiver<T> {
res
}
- pub fn inner(&self) -> &Receiver<T> {
- &self.receiver
- }
-
pub fn get_inflight_messages_count(&self) -> usize {
self.in_flight.load(Ordering::Relaxed)
}
diff --git a/rust/property-defs-rs/src/metrics_buckets.rs b/rust/property-defs-rs/src/metrics_buckets.rs
index 1ff3f699ac5f..c94b6f7ef101 100644
--- a/rust/property-defs-rs/src/metrics_buckets.rs
+++ b/rust/property-defs-rs/src/metrics_buckets.rs
@@ -10,9 +10,10 @@
//!
//! One unit trap to know about: `http_requests_duration_seconds`, recorded by the
//! `common_metrics` axum middleware, observes seconds while the default ladder is
-//! millisecond-shaped, so every sub-second request collapses into the first bucket. That is
-//! harmless while this service's HTTP surface is only `/metrics` and the probes, but if a real
-//! API endpoint ever ships here it needs a seconds-shaped override in this list.
+//! millisecond-shaped, so every sub-second request collapses into the first bucket. This already
+//! applies to the `/api/v1/projects/:project_id/property_definitions` route mounted in `main`, so
+//! any quantile over that endpoint is meaningless until a seconds-shaped override is added here.
+//! It has not mattered so far because the endpoint serves no production traffic.
use common_metrics::Matcher;
@@ -22,9 +23,10 @@ use crate::metrics_consts::{
};
// Batch-acquire spans "the channel already had a full batch waiting" to "we sat here until
-// max_issue_period expired", so the ladder has to cover sub-millisecond through the 500s
-// production timeout. Coarse at the top: past a minute the only question is which order of
-// magnitude.
+// max_issue_period expired", so the ladder runs from 1ms through the 500s production timeout.
+// It does not resolve below a millisecond: `timing_guard` truncates to integer milliseconds, so
+// a wait shorter than that records 0.0 regardless of the first boundary. Coarse at the top,
+// because past a minute the only question is which order of magnitude.
const BATCH_ACQUIRE_BUCKETS_MS: &[f64] = &[
1.0, 10.0, 100.0, 500.0, 1_000.0, 5_000.0, 10_000.0, 30_000.0, 60_000.0, 120_000.0, 300_000.0,
600_000.0,
diff --git a/rust/property-defs-rs/src/metrics_consts.rs b/rust/property-defs-rs/src/metrics_consts.rs
index 58e4d916976a..4a668012887d 100644
--- a/rust/property-defs-rs/src/metrics_consts.rs
+++ b/rust/property-defs-rs/src/metrics_consts.rs
@@ -1,4 +1,3 @@
-pub const UPDATES_ISSUED: &str = "prop_defs_issued_updates";
pub const EVENTS_RECEIVED: &str = "prop_defs_events_received";
pub const EVENTS_SKIPPED: &str = "prop_defs_events_skipped";
pub const FORCED_SMALL_BATCH: &str = "prop_defs_forced_small_batch";
@@ -9,7 +8,6 @@ pub const UPDATES_FILTERED_BY_CACHE: &str = "prop_defs_filtered_by_cache";
pub const EMPTY_EVENTS: &str = "prop_defs_empty_events";
pub const EVENT_PARSE_ERROR: &str = "prop_defs_event_parse_error";
pub const BATCH_ACQUIRE_TIME: &str = "prop_defs_batch_acquire_time_ms";
-pub const UPDATE_ISSUE_TIME: &str = "prop_defs_update_issue_time_ms";
pub const CACHE_CONSUMED: &str = "prop_defs_cache_space";
pub const CACHE_LEN: &str = "prop_defs_cache_len";
pub const CACHE_HITS: &str = "prop_defs_cache_hits";
@@ -21,10 +19,8 @@ pub const GROUP_TYPE_CACHE: &str = "prop_defs_group_type_cache";
pub const RECV_DEQUEUED: &str = "prop_defs_recv_dequeued";
pub const COMPACTED_UPDATES: &str = "prop_defs_compaction_dropped_updates";
pub const UPDATES_SKIPPED: &str = "prop_defs_skipped_updates";
-pub const UPDATES_DROPPED: &str = "prop_defs_dropped_updates";
pub const SKIPPED_DUE_TO_TEAM_FILTER: &str = "prop_defs_skipped_due_to_team_filter";
pub const ISSUE_FAILED: &str = "prop_defs_issue_failed";
-pub const CHUNK_SIZE: &str = "prop_defs_chunk_size";
pub const DUPLICATES_IN_BATCH: &str = "prop_defs_duplicates_in_batch";
pub const CHANNEL_MESSAGES_IN_FLIGHT: &str = "prop_defs_channel_messages_in_flight";
// Remaining free slots, not the channel size. CHANNEL_CAPACITY_TOTAL carries the size, so
@@ -32,8 +28,6 @@ pub const CHANNEL_MESSAGES_IN_FLIGHT: &str = "prop_defs_channel_messages_in_flig
pub const CHANNEL_CAPACITY: &str = "prop_defs_channel_capacity";
pub const CHANNEL_CAPACITY_TOTAL: &str = "prop_defs_channel_capacity_total";
-pub const ISOLATED_PROPDEFS_DB_SELECTED: &str = "isolated_propdefs_db_selected";
-
pub const PERSONHOG_RESOLVE_ERRORS: &str = "prop_defs_personhog_resolve_errors";
pub const PERSONHOG_RESOLVE_DURATION: &str = "prop_defs_personhog_resolve_duration_ms";
pub const PERSONHOG_ERRORS_TOTAL: &str = "personhog_errors_total";
@@ -41,7 +35,9 @@ pub const PERSONHOG_RETRIES_TOTAL: &str = "personhog_retries_total";
pub const PERSONHOG_TERMINAL_ERRORS_TOTAL: &str = "personhog_terminal_errors_total";
//
-// property-defs-rs "v2" batch write path metric keys below
+// Batch write path metric keys below. The "v2" prefix is vestigial and maps to nothing in the
+// current code, but Grafana dashboards query these names directly, so renaming them means
+// changing the dashboards in lockstep rather than editing this file alone.
//
pub const V2_EVENT_DEFS_BATCH_WRITE_TIME: &str = "propdefs_v2_eventdefs_batch_ms";
diff --git a/rust/property-defs-rs/src/types.rs b/rust/property-defs-rs/src/types.rs
index aa20661ea896..2eb079602d23 100644
--- a/rust/property-defs-rs/src/types.rs
+++ b/rust/property-defs-rs/src/types.rs
@@ -4,11 +4,9 @@ use chrono::{DateTime, Utc};
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::{Map, Value};
-use sqlx::{Executor, Postgres};
use tracing::warn;
-use uuid::Uuid;
-use crate::metrics_consts::{EVENTS_SKIPPED, UPDATES_ISSUED, UPDATES_SKIPPED};
+use crate::metrics_consts::{EVENTS_SKIPPED, UPDATES_SKIPPED};
// Custom deserializer that can handle both string and integer values
fn deserialize_string_or_i32<'de, D>(deserializer: D) -> Result<i32, D::Error>
@@ -111,17 +109,6 @@ pub enum PropertyParentType {
Session = 4,
}
-impl From<PropertyParentType> for i32 {
- fn from(parent_type: PropertyParentType) -> i32 {
- match parent_type {
- PropertyParentType::Event => 1,
- PropertyParentType::Person => 2,
- PropertyParentType::Group => 3,
- PropertyParentType::Session => 4,
- }
- }
-}
-
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum PropertyValueType {
DateTime,
@@ -181,9 +168,6 @@ pub struct PropertyDefinition {
pub property_type: Option<PropertyValueType>,
pub event_type: PropertyParentType,
pub group_type_index: Option<GroupType>,
- pub property_type_format: Option<String>, // Deprecated
- pub volume_30_day: Option<i64>, // Deprecated
- pub query_usage_30_day: Option<i64>, // Deprecated
}
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize)]
@@ -193,7 +177,9 @@ pub struct EventDefinition {
pub team_id: i32,
#[serde(deserialize_with = "deserialize_string_or_i64")]
pub project_id: i64,
- pub last_seen_at: DateTime<Utc>, // Always floored to our update rate for last_seen, so this Eq derive is safe for deduping
+ // Always floored to EVENTDEF_LAST_SEEN_FLOOR_SECS, so this Eq derive is safe for deduping:
+ // two sightings within the same floor period compare equal and collapse to one write.
+ pub last_seen_at: DateTime<Utc>,
}
// Derived hash since these are keyed on all fields in the DB
@@ -225,12 +211,6 @@ pub struct Event {
pub properties: Option<String>,
}
-impl From<&Event> for EventDefinition {
- fn from(event: &Event) -> Self {
- event.to_event_definition(DEFAULT_EVENTDEF_LAST_SEEN_FLOOR_SECS)
- }
-}
-
impl Event {
fn to_event_definition(&self, last_seen_floor_secs: i64) -> EventDefinition {
let name = sanitize_string(&self.event);
@@ -403,9 +383,6 @@ impl Event {
property_type,
event_type: parent_type,
group_type_index: group_type.clone(),
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
}));
}
}
@@ -636,35 +613,6 @@ pub fn sanitize_string(s: &str) -> String {
s.replace('\u{0000}', "\u{FFFD}")
}
-// The queries below are pulled more-or-less exactly from the TS impl.
-
-impl EventDefinition {
- pub async fn issue<'c, E>(&self, executor: E) -> Result<(), sqlx::Error>
- where
- E: Executor<'c, Database = Postgres>,
- {
- let res = sqlx::query!(
- r#"
- INSERT INTO posthog_eventdefinition (id, name, volume_30_day, query_usage_30_day, team_id, project_id, last_seen_at, created_at)
- VALUES ($1, $2, NULL, NULL, $3, $4, $5, NOW())
- ON CONFLICT (coalesce(project_id, team_id::bigint), name)
- DO UPDATE SET last_seen_at = $5
- "#,
- Uuid::now_v7(),
- self.name,
- self.team_id,
- self.project_id,
- // last_seen_at is floored only to bound how often we re-issue this write; the stored
- // value is the real time we saw the event.
- Utc::now()
- ).execute(executor).await.map(|_| ());
-
- metrics::counter!(UPDATES_ISSUED, &[("type", "event_definition")]).increment(1);
-
- res
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rust/property-defs-rs/src/update_cache.rs b/rust/property-defs-rs/src/update_cache.rs
index 98521ee3e39a..1a8c04b6ce89 100644
--- a/rust/property-defs-rs/src/update_cache.rs
+++ b/rust/property-defs-rs/src/update_cache.rs
@@ -59,10 +59,6 @@ impl Cache {
}
}
- pub fn len(&self) -> usize {
- self.eventdefs.len() + self.eventprops.len() + self.propdefs.len()
- }
-
pub fn eventdefs_len(&self) -> usize {
self.eventdefs.len()
}
@@ -75,10 +71,6 @@ impl Cache {
self.propdefs.len()
}
- pub fn is_empty(&self) -> bool {
- self.propdefs.is_empty() && self.eventdefs.is_empty() && self.eventprops.is_empty()
- }
-
pub fn contains_key(&self, key: &Update) -> bool {
let (found, label) = match key {
Update::Event(_) => (self.eventdefs.contains_key(key), "eventdefs"),
diff --git a/rust/property-defs-rs/tests/batch_ingestion.rs b/rust/property-defs-rs/tests/batch_ingestion.rs
index 094b3a417a66..7ddcae8f74eb 100644
--- a/rust/property-defs-rs/tests/batch_ingestion.rs
+++ b/rust/property-defs-rs/tests/batch_ingestion.rs
@@ -274,9 +274,6 @@ async fn test_property_definitions_conflict_update(db: PgPool) {
is_numerical: false,
event_type: PropertyParentType::Event,
group_type_index: None,
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
};
let initial_updates = vec![Update::Property(initial_prop)];
@@ -309,9 +306,6 @@ async fn test_property_definitions_conflict_update(db: PgPool) {
is_numerical: true,
event_type: PropertyParentType::Event,
group_type_index: None,
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
};
let updated_updates = vec![Update::Property(updated_prop)];
@@ -368,9 +362,6 @@ fn prop(
is_numerical,
event_type,
group_type_index: None,
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
})
}
diff --git a/rust/property-defs-rs/tests/group_type_resolver.rs b/rust/property-defs-rs/tests/group_type_resolver.rs
index 3c7f1a50e7f4..bda802e9b59e 100644
--- a/rust/property-defs-rs/tests/group_type_resolver.rs
+++ b/rust/property-defs-rs/tests/group_type_resolver.rs
@@ -418,7 +418,6 @@ fn make_config(addr: &str) -> property_defs_rs::config::Config {
config.personhog_max_retries = 2;
config.personhog_initial_backoff_ms = 1;
config.personhog_max_backoff_ms = 10;
- config.skip_writes = true;
config.skip_reads = false;
config
}
@@ -432,9 +431,6 @@ fn make_group_update(team_id: i32, group_name: &str) -> Update {
property_type: None,
event_type: PropertyParentType::Group,
group_type_index: Some(GroupType::Unresolved(group_name.to_string())),
- property_type_format: None,
- volume_30_day: None,
- query_usage_30_day: None,
})
}
@@ -873,7 +869,6 @@ async fn test_end_to_end_poisoned_group_def_recovers_and_persists(db: PgPool) {
let addr = start_mock_server(mock).await;
let mut config = make_config(&format!("http://{addr}"));
- config.skip_writes = false;
// TTL 0 makes round 1's negative-cache entry immediately stale, so round 2 re-drives personhog.
// This is the deterministic stand-in for "the TTL lapsed" between the two sparse events.
config.group_type_negative_ttl_secs = 0;
diff --git a/rust/property-defs-rs/tests/update_cache.rs b/rust/property-defs-rs/tests/update_cache.rs
index a2847d5d2278..040e59e4207a 100644
--- a/rust/property-defs-rs/tests/update_cache.rs
+++ b/rust/property-defs-rs/tests/update_cache.rs
@@ -73,9 +73,6 @@ fn make_prop_def(name: &str) -> Update {
property_type: Some(PropertyValueType::Numeric),
event_type: PropertyParentType::Event,
group_type_index: None,
- property_type_format: None,
- query_usage_30_day: None,
- volume_30_day: None,
})
}
@@ -129,9 +126,6 @@ fn make_group_prop_def(group_type_index: Option<GroupType>) -> Update {
property_type: Some(PropertyValueType::String),
event_type: PropertyParentType::Group,
group_type_index,
- property_type_format: None,
- query_usage_30_day: None,
- volume_30_day: None,
})
}
@@ -171,9 +165,6 @@ fn test_uncache_batch_evicts_unresolved_entry_for_group_prop() {
property_type: Some(PropertyValueType::String),
event_type: PropertyParentType::Group,
group_type_index: Some(GroupType::Resolved("company".into(), 2)),
- property_type_format: None,
- query_usage_30_day: None,
- volume_30_day: None,
};
let mut batch = PropertyDefinitionsBatch::new(10);
batch.append(resolved_pd);