Skip to content

Commit 4b4b317

Browse files
committed
fix(pb): get new actor ids working e2e
1 parent 5360cd4 commit 4b4b317

File tree

16 files changed

+149
-195
lines changed

16 files changed

+149
-195
lines changed

packages/common/config/src/config/server/rivet/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ pub struct Rivet {
6060
#[serde(default = "Rivet::default_namespace")]
6161
pub namespace: String,
6262

63+
/// If specified, will use this as the default cluster ID.
64+
///
65+
/// This will have no effect if applied after the cluster has first ran.
66+
pub instance_id: Option<Uuid>,
67+
6368
/// If specified, will use this as the default cluster ID.
6469
///
6570
/// This will have no effect if applied after the cluster has first ran.
@@ -139,6 +144,7 @@ impl Default for Rivet {
139144
fn default() -> Rivet {
140145
Self {
141146
namespace: Self::default_namespace(),
147+
instance_id: None,
142148
default_cluster_id: None,
143149
clusters: None,
144150
provision: None,
@@ -171,7 +177,7 @@ impl Rivet {
171177
}
172178
}
173179

174-
impl Rivet {
180+
impl Rivet {
175181
pub fn default_cluster_id(&self) -> GlobalResult<Uuid> {
176182
if let Some(default_cluster_id) = self.default_cluster_id {
177183
ensure!(
@@ -184,9 +190,7 @@ impl Rivet {
184190
// Return default development clusters
185191
AccessKind::Development => Ok(default_dev_cluster::CLUSTER_ID),
186192
// No cluster configured
187-
AccessKind::Public | AccessKind::Private => {
188-
bail!("`default_cluster_id` not configured")
189-
}
193+
AccessKind::Public | AccessKind::Private => bail!("`default_cluster_id` not configured"),
190194
}
191195
}
192196
}

packages/core/services/cluster/src/ops/datacenter/get_for_label.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async fn get_dcs(ctx: OperationCtx, labels: Vec<u16>) -> GlobalResult<Vec<Datace
5757
FROM db_cluster.datacenters@datacenter_label_idx
5858
WHERE label = ANY($1)
5959
",
60-
labels.into_iter().map(|x| x as i64).collect::<Vec<_>>(),
60+
labels.into_iter().map(|x| x.to_be_bytes()).collect::<Vec<_>>(),
6161
)
6262
.await?;
6363

packages/core/services/cluster/src/workflows/server/install/install_scripts/components/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub mod lz4 {
203203
indoc!(
204204
r#"
205205
echo 'Downloading lz4'
206-
curl -L https://releases.rivet.gg/tools/lz4/1.10.0/debian11-amd64/lz4 -o /usr/local/bin/lz4
206+
curl -Lfo /usr/local/bin/lz4 https://releases.rivet.gg/tools/lz4/1.10.0/debian11-amd64/lz4
207207
chmod +x /usr/local/bin/lz4
208208
"#
209209
)
@@ -224,7 +224,7 @@ pub mod umoci {
224224
indoc!(
225225
r#"
226226
echo 'Downloading umoci'
227-
curl -Lf -o /usr/bin/umoci "https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
227+
curl -Lfo /usr/bin/umoci "https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
228228
chmod +x /usr/bin/umoci
229229
"#
230230
).to_string()
@@ -238,7 +238,7 @@ pub mod cni {
238238
indoc!(
239239
r#"
240240
echo 'Downloading cnitool'
241-
curl -Lf -o /usr/bin/cnitool "https://github.com/rivet-gg/cni/releases/download/v1.1.2-build3/cnitool"
241+
curl -Lfo /usr/bin/cnitool "https://github.com/rivet-gg/cni/releases/download/v1.1.2-build3/cnitool"
242242
chmod +x /usr/bin/cnitool
243243
"#
244244
).to_string()

packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/guard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult<String> {
3636
tls: server_config.tls.clone(),
3737
rivet: Rivet {
3838
namespace: server_config.rivet.namespace.clone(),
39+
instance_id: server_config.rivet.instance_id,
3940
auth: server_config.rivet.auth.clone(),
4041
api_public: ApiPublic {
4142
// NOTE: Templated later

packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult<String> {
3636
tls: server_config.tls.clone(),
3737
rivet: Rivet {
3838
namespace: server_config.rivet.namespace.clone(),
39+
instance_id: server_config.rivet.instance_id,
3940
clusters: Some({
4041
let mut clusters = HashMap::new();
4142

packages/core/services/dynamic-config/db/dynamic-config/migrations/20250523120501_instance_id.down.sql

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE config
2+
RENAME COLUMN cluster_id TO rivet_instance_id;
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
use chirp_workflow::prelude::*;
22
use tokio::sync::OnceCell;
33

4-
// The cluster ID will never change, so store it in memory.
5-
static CLUSTER_ID_ONCE: OnceCell<Uuid> = OnceCell::const_new();
4+
// The instance ID will never change, so store it in memory.
5+
static INSTANCE_ID_ONCE: OnceCell<Uuid> = OnceCell::const_new();
66

77
#[derive(Debug, Default)]
88
pub struct Input {}
99

1010
#[derive(Debug)]
1111
pub struct Output {
12-
pub cluster_id: Uuid,
12+
pub instance_id: Uuid,
1313
}
1414

1515
#[operation]
16-
pub async fn get_cluster_id(ctx: &OperationCtx, input: &Input) -> GlobalResult<Output> {
16+
pub async fn get_config(ctx: &OperationCtx, input: &Input) -> GlobalResult<Output> {
1717
// IMPORTANT: This is not the same as the cluster ID from the `cluster` package. This is used
18-
// for unqiuely identifying the entire Rivet cluster.
18+
// for uniquely identifying the entire Rivet cluster.
1919

20-
// Pick a cluster ID to insert if none exists. If this is specified in the config. fall back to
20+
// Pick an instance ID to insert if none exists. If this is specified in the config. fall back to
2121
// this.
22-
let default_cluster_id =
23-
if let Some(cluster_id) = ctx.config().server()?.rivet.default_cluster_id {
24-
cluster_id
22+
let default_instance_id =
23+
if let Some(instance_id) = ctx.config().server()?.rivet.instance_id {
24+
instance_id
2525
} else {
2626
Uuid::new_v4()
2727
};
2828

29-
let cluster_id = CLUSTER_ID_ONCE
29+
let instance_id = INSTANCE_ID_ONCE
3030
.get_or_try_init(|| async {
3131
sql_fetch_one!(
3232
[ctx, (Uuid,)]
3333
"
3434
WITH new_row AS (
35-
INSERT INTO db_dynamic_config.config (id, cluster_id)
35+
INSERT INTO db_dynamic_config.config (id, rivet_instance_id)
3636
VALUES (1, $1)
3737
ON CONFLICT (id) DO NOTHING
38-
RETURNING cluster_id
38+
RETURNING rivet_instance_id
3939
)
40-
SELECT cluster_id
40+
SELECT rivet_instance_id
4141
FROM new_row
4242
UNION ALL
43-
SELECT cluster_id
43+
SELECT rivet_instance_id
4444
FROM db_dynamic_config.config
4545
WHERE NOT EXISTS (SELECT 1 FROM new_row)
4646
",
47-
default_cluster_id
47+
default_instance_id
4848
)
4949
.await
5050
.map(|x| x.0)
5151
})
5252
.await?;
5353

5454
Ok(Output {
55-
cluster_id: *cluster_id,
55+
instance_id: *instance_id,
5656
})
5757
}

packages/core/services/telemetry/standalone/beacon/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ pub async fn run_from_env(
4141
(),
4242
);
4343

44-
// Get the cluster ID
45-
let cluster_id = chirp_workflow::compat::op(&ctx, dynamic_config::ops::get_config::Input {})
44+
// Get the rivet instance ID
45+
let instance_id = chirp_workflow::compat::op(&ctx, dynamic_config::ops::get_config::Input {})
4646
.await?
47-
.cluster_id;
47+
.instance_id;
4848

4949
// Build events
5050
let mut events = Vec::new();
51-
let distinct_id = format!("cluster:{cluster_id}");
51+
let distinct_id = format!("instance:{instance_id}");
5252

5353
// Send beacon
54-
let mut event = async_posthog::Event::new("cluster_beacon", &distinct_id);
55-
event.insert_prop("$groups", json!({ "cluster": cluster_id }))?;
54+
let mut event = async_posthog::Event::new("instance_beacon", &distinct_id);
55+
event.insert_prop("$groups", json!({ "instance": instance_id }))?;
5656
event.insert_prop(
5757
"$set",
5858
json!({
59-
"cluster_id": cluster_id,
59+
"instance_id": instance_id,
6060
"os": os_report(),
6161
"source_hash": rivet_env::source_hash(),
6262
"config": get_config_data(&ctx)?,
@@ -66,10 +66,10 @@ pub async fn run_from_env(
6666
)?;
6767
events.push(event);
6868

69-
// Add cluster identification data
69+
// Add instance identification data
7070
let mut event = async_posthog::Event::new("$groupidentify", &distinct_id);
71-
event.insert_prop("$group_type", "cluster")?;
72-
event.insert_prop("$group_key", cluster_id)?;
71+
event.insert_prop("$group_type", "instance")?;
72+
event.insert_prop("$group_key", instance_id)?;
7373
event.insert_prop(
7474
"$group_set",
7575
json!({
@@ -89,7 +89,7 @@ pub async fn run_from_env(
8989
Ok(())
9090
}
9191

92-
/// Returns information about the operating system running the cluster.
92+
/// Returns information about the operating system running the instance.
9393
///
9494
/// This helps Rivet diagnose crash reports to easily pinpoint if issues are
9595
/// coming from a specific operating system.
@@ -190,9 +190,9 @@ struct ResourceAggregateRow {
190190

191191
// /// Returns information about the pegboard configuration.
192192
// ///
193-
// /// This is helpful for diagnosing issues with the self-hosted clusters under
194-
// /// load. e.g. if a cluster is running on constraint resources (see os_report),
195-
// /// does the cluster configuration affect it?
193+
// /// This is helpful for diagnosing issues with the self-hosted instances under
194+
// /// load. e.g. if a instance is running on constraint resources (see os_report),
195+
// /// does the instance configuration affect it?
196196
// async fn get_pegboard_data(ctx: &OperationContext<()>) -> GlobalResult<serde_json::Value> {
197197
// use pegboard::protocol::ClientFlavor;
198198

packages/edge/infra/client/echo/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ authors = ["Rivet Gaming, LLC <[email protected]>"]
66
license = "Apache-2.0"
77

88
[dependencies]
9+
anyhow = "1.0"
910
bytes = "1.0"
1011
futures-util = "0.3"
1112
http = "0.2"
13+
serde = { version = "1.0", features = ["derive"] }
1214
serde_json = "1.0"
1315
tokio = { version = "1.40", features = ["full",] }
14-
tokio-tungstenite = "0.23.1"
16+
tokio-util = "0.7"
1517
uuid = { version = "1", features = ["v4", "serde"] }
1618
warp = "0.3.7"

0 commit comments

Comments
 (0)