Skip to content

Commit 6fccebb

Browse files
committed
fix: disambiguate cluster_id <-> instance_id (#2472)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
1 parent ba7a88d commit 6fccebb

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
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/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,58 +1,58 @@
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
4747
",
48-
default_cluster_id
48+
default_instance_id
4949
)
5050
.await
5151
.map(|x| x.0)
5252
})
5353
.await?;
5454

5555
Ok(Output {
56-
cluster_id: *cluster_id,
56+
instance_id: *instance_id,
5757
})
5858
}

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

0 commit comments

Comments
 (0)