Skip to content

Commit 09a47be

Browse files
committed
fix(guard): use intercom_address for guard service discovery
1 parent 94a55e5 commit 09a47be

File tree

7 files changed

+45
-16
lines changed
  • docker/dev-full
  • packages
    • common/config/src/config/server/rivet
    • core/services/cluster/src/workflows/server/install/install_scripts/components/rivet
    • edge
      • infra/guard/server/src/routing
      • services/pegboard/src/workflows/client

7 files changed

+45
-16
lines changed

docker/dev-full/rivet-edge-server/config.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"cluster_id": "11ca8960-acab-4963-909c-99d72af3e1cb",
99
"datacenter_id": "f288913c-735d-4188-bf9b-2fcf6eac7b9c",
1010
"server_id": "174aca2a-98b7-462c-9ad9-3835094a9a10",
11-
"intercom_endpoint": "http://rivet-server:8081"
11+
"intercom_address": "http://rivet-server:8081"
1212
},
1313
"guard": {
1414
// TLS not configured for local development

docker/dev-full/rivet-guard/config.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"cluster_id": "11ca8960-acab-4963-909c-99d72af3e1cb",
2121
"datacenter_id": "f288913c-735d-4188-bf9b-2fcf6eac7b9c",
2222
"server_id": "174aca2a-98b7-462c-9ad9-3835094a9a10",
23-
"intercom_endpoint": "http://rivet-server:8081"
23+
"intercom_address": "http://rivet-server:8081"
2424
},
2525
"guard": {
2626
// TLS not configured for local development

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,20 @@ pub struct Edge {
841841
pub cluster_id: Uuid,
842842
pub datacenter_id: Uuid,
843843
pub server_id: Uuid,
844-
pub intercom_endpoint: Url,
844+
/// Url of the core cluster.
845+
pub intercom_address: Url,
845846
/// This API address will be used if there are no worker servers listed in the cluster package
846847
#[serde(default)]
847848
pub api_lan_address: Option<(String, u16)>,
848849
#[serde(default)]
849850
pub redirect_logs_dir: Option<PathBuf>,
850851
}
852+
853+
impl Edge {
854+
/// u16 used in the `Id` type for actors
855+
pub fn datacenter_label(&self) -> u16 {
856+
// Read first 2 bytes
857+
let bytes = self.datacenter_id.as_bytes();
858+
u16::from_be_bytes([bytes[0], bytes[1]])
859+
}
860+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult<String> {
5858
datacenter_id: Uuid::nil(),
5959
server_id: Uuid::nil(),
6060
api_lan_address: None,
61-
intercom_endpoint: Url::parse(&format!("http://127.0.0.1:{TUNNEL_API_EDGE_PORT}"))?,
61+
intercom_address: Url::parse(&format!("http://127.0.0.1:{TUNNEL_API_EDGE_PORT}"))?,
6262
redirect_logs_dir: Some(PathBuf::from("/var/log/rivet-guard")),
6363
}),
6464
status: server_config.rivet.status.clone(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult<String> {
7272
datacenter_id: Uuid::nil(),
7373
server_id: Uuid::nil(),
7474
api_lan_address: None,
75-
intercom_endpoint: Url::parse(&format!("http://127.0.0.1:{TUNNEL_API_EDGE_PORT}"))?,
75+
intercom_address: Url::parse(&format!("http://127.0.0.1:{TUNNEL_API_EDGE_PORT}"))?,
7676
redirect_logs_dir: Some(PathBuf::from("/var/log/rivet-edge-server")),
7777
}),
7878
..Default::default()

packages/edge/infra/guard/server/src/routing/api.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use service_discovery::ServiceDiscovery;
1010
use url::Url;
1111
use uuid::Uuid;
1212

13-
// TODO: Copied from cluster/src/workflows/server/install/install_scripts/components/rivet/mod.rs
14-
const TUNNEL_API_EDGE_PORT: u16 = 5010;
15-
1613
/// Route requests to the API service
1714
#[tracing::instrument(skip_all)]
1815
pub async fn route_api_request(
@@ -46,7 +43,8 @@ pub async fn route_api_request(
4643

4744
// NOTE: We use service discovery instead of server::list or datacenter::server_discovery because cache is not
4845
// shared between edge-edge or edge-core. SD requests the core which has a single cache.
49-
let url = Url::parse(&format!("http://127.0.0.1:{TUNNEL_API_EDGE_PORT}/provision/datacenters/{dc_id}/servers?pools=worker"))?;
46+
let edge = ctx.config().server()?.rivet.edge()?;
47+
let url = Url::parse(&format!("{}provision/datacenters/{dc_id}/servers?pools=worker", edge.intercom_address))?;
5048
let sd = ServiceDiscovery::new(url);
5149
let servers = sd.fetch().await?;
5250

packages/edge/services/pegboard/src/workflows/client/mod.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,41 @@ pub async fn pegboard_client(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResu
142142
state,
143143
} = event.inner.deserialize()?
144144
{
145+
// Try actor2 first
145146
let res = ctx
146147
.signal(crate::workflows::actor::StateUpdate {
147148
generation,
148-
state,
149+
state: state.clone(),
149150
})
150-
.to_workflow::<crate::workflows::actor::Workflow>()
151+
.to_workflow::<crate::workflows::actor2::Workflow>()
151152
.tag("actor_id", actor_id)
152153
.send()
153154
.await;
154155

155156
if let Some(WorkflowError::WorkflowNotFound) =
156157
res.as_workflow_error()
157158
{
158-
tracing::warn!(
159-
?actor_id,
160-
"actor workflow not found, likely already stopped"
161-
);
159+
// Try old actors
160+
let res = ctx
161+
.signal(crate::workflows::actor::StateUpdate {
162+
generation,
163+
state,
164+
})
165+
.to_workflow::<crate::workflows::actor::Workflow>()
166+
.tag("actor_id", actor_id)
167+
.send()
168+
.await;
169+
170+
if let Some(WorkflowError::WorkflowNotFound) =
171+
res.as_workflow_error()
172+
{
173+
tracing::warn!(
174+
?actor_id,
175+
"actor workflow not found, likely already stopped"
176+
);
177+
} else {
178+
res?;
179+
}
162180
} else {
163181
res?;
164182
}
@@ -510,7 +528,7 @@ async fn publish_registered(ctx: &ActivityCtx, input: &PublishRegisteredInput) -
510528

511529
let config = Configuration {
512530
client: rivet_pools::reqwest::client().await?,
513-
base_path: util::url::to_string_without_slash(&edge.intercom_endpoint),
531+
base_path: util::url::to_string_without_slash(&edge.intercom_address),
514532
bearer_access_token: Some(token),
515533
..Default::default()
516534
};
@@ -772,6 +790,9 @@ pub async fn handle_commands(
772790
}
773791
}
774792
}
793+
protocol::Command::SignalRunner { .. } => {
794+
// No-op in this workflow
795+
}
775796
}
776797
}
777798

0 commit comments

Comments
 (0)