Skip to content

Commit

Permalink
add region field to balancer protocol (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored Nov 3, 2023
1 parent f5a8664 commit 5c61552
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/harness/src/monolith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl Monolith {
loop {
let (stream, _) = _listener.accept().await.unwrap();
let mut ws = tokio_tungstenite::accept_async(stream).await.unwrap();
let init = M2BInit { port: http_port };
let init = M2BInit {
port: http_port,
region: "unknown".into(),
};
let msg = serde_json::to_string(&MsgM2B::Init(init)).unwrap();
ws.send(Message::Text(msg)).await.unwrap();
state.lock().unwrap().connected = true;
Expand Down
1 change: 1 addition & 0 deletions crates/ott-balancer-protocol/src/monolith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub enum MsgM2B {
pub struct M2BInit {
/// The port that the monolith is listening for HTTP requests on.
pub port: u16,
pub region: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions server/balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class BalancerManager {
type: "init",
payload: {
port: conf.get("port"),
region: conf.get("balancing.region"),
},
};
conn.send(init);
Expand Down Expand Up @@ -170,6 +171,7 @@ export class BalancerConnection {
type: "init",
payload: {
port: conf.get("port"),
region: conf.get("balancing.region"),
},
};
this.send(init);
Expand Down
1 change: 1 addition & 0 deletions server/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface B2MClientMsg<T = unknown> {
export interface M2BInit {
/** The port that the monolith is listening for HTTP requests on. */
port: number;
region: string;
}

export enum Visibility {
Expand Down
11 changes: 11 additions & 0 deletions server/ott-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ export const conf = convict({
default: 3002,
env: "BALANCING_PORT",
},
region: {
doc: "The region that this server is in.",
format: String,
default: "unknown",
env: "BALANCING_REGION",
},
},
mail: {
enabled: {
Expand Down Expand Up @@ -513,6 +519,11 @@ function postProcessConfig(): void {
if (conf.get("mail.enabled")) {
validateMail();
}

if (process.env.FLY_REGION) {
log.info("Found FLY_REGION. Using it for balancing.region.");
conf.set("balancing.region", process.env.FLY_REGION);
}
}

function validateMail() {
Expand Down

0 comments on commit 5c61552

Please sign in to comment.