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.

feat(propvals): part 2: scaffold property-vals-rs service skeleton (#59144)

Andy Zhaod6394d27768a
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index c217555549ea..5b4451bdfb21 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -113,6 +113,7 @@ jobs:
"personhog-router": 38,
"posthog-symbol-data": 19,
"property-defs-rs": 136,
+ "property-vals-rs": 5,
"serve-metrics": 14,
}
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index e0172ecf39df..46d03afee678 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -4458,7 +4458,7 @@ dependencies = [
"libc",
"percent-encoding",
"pin-project-lite",
- "socket2 0.5.10",
+ "socket2 0.6.3",
"system-configuration 0.7.0",
"tokio",
"tower-service",
@@ -7315,6 +7315,43 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "property-vals-rs"
+version = "0.1.0"
+dependencies = [
+ "axum 0.7.9",
+ "common-alloc",
+ "common-continuous-profiling",
+ "common-kafka",
+ "envconfig",
+ "lifecycle",
+ "proptest",
+ "serve-metrics",
+ "siphasher 1.0.2",
+ "tokio",
+ "tracing",
+ "tracing-subscriber",
+]
+
+[[package]]
+name = "proptest"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
+dependencies = [
+ "bit-set 0.8.0",
+ "bit-vec 0.8.0",
+ "bitflags 2.11.0",
+ "num-traits",
+ "rand 0.9.2",
+ "rand_chacha 0.9.0",
+ "rand_xorshift",
+ "regex-syntax",
+ "rusty-fork",
+ "tempfile",
+ "unarray",
+]
+
[[package]]
name = "prost"
version = "0.11.9"
@@ -7639,6 +7676,12 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "quick-error"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
+
[[package]]
name = "quick-xml"
version = "0.26.0"
@@ -7683,7 +7726,7 @@ dependencies = [
"quinn-udp",
"rustc-hash 2.1.1",
"rustls 0.23.37",
- "socket2 0.5.10",
+ "socket2 0.6.3",
"thiserror 2.0.18",
"tokio",
"tracing",
@@ -7720,7 +7763,7 @@ dependencies = [
"cfg_aliases",
"libc",
"once_cell",
- "socket2 0.5.10",
+ "socket2 0.6.3",
"tracing",
"windows-sys 0.60.2",
]
@@ -7815,6 +7858,15 @@ dependencies = [
"getrandom 0.3.4",
]
+[[package]]
+name = "rand_xorshift"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
+dependencies = [
+ "rand_core 0.9.5",
+]
+
[[package]]
name = "range-collections"
version = "0.2.4"
@@ -8448,6 +8500,18 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
+[[package]]
+name = "rusty-fork"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
+dependencies = [
+ "fnv",
+ "quick-error",
+ "tempfile",
+ "wait-timeout",
+]
+
[[package]]
name = "ryu"
version = "1.0.23"
@@ -10615,6 +10679,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
+[[package]]
+name = "unarray"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
+
[[package]]
name = "unicase"
version = "2.9.0"
@@ -10803,6 +10873,15 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64"
+[[package]]
+name = "wait-timeout"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "walkdir"
version = "2.5.0"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index c0d10cc994c8..579a54052f8f 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -49,6 +49,7 @@ members = [
"personhog-proto",
"personhog-replica",
"personhog-router",
+ "property-vals-rs",
]
[workspace.lints.rust]
diff --git a/rust/property-vals-rs/Cargo.toml b/rust/property-vals-rs/Cargo.toml
new file mode 100644
index 000000000000..28e83e4cfc67
--- /dev/null
+++ b/rust/property-vals-rs/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "property-vals-rs"
+version = "0.1.0"
+edition = "2021"
+publish = false
+
+[dependencies]
+axum = { workspace = true }
+common-alloc = { path = "../common/alloc" }
+common-continuous-profiling = { path = "../common/continuous_profiling" }
+common-kafka = { path = "../common/kafka" }
+envconfig = { workspace = true }
+lifecycle = { path = "../common/lifecycle" }
+serve-metrics = { path = "../common/serve_metrics" }
+siphasher = { workspace = true }
+tokio = { workspace = true }
+tracing = { workspace = true }
+tracing-subscriber = { workspace = true }
+
+[dev-dependencies]
+proptest = "1"
+
+[lints]
+workspace = true
diff --git a/rust/property-vals-rs/src/config.rs b/rust/property-vals-rs/src/config.rs
new file mode 100644
index 000000000000..489dc2718b31
--- /dev/null
+++ b/rust/property-vals-rs/src/config.rs
@@ -0,0 +1,216 @@
+use std::hash::{Hash, Hasher};
+use std::{num::ParseIntError, str::FromStr};
+
+use common_continuous_profiling::ContinuousProfilingConfig;
+use common_kafka::config::{ConsumerConfig, KafkaConfig};
+use envconfig::Envconfig;
+use siphasher::sip::SipHasher13;
+
+#[derive(Envconfig, Clone)]
+pub struct Config {
+ #[envconfig(nested = true)]
+ pub continuous_profiling: ContinuousProfilingConfig,
+
+ #[envconfig(nested = true)]
+ pub kafka: KafkaConfig,
+
+ #[envconfig(nested = true)]
+ pub consumer: ConsumerConfig,
+
+ #[envconfig(default = "clickhouse_property_values")]
+ pub output_topic: String,
+
+ #[envconfig(default = "30")]
+ pub flush_interval_secs: u64,
+
+ #[envconfig(default = "500000")]
+ pub max_buffered_tuples: usize,
+
+ #[envconfig(default = "property-vals-rs-local-events")]
+ pub kafka_transactional_id: String,
+
+ #[envconfig(default = "60")]
+ pub kafka_transaction_timeout_secs: u64,
+
+ #[envconfig(default = "clickhouse_groups")]
+ pub groups_kafka_consumer_topic: String,
+
+ #[envconfig(default = "clickhouse-property-vals-rs-groups")]
+ pub groups_kafka_consumer_group: String,
+
+ #[envconfig(default = "property-vals-rs-local-groups")]
+ pub groups_kafka_transactional_id: String,
+
+ #[envconfig(default = "")]
+ pub allowed_teams: TeamList,
+
+ #[envconfig(default = "")]
+ pub blocked_teams: TeamList,
+
+ #[envconfig(default = "100")]
+ pub rollout_percentage: u8,
+
+ #[envconfig(from = "BIND_HOST", default = "::")]
+ pub host: String,
+
+ #[envconfig(from = "BIND_PORT", default = "3302")]
+ pub port: u16,
+}
+
+#[derive(Clone)]
+pub struct TeamList {
+ pub teams: Vec<i64>,
+}
+
+impl FromStr for TeamList {
+ type Err = ParseIntError;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let mut teams = Vec::new();
+ for team in s.trim().split(',') {
+ if team.is_empty() {
+ continue;
+ }
+ teams.push(team.parse()?);
+ }
+ Ok(TeamList { teams })
+ }
+}
+
+impl Config {
+ pub fn init_with_defaults() -> Result<Self, envconfig::Error> {
+ // auto_commit=false because offsets are committed by the
+ // transactional producer via send_offsets_to_transaction; auto-commit
+ // would break the exactly-once guarantee.
+ ConsumerConfig::set_defaults(
+ "clickhouse-property-vals-rs",
+ "clickhouse_events_json",
+ false,
+ );
+ Config::init_from_env()
+ }
+
+ pub fn should_process(&self, team_id: i64) -> bool {
+ team_filter_allows(
+ team_id,
+ &self.allowed_teams.teams,
+ &self.blocked_teams.teams,
+ self.rollout_percentage,
+ )
+ }
+}
+
+pub fn team_filter_allows(
+ team_id: i64,
+ allowed: &[i64],
+ blocked: &[i64],
+ rollout_percentage: u8,
+) -> bool {
+ if blocked.contains(&team_id) {
+ return false;
+ }
+ if allowed.contains(&team_id) {
+ return true;
+ }
+ team_in_rollout(team_id, rollout_percentage)
+}
+
+fn team_in_rollout(team_id: i64, rollout_percentage: u8) -> bool {
+ if rollout_percentage >= 100 {
+ return true;
+ }
+ if rollout_percentage == 0 {
+ return false;
+ }
+ let mut hasher = SipHasher13::new();
+ team_id.hash(&mut hasher);
+ (hasher.finish() % 100) < rollout_percentage as u64
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use proptest::prelude::*;
+
+ #[test]
+ fn team_list_parses() {
+ let list: TeamList = "1,2,3".parse().unwrap();
+ assert_eq!(list.teams, vec![1, 2, 3]);
+ let empty: TeamList = "".parse().unwrap();
+ assert!(empty.teams.is_empty());
+ }
+
+ fn arb_team_list() -> impl Strategy<Value = Vec<i64>> {
+ prop::collection::vec(-1_000i64..=1_000, 0..10)
+ }
+
+ proptest! {
+ #[test]
+ fn blocked_teams_never_process(
+ team_id: i64,
+ rollout in 0u8..=100,
+ allowed in arb_team_list(),
+ mut blocked in arb_team_list(),
+ ) {
+ blocked.push(team_id);
+ prop_assert!(!team_filter_allows(team_id, &allowed, &blocked, rollout));
+ }
+
+ #[test]
+ fn allowed_teams_process_when_not_blocked(
+ team_id: i64,
+ rollout in 0u8..=100,
+ blocked in arb_team_list(),
+ mut allowed in arb_team_list(),
+ ) {
+ let blocked: Vec<i64> = blocked.into_iter().filter(|t| *t != team_id).collect();
+ allowed.push(team_id);
+ prop_assert!(team_filter_allows(team_id, &allowed, &blocked, rollout));
+ }
+
+ #[test]
+ fn full_rollout_processes_any_non_blocked_team(
+ team_id: i64,
+ allowed in arb_team_list(),
+ blocked in arb_team_list(),
+ ) {
+ let blocked: Vec<i64> = blocked.into_iter().filter(|t| *t != team_id).collect();
+ prop_assert!(team_filter_allows(team_id, &allowed, &blocked, 100));
+ }
+
+ #[test]
+ fn zero_rollout_drops_any_non_allowed_team(
+ team_id: i64,
+ allowed in arb_team_list(),
+ blocked in arb_team_list(),
+ ) {
+ let allowed: Vec<i64> = allowed.into_iter().filter(|t| *t != team_id).collect();
+ let blocked: Vec<i64> = blocked.into_iter().filter(|t| *t != team_id).collect();
+ prop_assert!(!team_filter_allows(team_id, &allowed, &blocked, 0));
+ }
+
+ #[test]
+ fn should_process_is_deterministic(
+ team_id: i64,
+ rollout in 0u8..=100,
+ allowed in arb_team_list(),
+ blocked in arb_team_list(),
+ ) {
+ let first = team_filter_allows(team_id, &allowed, &blocked, rollout);
+ for _ in 0..5 {
+ prop_assert_eq!(team_filter_allows(team_id, &allowed, &blocked, rollout), first);
+ }
+ }
+ }
+
+ #[test]
+ fn rollout_percentage_approximates_target_share() {
+ let included = (1..=10_000)
+ .filter(|t| team_filter_allows(*t, &[], &[], 10))
+ .count();
+ assert!(
+ (900..=1100).contains(&included),
+ "expected ~1000 of 10000 at 10%, got {included}"
+ );
+ }
+}
diff --git a/rust/property-vals-rs/src/lib.rs b/rust/property-vals-rs/src/lib.rs
new file mode 100644
index 000000000000..ef68c36943d4
--- /dev/null
+++ b/rust/property-vals-rs/src/lib.rs
@@ -0,0 +1 @@
+pub mod config;
diff --git a/rust/property-vals-rs/src/main.rs b/rust/property-vals-rs/src/main.rs
new file mode 100644
index 000000000000..ed353b8572fe
--- /dev/null
+++ b/rust/property-vals-rs/src/main.rs
@@ -0,0 +1,87 @@
+use std::time::Duration;
+
+use axum::{response::IntoResponse, routing::get, Router};
+use lifecycle::{ComponentOptions, Manager};
+use property_vals_rs::config::Config;
+use serve_metrics::setup_metrics_routes;
+use tokio::net::TcpListener;
+use tracing::level_filters::LevelFilter;
+use tracing::{info, warn};
+use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
+
+common_alloc::used!();
+
+fn setup_tracing() {
+ let log_layer = tracing_subscriber::fmt::layer().with_filter(
+ EnvFilter::builder()
+ .with_default_directive(LevelFilter::INFO.into())
+ .from_env_lossy()
+ .add_directive("pyroscope=warn".parse().unwrap()),
+ );
+ tracing_subscriber::registry().with(log_layer).init();
+}
+
+pub async fn index() -> &'static str {
+ "property-vals-rs"
+}
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ setup_tracing();
+ info!("Starting up property-vals-rs...");
+
+ let config = Config::init_with_defaults()?;
+
+ let _profiling_agent = match config.continuous_profiling.start_agent() {
+ Ok(agent) => agent,
+ Err(e) => {
+ warn!("Failed to start continuous profiling agent: {e}");
+ None
+ }
+ };
+
+ let mut manager = Manager::builder("property-vals-rs")
+ .with_global_shutdown_timeout(Duration::from_secs(60))
+ .build();
+
+ let metrics_handle =
+ manager.register("metrics", ComponentOptions::new().is_observability(true));
+
+ let readiness = manager.readiness_handler();
+ let liveness = manager.liveness_handler();
+
+ let app = Router::new()
+ .route("/", get(index))
+ .route(
+ "/_readiness",
+ get({
+ let r = readiness.clone();
+ move || {
+ let r = r.clone();
+ async move { r.check().await }
+ }
+ }),
+ )
+ .route(
+ "/_liveness",
+ get({
+ let l = liveness.clone();
+ move || {
+ let l = l.clone();
+ async move { l.check().into_response() }
+ }
+ }),
+ );
+ let app = setup_metrics_routes(app);
+
+ let bind = format!("{}:{}", config.host, config.port);
+ info!(address = %bind, "HTTP server starting");
+ let listener = TcpListener::bind(&bind).await?;
+ axum::serve(listener, app)
+ .with_graceful_shutdown(metrics_handle.shutdown_signal())
+ .await?;
+ metrics_handle.work_completed();
+
+ info!("property-vals-rs stopped");
+ Ok(())
+}