Skip to content
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

duplicate traffic to new server for stress testing #825

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
NODE_ENV=development
VITE_APP_SITE="http://localhost:4200"
VITE_APP_API="http://localhost:3100/v3"
VITE_APP_API_TEST="https://7tv.foo/v3"
VITE_APP_API_GQL="http://localhost:3000/v3/gql"
VITE_APP_API_EVENTS="ws://localhost:3700/v3"
VITE_APP_API_EVENTS_TEST="wss://events.7tv.foo/v3"
VITE_APP_API_EGVAULT="http://localhost:3444/v1"
VITE_APP_HOST="http://localhost:8080"
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
NODE_ENV=production
VITE_APP_SITE="https://7tv.app"
VITE_APP_API="https://7tv.io/v3"
VITE_APP_API_TEST="https://7tv.foo/v3"
VITE_APP_API_GQL="https://7tv.io/v3/gql"
VITE_APP_API_EVENTS="wss://events.7tv.io/v3"
VITE_APP_API_EVENTS_TEST="wss://events.7tv.foo/v3"
VITE_APP_API_EGVAULT="https://egvault.7tv.io/v1"
VITE_APP_HOST="https://extension.7tv.gg"

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"displayName": "7TV",
"description": "Improve your viewing experience on Twitch & YouTube with new features, emotes, vanity and performance.",
"private": true,
"version": "3.0.15",
"dev_version": "1.0",
"version": "3.0.15.1-st",
"dev_version": "2.0",
"scripts": {
"start": "NODE_ENV=dev yarn build:dev && NODE_ENV=dev vite --mode dev",
"build:section:app": "vite build --config vite.config.ts",
Expand Down
17 changes: 12 additions & 5 deletions src/composable/channel/useChannelContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ export class ChannelContext implements CurrentChannel {
}

leave(): void {
this.active = false;

sendMessage("STATE", {
channel: toRaw(this.base),
});
// debounce leave
// this allows some time for other channel trackers to join
/// note: perhaps this could be designed better
setTimeout(() => {
if (this.count > 0) return;

this.active = false;

sendMessage("STATE", {
channel: toRaw(this.base),
});
}, 1e3);
}

fetch(): void {
Expand Down
4 changes: 4 additions & 0 deletions src/worker/worker.driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WorkerPort } from "./worker.port";
export class WorkerDriver extends EventTarget {
http: WorkerHttp;
eventAPI: EventAPI;
eventAPITest?: EventAPI;
db: Dexie7;
log: Logger;

Expand Down Expand Up @@ -37,6 +38,9 @@ export class WorkerDriver extends EventTarget {
this.http = new WorkerHttp(this);
this.eventAPI = new EventAPI(this);

// stress-test
this.eventAPITest = new EventAPI(this, import.meta.env.VITE_APP_API_EVENTS_TEST, true);

db.ready().then(async () => {
// Fetch global emotes & cosmetics
const sets = [] as SevenTV.EmoteSet[];
Expand Down
9 changes: 8 additions & 1 deletion src/worker/worker.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export class EventAPI {
return "TWITCH";
}

constructor(private driver: WorkerDriver) {}
constructor(
private driver: WorkerDriver,
overrideURL = "",
private test = false,
) {
if (overrideURL) this.url = overrideURL;
}

private getContext(): EventContext {
return {
Expand Down Expand Up @@ -72,6 +78,7 @@ export class EventAPI {
this.onHello(msg as EventAPIMessage<"HELLO">);
break;
case "DISPATCH":
if (this.test) return;
this.onDispatch(msg as EventAPIMessage<"DISPATCH">);
break;
case "ERROR":
Expand Down
67 changes: 44 additions & 23 deletions src/worker/worker.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { WorkerPort } from "./worker.port";

namespace API_BASE {
export const SEVENTV = import.meta.env.VITE_APP_API;
export const SEVENTV_TEST = import.meta.env.VITE_APP_API_TEST;
export const FFZ = "https://api.frankerfacez.com/v1";
export const BTTV = "https://api.betterttv.net/3";
}
Expand Down Expand Up @@ -38,6 +39,7 @@ export class WorkerHttp {
if (!ev.port) return;

this.driver.eventAPI.unsubscribeChannel(ev.detail.id, ev.port);
this.driver.eventAPITest?.unsubscribeChannel(ev.detail.id, ev.port);
});
driver.addEventListener("identity_updated", async (ev) => {
const user = await this.API()
Expand Down Expand Up @@ -155,7 +157,9 @@ export class WorkerHttp {

const user = await userPromise;
if (user) {
this.driver.eventAPI.subscribe("user.*", { object_id: user.id }, port, channel.id);
[this.driver.eventAPI, this.driver.eventAPITest].forEach(
(inst) => inst?.subscribe("user.*", { object_id: user.id }, port, channel.id),
);
}

// begin subscriptions to personal events in the channel
Expand All @@ -165,9 +169,15 @@ export class WorkerHttp {
id: channel.id,
};

this.driver.eventAPI.subscribe("entitlement.*", cond, port, channel.id);
this.driver.eventAPI.subscribe("cosmetic.*", cond, port, channel.id);
this.driver.eventAPI.subscribe("emote_set.*", cond, port, channel.id);
[this.driver.eventAPI, this.driver.eventAPITest].forEach(
(inst) => inst?.subscribe("entitlement.*", cond, port, channel.id),
);
[this.driver.eventAPI, this.driver.eventAPITest].forEach(
(inst) => inst?.subscribe("cosmetic.*", cond, port, channel.id),
);
[this.driver.eventAPI, this.driver.eventAPITest].forEach(
(inst) => inst?.subscribe("emote_set.*", cond, port, channel.id),
);

// Send an initial presence so that the current user immediately has their cosmetics
// (sent with "self" property, so that the presence and entitlements are not published)
Expand Down Expand Up @@ -403,24 +413,35 @@ export const betterttv = {
};

async function doRequest<T = object>(base: string, path: string, method?: string, body?: T): Promise<Response> {
return fetch(`${base}/${path}`, {
method,
body: body ? JSON.stringify(body) : undefined,
headers: body
? {
"Content-Type": "application/json",
}
: undefined,
referrer: location.origin,
referrerPolicy: "origin",
}).then(async (resp) => {
const loggable = resp.clone();

log.debugWithObjects(
["<API>", `${resp.status} ${resp.statusText}${method ?? "GET"} ${base}/${path}`],
[await loggable.json()],
);
const makeFetch = (overrideBase?: string) => {
return fetch(`${overrideBase || base}/${path}`, {
method,
body: body ? JSON.stringify(body) : undefined,
headers: body
? {
"Content-Type": "application/json",
}
: undefined,
referrer: location.origin,
referrerPolicy: "origin",
}).then(async (resp) => {
const loggable = resp.clone();

log.debugWithObjects(
["<API>", `${resp.status} ${resp.statusText}${method ?? "GET"} ${resp.url}`],
[await loggable.json()],
);

return resp;
});
};

const live = await makeFetch();

// new server stress test
if (base === API_BASE.SEVENTV) {
makeFetch(API_BASE.SEVENTV_TEST).catch(() => void 0);
}

return resp;
});
return live;
}
Loading