Skip to content

make balancer ids constant from the perspective of the monolith #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 13, 2024
15 changes: 14 additions & 1 deletion crates/ott-balancer-protocol/src/monolith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use typeshare::typeshare;

use crate::{ClientId, MonolithId, RoomName};
use crate::{BalancerId, ClientId, MonolithId, RoomName};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "payload", rename_all = "snake_case")]
Expand All @@ -15,6 +15,7 @@ pub enum MsgB2M {
Join(B2MJoin),
Leave(B2MLeave),
ClientMsg(B2MClientMsg),
Init(B2MInit),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -52,6 +53,12 @@ pub struct B2MClientMsg<T = Box<RawValue>> {
pub payload: T,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[typeshare]
pub struct B2MInit {
pub id: BalancerId,
}

impl From<B2MLoad> for MsgB2M {
fn from(val: B2MLoad) -> Self {
Self::Load(val)
Expand Down Expand Up @@ -82,6 +89,12 @@ impl From<B2MClientMsg> for MsgB2M {
}
}

impl From<B2MInit> for MsgB2M {
fn from(val: B2MInit) -> Self {
Self::Init(val)
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "payload", rename_all = "snake_case")]
#[typeshare]
Expand Down
19 changes: 18 additions & 1 deletion crates/ott-balancer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet};
use std::time::Duration;

use futures_util::{SinkExt, StreamExt};
use ott_balancer_protocol::monolith::MsgM2B;
use ott_balancer_protocol::monolith::{MsgB2M, MsgM2B};
use ott_common::discovery::{ConnectionConfig, ServiceDiscoveryMsg};
use tokio_tungstenite::{connect_async, WebSocketStream};
use tokio_util::sync::CancellationToken;
Expand All @@ -16,6 +16,13 @@ use tungstenite::Message;
use crate::balancer::BalancerLink;
use crate::messages::SocketMessage;
use crate::monolith::NewMonolith;
use ott_balancer_protocol::monolith::B2MInit;
use ott_balancer_protocol::*;
use uuid::Uuid;

use once_cell::sync::Lazy;

pub static BALANCER_ID: Lazy<BalancerId> = Lazy::new(|| Uuid::new_v4().into());

pub struct MonolithConnectionManager {
discovery_rx: tokio::sync::mpsc::Receiver<ServiceDiscoveryMsg>,
Expand Down Expand Up @@ -106,6 +113,16 @@ async fn connect_and_maintain(
}
}

let init = B2MInit { id: *BALANCER_ID };
stream
.send(Message::Text(
serde_json::to_string(&MsgB2M::Init(init)).unwrap(),
))
.await
.unwrap_or_else(|err| {
error!("Failed to send init message to monolith: {}", err);
});

let result = tokio::time::timeout(Duration::from_secs(20), stream.next()).await;
let Ok(Some(Ok(message))) = result else {
let _ = stream
Expand Down
146 changes: 73 additions & 73 deletions packages/ott-vis-datasource/package.json
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
{
"name": "ott-vis-datasource",
"version": "0.12.0",
"description": "Collects ott system state",
"author": "Ott",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=18"
},
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
"test": "jest --passWithNoTests --maxWorkers 4 --coverage",
"test:ci": "jest --passWithNoTests --maxWorkers 4",
"typecheck": "tsc --noEmit",
"lint": "prettier --write --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx . --fix",
"lint-ci": "prettier --check --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"e2e": "npm exec cypress install && npm exec grafana-e2e run",
"e2e:update": "npm exec cypress install && npm exec grafana-e2e run --update-screenshots",
"server": "docker-compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@grafana/e2e": "10.0.3",
"@grafana/e2e-selectors": "10.0.3",
"@grafana/eslint-config": "^6.0.0",
"@grafana/tsconfig": "^1.2.0-rc1",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/node": "^20.8.7",
"@types/react-router-dom": "^5.2.0",
"@types/testing-library__jest-dom": "5.14.8",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"eslint": "^8.57.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-webpack-plugin": "^4.0.1",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"glob": "^10.2.7",
"identity-obj-proxy": "3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.8.7",
"replace-in-file-webpack-plugin": "^1.0.6",
"sass": "1.63.2",
"sass-loader": "13.3.1",
"style-loader": "3.3.3",
"swc-loader": "^0.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4",
"webpack-livereload-plugin": "^3.0.2"
},
"dependencies": {
"@emotion/css": "11.10.6",
"@grafana/data": "10.0.3",
"@grafana/runtime": "10.0.3",
"@grafana/schema": "10.0.3",
"@grafana/ui": "10.0.3",
"ott-vis": "*",
"react": "18.2.0",
"react-dom": "18.2.0",
"rxjs": "7.8.0",
"tslib": "2.5.3"
}
"name": "ott-vis-datasource",
"version": "0.12.0",
"description": "Collects ott system state",
"author": "Ott",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=18"
},
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
"test": "jest --passWithNoTests --maxWorkers 4 --coverage",
"test:ci": "jest --passWithNoTests --maxWorkers 4",
"typecheck": "tsc --noEmit",
"lint": "prettier --write --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx . --fix",
"lint-ci": "prettier --check --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"e2e": "npm exec cypress install && npm exec grafana-e2e run",
"e2e:update": "npm exec cypress install && npm exec grafana-e2e run --update-screenshots",
"server": "docker-compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@grafana/e2e": "10.0.3",
"@grafana/e2e-selectors": "10.0.3",
"@grafana/eslint-config": "^6.0.0",
"@grafana/tsconfig": "^1.2.0-rc1",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/node": "^20.8.7",
"@types/react-router-dom": "^5.2.0",
"@types/testing-library__jest-dom": "5.14.8",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"eslint": "^8.57.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-webpack-plugin": "^4.0.1",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"glob": "^10.2.7",
"identity-obj-proxy": "3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.8.7",
"replace-in-file-webpack-plugin": "^1.0.6",
"sass": "1.63.2",
"sass-loader": "13.3.1",
"style-loader": "3.3.3",
"swc-loader": "^0.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4",
"webpack-livereload-plugin": "^3.0.2"
},
"dependencies": {
"@emotion/css": "11.10.6",
"@grafana/data": "10.0.3",
"@grafana/runtime": "10.0.3",
"@grafana/schema": "10.0.3",
"@grafana/ui": "10.0.3",
"ott-vis": "*",
"react": "18.2.0",
"react-dom": "18.2.0",
"rxjs": "7.8.0",
"tslib": "2.5.3"
}
}
152 changes: 76 additions & 76 deletions packages/ott-vis-panel/package.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
{
"name": "ott-vis-panel",
"version": "0.12.0",
"description": "",
"author": "Ott",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=18"
},
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
"test": "jest --passWithNoTests --maxWorkers 4 --coverage",
"typecheck": "tsc --noEmit",
"lint": "prettier --write --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx . --fix",
"lint-ci": "prettier --check --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"e2e": "npm exec cypress install && npm exec grafana-e2e run",
"e2e:update": "npm exec cypress install && npm exec grafana-e2e run --update-screenshots",
"server": "docker-compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@grafana/e2e": "10.0.3",
"@grafana/e2e-selectors": "10.0.3",
"@grafana/eslint-config": "^6.0.0",
"@grafana/tsconfig": "^1.2.0-rc1",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/d3": "7.4.3",
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/node": "^20.8.7",
"@types/testing-library__jest-dom": "5.14.8",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"d3": "7.8.5",
"eslint": "^8.57.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-webpack-plugin": "^4.0.1",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"glob": "^10.2.7",
"identity-obj-proxy": "3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.8.7",
"replace-in-file-webpack-plugin": "^1.0.6",
"sass": "1.63.2",
"sass-loader": "13.3.1",
"style-loader": "3.3.3",
"swc-loader": "^0.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4",
"webpack-livereload-plugin": "^3.0.2"
},
"dependencies": {
"@emotion/css": "11.10.6",
"@grafana/data": "10.0.3",
"@grafana/runtime": "10.0.3",
"@grafana/schema": "10.0.3",
"@grafana/ui": "10.0.3",
"ott-vis": "*",
"react": "18.2.0",
"react-dom": "18.2.0",
"rxjs": "7.8.0",
"tslib": "2.5.3"
}
"name": "ott-vis-panel",
"version": "0.12.0",
"description": "",
"author": "Ott",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=18"
},
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
"test": "jest --passWithNoTests --maxWorkers 4 --coverage",
"typecheck": "tsc --noEmit",
"lint": "prettier --write --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx . --fix",
"lint-ci": "prettier --check --config ../../.prettierrc . && tsc --noEmit && eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"e2e": "npm exec cypress install && npm exec grafana-e2e run",
"e2e:update": "npm exec cypress install && npm exec grafana-e2e run --update-screenshots",
"server": "docker-compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest"
},
"devDependencies": {
"@babel/core": "^7.21.4",
"@grafana/e2e": "10.0.3",
"@grafana/e2e-selectors": "10.0.3",
"@grafana/eslint-config": "^6.0.0",
"@grafana/tsconfig": "^1.2.0-rc1",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
"@testing-library/jest-dom": "6.1.4",
"@testing-library/react": "14.0.0",
"@types/d3": "7.4.3",
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/node": "^20.8.7",
"@types/testing-library__jest-dom": "5.14.8",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"d3": "7.8.5",
"eslint": "^8.57.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-webpack-plugin": "^4.0.1",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"glob": "^10.2.7",
"identity-obj-proxy": "3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.8.7",
"replace-in-file-webpack-plugin": "^1.0.6",
"sass": "1.63.2",
"sass-loader": "13.3.1",
"style-loader": "3.3.3",
"swc-loader": "^0.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "4.8.4",
"webpack": "^5.86.0",
"webpack-cli": "^5.1.4",
"webpack-livereload-plugin": "^3.0.2"
},
"dependencies": {
"@emotion/css": "11.10.6",
"@grafana/data": "10.0.3",
"@grafana/runtime": "10.0.3",
"@grafana/schema": "10.0.3",
"@grafana/ui": "10.0.3",
"ott-vis": "*",
"react": "18.2.0",
"react-dom": "18.2.0",
"rxjs": "7.8.0",
"tslib": "2.5.3"
}
}
Loading
Loading